Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Adding Google Pagetracker into link
Old 11-28-2010, 06:16 AM Adding Google Pagetracker into link
Spud In Disguise's Avatar
Super Spam Talker

Posts: 808
Location: UK... where else?
Trades: 0
Hi all, I am trying to add the Google Analytics external link tracker into some links on my site. The problem is, the links use javascript in two places and so no matter how I try to add the second script in it always fails. Can someone help me make sense of this?

The process is:

This is the desired output:
Code:
<a href="http://www.facebook.com/sharer.php?u=PAGEURL" onclick="javascript: pageTracker._trackPageview('share_link/PAGEURL');"><img src="facebook.png"></a>
Adding the first PAGEURL
This is how I currently display the links (without tracking)
Code:
<script language="JavaScript">

document.write( '<a href="http://www.facebook.com/sharer.php?u=' + location.href + '"><img src="facebook.png"></a>' );

</script>
Adding the second PAGEURL
This is my attempt at adding the second URL, I have tweaked the quote marks and apostrophes in loads of ways, but just can't make it work.
Code:
<script language="JavaScript">

document.write( '<a href="http://www.facebook.com/sharer.php?u=' + location.href + '" onclick="javascript: pageTracker._trackPageview('share_link/'+ location.href +'');"><imgsrc="facebook.png"></a>' );

</script>
Can anyone help?
__________________

Please login or register to view this content. Registration is FREE
- Fansite

Please login or register to view this content. Registration is FREE
- Blog
Spud In Disguise is offline
Reply With Quote
View Public Profile Visit Spud In Disguise's homepage!
 
 
Register now for full access!
Old 11-28-2010, 09:06 AM Re: Adding Google Pagetracker into link
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Code:
onclick="javascript: pageTracker
the "javascript:" append should ONLY be used when the function is being called from the href attribute and NOT in event calls.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-28-2010, 10:55 AM Re: Adding Google Pagetracker into link
Spud In Disguise's Avatar
Super Spam Talker

Posts: 808
Location: UK... where else?
Trades: 0
Right, so does that mean I can't actually do this?
__________________

Please login or register to view this content. Registration is FREE
- Fansite

Please login or register to view this content. Registration is FREE
- Blog
Spud In Disguise is offline
Reply With Quote
View Public Profile Visit Spud In Disguise's homepage!
 
Old 11-28-2010, 11:00 AM Re: Adding Google Pagetracker into link
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
No, just leave it off the onclick call.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-28-2010, 11:07 AM Re: Adding Google Pagetracker into link
Spud In Disguise's Avatar
Super Spam Talker

Posts: 808
Location: UK... where else?
Trades: 0
Ah so something like:

Code:
<script language="JavaScript">

document.write( '<a href="http://www.facebook.com/sharer.php?u=' + location.href + '" pageTracker._trackPageview('share_link/'+ location.href +'');><imgsrc="facebook.png"></a>' );

</script>
?
__________________

Please login or register to view this content. Registration is FREE
- Fansite

Please login or register to view this content. Registration is FREE
- Blog
Spud In Disguise is offline
Reply With Quote
View Public Profile Visit Spud In Disguise's homepage!
 
Old 11-28-2010, 08:11 PM Re: Adding Google Pagetracker into link
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
You still need the onclick=
It's the javascript: you don't want.
PaulW is online now
Reply With Quote
View Public Profile
 
Old 11-29-2010, 04:16 AM Re: Adding Google Pagetracker into link
Spud In Disguise's Avatar
Super Spam Talker

Posts: 808
Location: UK... where else?
Trades: 0
Oh I see! So like this:

Code:
<script language="JavaScript">

document.write( '<a href="http://www.facebook.com/sharer.php?u=' + location.href + '" 

onclick="pageTracker._trackPageview("share_link/'+ location.href +'");">link</a>' );

</script>
Thanks!
__________________

Please login or register to view this content. Registration is FREE
- Fansite

Please login or register to view this content. Registration is FREE
- Blog
Spud In Disguise is offline
Reply With Quote
View Public Profile Visit Spud In Disguise's homepage!
 
Reply     « Reply to Adding Google Pagetracker into link
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.63916 seconds with 12 queries