Google Analytics: script to track outbound links and downloads
Update 2010-08-03! Check out gaAddons v2.0, now with async!
Important! Please see "gaAddons open source project: enhancing Google Analytics" instead.In my opinion, tracking outbound links and downloads should be part of any good web analytics implementation.
Introducing gaAddons.js
The goal of this script is to automate a couple of common tagging requirements: outbound links, download links and email links tracking. It makes the job very easy and reduce risks of errors. Basically, just add a reference to gaAddons.js as explained bellow and voilà!Outbound links:
- Event: "outbound"
- Action: "click"
- Label: target URL
- Event: "mailto"
- Action: "click"
- Label: email
- Event: "download"
- Action: "click"
- Label: URL of downloadable document. The default looks for the following regular expression:
/\.(docx*|xlsx*|pptx*|exe|zip|pdf|xpi)$
It basically says: "Look for any links ending with a dot, followed by any of the popular file extension"
Those can easily be changed in the gaAddons.js script.
Get going with gaAddons.js
To get going, do the following:- Get the gaAddons.js script and save it somewhere on your own server
- Add this line near the closing BODY tag of all your pages, just after the standard Google Analytics tag:
<script src="/js/gaAddons.js" type="text/javascript"></script>
Integrating the code
Your code should look like this:<script src='http://www.google-analytics.com/ga.js' type='text/javascript'></script>
<script type='text/javascript'>
var pageTracker = _gat._getTracker("UA-999999-1");
pageTracker._trackPageview();
</script>
<script src='gaAddons.js' type='text/javascript'></script>
Your tracker variable should be named "pageTracker", otherwise you will need to modify the gaA_pageTracker variable in gaAddons.js code.
Looking at the stats
Once your change is live, give Google Analytics some time to gather data and look under Content/Event Tracking for outbound, mailto and downloads stats (if using events, the default), or under Content/Content Drilldown for /outbound, /mailto or /download statistics if using the page view method.---
Credit where credit is due! A while back, Justin Cutroni at EpikOne published "Google Analytics Short Cuts". This script is an optimized/improved version of his script. Also inspired from the work of Brian Clifton, author of Advanced Web Metrics with Google Analytics


120 comments:
Hi Stephane,
Neat idea with the script. If only Google Analytics would be able to track events as goals. It's the only reason for which i still use trackPageView() for tracking downloads.
However your script sounds the easiest solution to use in tracking outbound links.
Thanks for your post.
Claudiu: good point! And since not everyone has the Events feature enabled, I have just modified the script so you can set bUseEventForDownload and bUseEventForOutbount to false to use trackPageView instead of _trackEvent.
Google Translate:
Hi Stéphane,
a visitor enters the site through Google AdWords. Target is opening price list in pdf format. Prices consider further open page. It is better to use trackPageView..
Tedy: As with any other things in web analytics "it depends". If downloading the document is considered to be a successful business conversion, then yes, maybe tracking the download as a Page View, part of a Goal Funnel, would make sense.
+1 Claudiu: goals and incorporation in custom reports, segments, and motion charts are big weaknesses of the approach
Still, I think it's a great cheap way to enable logging of once per session attributes, entrance *or* exit
I've open sourced a small script for getting google SERP page offset:
http://alwaysbetesting.com/abtest/index.cfm/2009/1/2/Using-the-new-Google-Eventing-for-SEO-Reporting
Perhaps we should merge this with the outbound link tracking, check into github, and let it loose to bloom?
Hi Stephanie,
I installed the gaAddons.js on my site the other day and noticed an interesting phenomenon on my Google Analytics stats afterward. On my site's main profile the events tracking looks great and I can see all of the downloads and exit links. However, on my profiles that track (using filters) sub-directories of my site, my visits numbers went up by about 1000%. Has anyone had this same problem happen to them, and/or know how the gaaddons.js causes it to happen?
Thanks for any help you can provide!
B: that's odd, maybe the filtering is getting broken by the events call? That certainly doesn't sound right to have such a high increase!
Thank you very much for this file Stephane.
Does it work with righ-clicks?
Does this work with right-click... not at this time.
The right-click event (such as when doing a Save As) would be captured with a combination of onmouseup/onmousedown handlers (instead of onclick). You can search for "capture right-click event" on Google for further info.
Hi,
I have event tracking enabled by google and have installed the script on my domain and followed your instructions. Just a little stuck as to how I track outgoing links.
You mention in the blog post:
'Basically, just add a reference to gaAddons.js and voilà!
Outbound links:
* Event: "outbound"
* Action: "click"
* Label: target URL'
For those of use non-techies, can you tell me what a 'reference' would look like to a link such as this:
link text
In other words what should I do to the above html or how do i add a reference to gaAddons.js for this link in my website?
Can you specify what section of gaAddons.js i need to change please.
If anyone else has a clue about this please let me know at: contact at bob harrison dot net.
Many thanks,
Bob
Hi Stephane,
I started using your script last week and found that it was tracking all clicks including internal clicks in Wordpress.
I found the problem on line 26 of gaAddons.js. The else statement needs to exclude clicks for the current domain.
I've been trying to learn Javascript, so I decided to work out the solution on my own first and now I have one that appears to work.
Change line 26 to this:
else if (hrefs[l].hostname !== location.host)
After line 27 insert this code:
else continue;
I hope the code doesn't wreck the
Damon: Thanks for catching this! I've made the fix.
Hi Stephane, I'm using FF 3.06 - how can you tell it the event is being fired when a click occurs? I've got Firebug installed but this doesn't show anything when the click happens. Basically I've set the booleans to false as I don't have event tracking enabled but I'm not getting trackpageview hits in GA. If I modify my HTML and add onClick="javascript: pageTracker._trackPageview('path..'); " to the a element, it see the page view in GA. but nothing when I use the gaaddons.js code
thanks. really want this to work!
Hi Stephane,
Your script works well, however, would it be possible to update it so that it properly tracks clicks on "mailto" links?
Currently, clicks on "mailto" links show up in HttpHeaders as:
utme=5(outbound*click*)
I think it should be more like:
utme=5(mailto*click*name@domain.com)
Regards,
Brendan Halloran.
Hey there,
I've been trying to get your script to work with Google analytics, but for some reason, it just won't go at all. I've tried modifying it, moving where it calls the script, and a few other hare-brained ideas. But everything I try just doesn't seem to work. I'm kind of new to Google analytics, so maybe I'm just not getting it.
Is there anything you can think I'm missing? Both values are set to true, my file list is "(/\.(docx|xlsx|pptx|doc|xls|ppt|zip|pdf)$/i)". I just don't know what else to try.
Any help is greatly appreciated. Thanks.
Great script Stéphane! Thank you very much!
I've installed your script on my server and I noticed that I just could not see the Events Tracking Reports in Google Analytics. I soon realized that I just didn’t have access to this functionality within my GA account, simply because I didn’t have a Beta version for my own personal Web site.
So here are some links that might be useful for others that happen to have the same problem that I had.
First, if you want to benefit from the Event Tracking method, you need to fill that request form from Google (http://spreadsheets.google.com/viewform?key=p7DycufUwNgmtunKEtgNGBg&hl=en).
Secondly, even though you don’t receive any news from Google, you don’t have to wait to see the Event Tracking reports. Here is an article from 3DIssue (http://www.3dissue.com/news/?tag=event-tracking) that shows you exactly what to do. You’ll see, it is pretty easy and very useful.
Thanks for sharing this information with your audience.
Best regards, Antoine Préfontaine ;-)
Hi Stephane,
Do you know if it's possible to modify the script to send data back to multiple GA accounts/profiles?
Brendan.
Thanks for this script! I used to use a google analytics plugin that would do all this but after high CPU usage warnings i'm trying to cut down on plugins and put my own javascript if needed. (Also i noticed WP-Cache stopped analytics from working properly so i want to try it manually)
Would your script also be able to track ad banner clicks? Such as described in
http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55526
That would be really useful! (Too many adsense on too many pages.... can't put them in manually!)
Thanks again!
I have done another round of updates to the script. It will now track mailto links correctly and fixes a number of issues.
Enjoy, and send in your feedback & ideas to improve the script!
Stéphane
Chia: Tracking banner clicks to external links: yes, the script will do it automatically and will show them under "outbound".
Brendan: Sending to multiple account: you would have to modify the script to duplicate each calls so they send values to two different trackers.
Antoine: Thanks for the tips for those who don't have events tracking yet!
Michael & Will: With the latest round of fixes, the script should be working fine for you now. Just get the source code again.
Brandan: The script will now automatically track email links.
Hi Stephane,
I have tested and debugged until I'm red in the face, but I can't get the script to work when I change the setting from true to false. I would like to be able to track these actions using pageviews instead of events. Do you have any further info or updates tnat can be made to get this "switching" working again?
Kind regards,
Brendan.
Hi Stephane,
Your script is working well for tracking events, but it is not working for tracking pageviews.
Firstly, I had to change all references in your script to "trackPageview" from "trackPageView", as the uppercase "V" was stopping the script from working when "false" was set.
Secondly, when I changed all relevant uppercase "V's" to lowercase "v's" and pageview data started to come through, I notice that all that was being recorded was either "/outbound/", "/downloads/" or "/mailto/".
I think that simply copying and pasting the same syntax from trackEvent to trackPageview does not work. You must have to use syntax specific to trackPageview.
Let me know if you would like further information.
Kind regards,
Brendan Halloran.
sorry stephane but your new script doesnt seem to work for me either! Neither events nor pageview works (i tried using both true and false mode). With the previous code, I saw that download events were being tracked (once i added events as per antoine's suggestion), but not outbound links. however i am quite sure that i do have visitors clicking on outbound links as i was using the yoast analytics plugin before this and it registered plenty of clicks.
i've tried both "js/gaAddons.js" and "/js/gaAddons.js". i've placed my script above the content and tried at the end before /body as well. no difference!
the website is www.creatinemonohydrate.net
hopefully it's just a really silly error and not code-related.
thanks for working on this script!
Brendan & chia: I have done another round of fixes, the updated version fixes the trackPageview() call and better validate the presence of the tracker.
Thanks Stephane! I'll give it another shot again today :) Fingers crossed!!!
Hi Stephane,
Thanks so much for being so responsive to our feedback.
The last hurdle for this script appears to be the creation of cookies when pageviews of downloads are required.
When the value is set to false, no cookies at all are being generated when you click on a file in Firefox.
However, a cookie with the filename of the download (no leading /download/ though) is being generated when you click on a download in IE. For example:
&utmp=/filename.pdf
Brendan.
Hi Stephane,
OK, one last thing (I hope!). Are you able to provide some information about how you might specify which domains and/or subdomains are to be treated as internal links and therefore not treated as outbound links?
The issue is that on a website with subdomains, if a user clicks on a link to a subdomain on that website (either to a standard page or file download) then a virtual page name of "/outbound/subdomain.website.com" or "/outbound/website.com/file.pdf" will be generated by your javascript file - this is not desired in many (if not all) cases.
I presume that it is possible to specify what is considered an internal link by defining a variable such as:
var extTrack = [.website.com];
where the leading "." before "website.com" would allow subdomains to be identified as internal links and therefore not tracked as "outbound" links. This would then be integrated into the part of the javascript that handles outbound links and downloads.
I presume that it might also be possible to define the "extTrack" variable to include other domains as internal (where identified as appropriate by the website owner) as follows:
var extTrack = [.website.com|.shoppingcartsite.com];
Let me know if you would like further information, clarification, etc...
Kind regards,
Brendan Halloran.
Still not working :( Both true and false settings. could i be doing something wrong?
Just added the script, just what I was looking for, thanks!
Excellent script!
We're trying to modify this script so that it can track user-defined event types (as opposed to just 'click') to allow us to report to different Business Units of our company.
We'd like to define a variable on the webpage, which the script will then use in place of 'click'.
For example, on a webpage we would have:
(GA Tracking Code)
(Load Stephane's Script)
(Set $SectionSource variable =SomeIdentifer)
For the life of me, however, I'm not certain how to modify the .js to use the $SectionSource variable in instead of a univeral 'click' monicker.
Can anyone provide some help? (and thank you in advance)
Thanks for the script. I added a new function to the script:
function trackLink(url)
{
if(url != undefined)
gaA_pageTracker._trackPageview(url);
}
I can then use this easily in my webpages - for example:
onclick="trackLink('/link/to/page')"
I am mostly using this for internal website links being handled by JavaScript, such as via an onClick event.
I thought I would contribute this change back, as per the license requirements...
Hi,
We are trying to use event tracking ourselves however it only seems to work if we call the trackPageView() function before the trackEvent() function otherwise we get an "undefined object" error.
This is not good as it messes up our visitor stats.
Any ideas how i could fix this?
Hi There,
I need a little help with adding the code. I've uploaded the gaAddons.js script to my server and added the line of code to my page.
Now how do I "add a reference to gaAddons.js" to an outbound link. I see :
Outbound links:
* Event: "outbound"
* Action: "click"
* Label: target URL
Unfortunately, this doesn't mean anything to me. Could someone please walk me through this?
In case you haven't guessed, I'm not a tech guy.
Thanks!
Tyson: the code on your page should look like what's under "Integrating the code" and that should do it.
I am still trying to figure out if it is possible to track "outbound clicks" without having to code eack outbound link - using Google Analytics. There seem to several paid services that can do this.
Stand: the script I'm proposing comes in very handy since you don't have to manually code each links yourself, the script will look at the document structure (the DOM) and add the necessary logical to all external links.
Hi all,
Excuse my ignorance I am no developer and I am trying to apply this code exactly as instructed.
The question is: I noticed in the "Integration" note above that you have used the Legacy GA script.
Will this code still do the job if I am using the latest GA code?
i.e.
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
try {
var pageTracker = _gat._getTracker("UA-XXXXXXX-X");
pageTracker._trackPageview();
} catch(err) {}
Hi Stephane,
Any books or other training resources to learn Javascript for a total newbie?
Thank you.
Tommy: Yes, that will still work. Just put the gaAddons.js code inclusion before the "try"
Alain: I haven't bought programming books in years... there's a "JavaScript for dummies", usually this collection is pretty good, so it might be a good start. Maybe others have ideas?
Thanks Stephane!
I did as per your suggestion and everything is in place just right.
However, I don't seem to be getting any results via GA.
I must be doing something wrong probably :(
Tommy: make sure to include gaAddons.js AFTER the usual GA script. The GA tracker variable needs to be defined before loading the addons. Also, in gaAddons.js, the line should read "var gaA_pageTracker = pageTracker;"
I am back again to say a BIG THANK YOU for all the support you provided!
Finally I successfully started tracking outbound links and downloads :)
Could you provide a sample of how the link should be formatted within the HTML?
I read through the comments and didn't see it mentioned.
Hi, Stephane. Thanks so much for this code.
Do you have a suggestion for how to implement this if we don't have server space to host a .js file? I have a blog on blogspot.
Do you have a suggestion as to a place I could put the code or should I just plug the .js script into my Blogger template?
Reid: Try http://gaddons.googlecode.com/files/gaAddons.js
I'm currently in the process of setting up an open source project for this code.
Stephane, thank you for the script.
I'm following up on Brandon and Tommy's comments. I'm also having trouble getting the script to show its results on the Analytics page.
You say:
1. make sure to include gaAddons.js AFTER the usual GA script.
2. put the gaAddons.js code inclusion before the "try"
This seems contradictory, and I can't tell how you mean it should be formatted. This is how I just tried it, which is not working:
<script src="http://www.google-analytics.com/ga.js" type="text/javascript"></script>
<script src="scripts/gaAddons.js" type="text/javascript"></script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-10400062-1");
pageTracker._trackPageview();
} catch(err) {}
</script>
Can you please clarify?
Thanks so much,
oren
irradiant: heee... reread the post, look at the code snipet example under "Integrating the code"... put the gaAddons AFTER the GA code. Sorry, I can't make it clearer.
I'm also confused.
Should it be:
script type=text/javascript
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
/script
script src='/includes/js/gaAddons.js' type=text/javascript
/script
script type='text/javascript
try {
var pageTracker = _gat._getTracker("UA-xxxxxx-xx");
pageTracker._trackPageview();
} catch(err) {}
/script
or
script type=text/javascript
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
/script
script type=text/javascript
try {
var pageTracker = _gat._getTracker("UA-xxxxxx-xx");
pageTracker._trackPageview();
} catch(err) {}
/script
script type=text/javascript src='/includes/js/gaAddons.js'
/script
Also how can I tell it's working? Does it show up in the page source, or do I just have to wait until it registers in analytics?
Thanks for the script!
Sam: The gaAddons.js script should be included after the standard GA code, although its not a requirement with the latest version of the code.
To check if it works, you should see new stats under /Content/Event Tracking (the default) or /Content/Content Drilldown. Look for Download, Outboud or Mailto.
Hi Stephane, I think what a lot of us are asking is, how does the outbound link code look? Can anyone just type in a simple example for us newbies, please? We're not talking about the js include code, but the actual implementation within the link part of the code.
Thanks.
Rob I see what you mean. But you actually don't have to change your links. The script will detect all links and automatically add the necessary on-click event handling! :)
When I set bUseEventForDownload to false I get a javascript error on every link that says evnt.srcElement is undefined (line 66). It seems to be tracking okay anyway. Is there a way to fix the error though?
Julie: thanks for raising this issue, it's now fixed.
For an outbound link such as http://www.foo.com/ the event name I get in Google Analytics is sometimes
www.foo.com/
and sometimes
www.foo.com//
(with 2 slashes)
It seems to be there are 2 slashes when the navigator is either Chrome or Safari... Any way to fix that?
Nate: should be fixed now.
I'm actually working on making this source code available as an open source project on Google Code. Stay tuned for more info!
Hi,
Does this script will count the number of click a button on form?
thanks
Ludovic: no, this is not the intent, but if you describe your need maybe that's something that could be added in the future.
I already use your script for outbound links but I'd like to also follow events on the forms...
Regarding the issue with double forward slashes being created for outbound links when Safari and Chrome are used, you could replace:
(elmnt.hostname + "/" + elmnt.pathname + elmnt.search).replace(/\/\//,''))
with:
(elmnt.href)
This takes the entire URL of the link, i.e.:
http://www.website.com/page1?query=word
It might look a bit "unclean" in your reports to see "http://", but it's non-browser dependant code.
Regards,
Brendan.
Hi Stephane
How would this affect tracking multi domain tracking?
I need to code the outbound link with onclick (below) and wonder if the gaAddons will override it or can I just rely on its event tracking to link the two?
example of current implementation for cross domain tracking
href="https://www.secondsite.com/?login=parameters" onclick="pageTracker._link(this.href); return false;">Go to second site Now
Hope you can shed some light.
Brendan: Interestingly enough, just 2 days ago I had a flash and I was wondering if my code would overwrite existing onclick events. I'll have to check that.
Alvin: The reason I'm doing it this way is I specifically didn't want to have the QueryString and protocol in there. But your method would work too... although resulting in a little more messy reports :)
Thanks for all those great feedback! As soon as I can free some time I'll complete the open source project on Google Code.
Stéphane
With your new version of gaAddons.js I now get in Google Analytics as an event name (for an outbound link such as http://www.foo.com/):
www.foo.com/
and sometimes
www.foo.com
The no slash version is when the navigator is either Chrome, Firefox or Safari. Note that if the link was http://www.foo.com/here the event name is www.foo.comhere
Hi Stephane,
I use budurl in one of my outbound links and the addon automatically tags on the utm codes which makes it not work.
E.g budurl.com/extlink
When it is clicked, it becomes
budurl.com/extlink?_utm....
That screws up the budurl link.
Is there a way to manually override that automatic tagging appended on the budurl outbound and manually tag it with onclick="pageTracker._trackPageview('/extlink')
?
Thanks
Nate: I have just posted another enhancement to the outbound links tracking. It should be fine now!
Alvin: I'm not sure I understand your issue. What do you mean by "it screws up the budurl link"?
The gaAddons waits for the whole page to be loaded, then looks at all A HREF links and ads an onclick event which fires a call to trackPageview() or trackEvent().
Basically, when you mention by manually overwriting your link is what gaAddons does automatically...
Hi Stephane
Using the Onclick parameters actually renders the redirects like Budurl unusable as it doesn't redirect once there are any additional parameters tagged behind it.
Good news is that stripping out that onclick and relying on your event tracking script, it Works!
I had wanted to tag the event with a different name which was why I had the onclick.
Anyway to tack on custom tags on event tracking?
Great job on the script, by the way.
Alvin: still find it strange because the script doesn't add any parameters to any URLs, it just adds onClick events...
You could change the line that says:
if (hrefs[l].hostname != location.hostname)
To:
if (hrefs[l].hostname != location.hostname && !/budurl/.test(hrefs[1].hostname))
This way, the script will NOT track bururl links.
Hi Stephane,
What I meant was when I used the manual tagging with the Onclick parameter, it tagged on the _utm codes behind the budurl.com/xxx?_utma.. and that screwed up budurl redirect.
I removed the manual tagging and relied on your script event tracking alone and it works.
I had wanted to tag the outgoing link with custom name like "/orderpage".
Anyway, I am getting the stats now without the custom name.
Awesome script!
Any simple way to tracking image links?
we have several logos with links attached, I would like to be able to capture these too.
Thanks
Jack: change the line that says "gaA_fileTypes" to include the file extensions of your images (i.e. gif, jpg, png)
Does gaAddons.js is compatible with the asynchronous tracking script?
http://code.google.com/intl/fr-FR/apis/analytics/docs/tracking/asyncTracking.html
Ludovic: No, gaAddons is not actually compatible with the new GA async metho. But give me some time and I'll offer a version that works fine with it.
Thanks for the excellent script. 1 question that I couldn't find in the comments: are events (such as using an external link, downloading a file or sending an e-mail) considered as a new pageview, or are they considered as isolated events that do not add up to the total number of pageviews?
I used a script that tracks these events as pageviews, so changing this method would make this number drop (which is not a bad thing, but I do need to make sure such is the case to justify these new numbers within my organisation).
Inge Janse: events are tracked somewhat differently than page views: they won't add to the page view count, but they will influence the bounce rate.
Thank you for your comment. You mean that an event does not add up to the total number of pageviews, but that if a visitor has 1 pageview and 1 event, he is not considered as a bounced visitor (ie: 1 page + 1 event = no bounce)?
Inge Janse: That's exactly it: an event does not add up to the total number of pageviews, but that if a visitor has 1 pageview and 1 event, he is not considered as a bounced visitor (ie: 1 page + 1 event = no bounce).
Then this is truelly one of the best scripts I've ever seen. It works like a charm, and gives excellent information without polluting my stats. Thanks a lot!
One more question for now: are events only logged if the left mouse button is used? For instance, opening an external link in a new tab (via middle mouse button or context menu via right mouse button), is that also logged as a click?
Inge Janse: tracking right-click on download links: the way the script is actually done, I don't think it will track it. But that's a pretty good idea for a future update!
Hi Inge and Stephane,
You can actually track all mouse actions by replacing "click" in the code with "mouseup". This has the effect of tracking the release of the left, middle and right mouse buttons.
And if you are really interested in tracking all activity, you can add a similar line of code for "keyup", which will track the release of all keyboard keys. However, seeing as you should only track when the "enter" key is released, you will need to add a filter to your profile/s to exclude non-"Enter" key related actions.
If you are interested in seeing how this works, you can visit the following website to see how the Google Analytics Tracking Code is implemented:
www.diird.vic.gov.au
The URL of the gaAddons.js file for this website is:
www.diird.vic.gov.au/__data/assets/js_file/0009/119592/gaAddons-diird.js
As you can see from this gaAddons.js file, it has been modified from Stephane's original script and relies upon a bit more customisation an JS knowledge to implement.
I would be very interested to hear any feedback.
Regards,
Brendan.
Brendan That's something that could definitely be added to gaAddons.js, just lacking time to get going with the open source project.
Thank you for such a great script. I have implemented it on our companies intranet.
For the record, I am not a java coder. :)
Question: While viewing the downloads report in GA, is there a way to give the downloads a more friendly name than "clicks". I'd love to name the downloads report "Requested_Files". Is this possible?
Cheers!
Brian B.: to change "clicks" to "Request_Files" just save a local copy of gaAddons.js and search for that string in the code.
Hi Stephane..thanks for the response...I assume you mean change this line of code from:
bUseEventForDownload ? gaA_pageTracker._trackEvent("download", "click", pathname) : gaA_pageTracker._trackPageview("/download" + pathname);
To this:
bUseEventForDownload ? gaA_pageTracker._trackEvent("download", "Requested_Files", pathname) : gaA_pageTracker._trackPageview("/download" + pathname);
Brian B.: exactly! :)
Don't mean to push you but any idea when code for the new GA Asynchronous tracker will be available. I've started moving our sites over to this but obviously want to maintain the 'event' tracking bit as well.
Thanks for all your work on this.
Cam: I intend to do a complete rewrite in a more object-oriented form that will easily support async-calls. However... this being an open-source/free project, it tends to fall lower in the list while I focus on consulting, teaching & speaking :)
Sorry, I'm posting again as I was not clear originally...
---
Great script! third one I've found that tracks downloads, but no others have seemed to work!
Question: line 73 of v2.8
var pathname = ("/" + elmnt.pathname).replace(/\/\//,'');
in a Visual Studio .js file gets made into a 'comment' due to the //
I'm worried this will break the script as [ //,''); ] is all a 'comment'. Anyone using VS and have this problem -or- anyone have ideas of what I can do to fix this?
THANKS!
Stephane,
Thanks for putting together a great script.
Could you add an event tracker to it for "onmousedown"?
I want the script to track right-click save-as downloads of PDF files.
Or what HTML should I add to the script to make this happen?
Lou,
I would recommend using "mouseup" because it would more accurately track the completion of right and middle mouse clicks as well as the standard left mouse click.
See my post from Dec 10 for more info about this and other features.
Brendan.
under "To get going, do the following:" item 2, the path sample to the script contains /js/
under "Integrating the code" your other sample does NOT have /js/
took me sometime to figure out that the samples had an error.
thanks for the great addon
OK, this script works ok, but I need to be able to see from which page the outbound link was clicked from. How can I implement this?
Thomas T: you could modify the script to suite your needs. I'm working on a newer/better/enhanced/super version. However, I'm providing the script "as is" - I'm not providing support for it. If you don't have experience of JavaScript you can use as is or find an experienced JavaScript developer who should be able to help you.
Thomas T: there are a couple of ways to do this.
1. If you have implemented using trackPageview, you can run a navigation summary report like you would for a standard page.
2. You can add some JS code to the trackEvent variable that will automatically append the URI of the page that the link was clicked on, as well as the text of the link.
Simply replace the following in your script (disregard the square brackets of course):
[ + " From page: " + sPage]
with (IE version):
[ + "&refURL=" + location.pathname + location.search + "&LinkText=" + elmnt.innerHTML]
and (non-IE version):
[ + "&refURL=" + location.pathname + location.search + "&LinkText=" + this.innerHTML]
The difference between the IE and non-IE version is "elmnt.innerHTML" and "this.innerHTML".
Wonderful script! In about 2 hours I start to get the number in the analytics panels. BUt..
Can I track Flash outbond links? How?
Alex Tracking links in Flash must be done manually in Flash itself, the script can not be used for this purpose.
Is it possible to track internal links that get redirected to external sites?
I have urls that are for e.g.
mysite.com/goto/external-site/
which is 302 redirected to the external site
Tim: you could start from the gaAddons.js and make a minor modification to also track specific internal links - but better still would be to fix the link to avoid the redirect.
You might also want to read How Does Google Analytics handle 301 and 302 Redirects?
Tim,
I too have come across this problem with one of the websites my web team looks after. The developers implemented it this way to make managing external links easier.
I am using a modified version of Stephane's code (with his approval), so the way we have handled this is quite different from the solution that would apply to Stephane's current gaAddons code.
However, I think that the code you need to add (if you're using Stephane's latest version) is:
else (hrefs[l].hostname.indexOf('mysite.com/goto/') != -1) startListening(hrefs[l], "click", trackExternalLink);
after the existing line of code:
else if (hrefs[l].hostname != location.hostname) startListening(hrefs[l], "click", trackExternalLink);
Hopefully this works! Let me know if it doesn't.
Brendan.
Thanks for the advice Stephane and thanks Brendon for the code adjustment suggestion.
I tried something similar to your suggestion Brendan and then I tried the exact same code but it looks like it's still not tracking correctly :(
I'm not sure what I'm doing wrong...
Tim - let me know what your website is and I'll use Firebug to see what's going on.
Brendan.
Thanks Brendan but looks like I managed to get it to work! :)
I didn't realize you could debug javascript in firebug so after you mentioned it, I saw what I was doing wrong and ended up using this to get it to work:
else if (hrefs[l].href.indexOf('mysite.com/goto/') != -1) startListening(hrefs[l], "click", trackExternalLink);
Using "onClick" event in the links you may lose some data about clicks.
If you click the right button and select the context menu "Open in new tab" - event onClick does not work.
I posted recently why so here
mev: I agree we might miss some data with just onclick, but onmouseup might collect too much! Realistically, even if a % of clicks are not tracked, we are still in the realm of a statistical population with an acceptable margin of error. Unless specific exceptions - like the ones you mentioned in your post, casual users will use the regular left-click button. But then again... it depends :)
It all boils down to the kind of decision you want to make with this data (left or right click).
Stéphane
Hi Mev,
I too use onmouseup, because it tracks all mouse buttons - left, right and scroll (middle).
I also use onkeyup to track when people use the enter key to activate links. However, you need to add a couple of filters to your Google Analytics profiles to ensure only the enter key is tracked. This means that you have to use trackPageview instead of trackEvent.
Brendan.
Is it possible to track mp3 files too ? How do I remove the tracking of "mailto" ?
hindi To track mp3 files, just modify the line in gaAddons.js where it says gaA_fileTypes and add it there.
For mailto, find the two lines where it says protocol == "mailto:" and comment them.
Any word yet on a possible Asynchronous gaAddons.js version? THANKS!
BHC: I have a version of gaAddons with async calls I'm actually testing... just a matter of time & priority :)
Stéphane, I would totally be your best friend... haha! But understand the time it really does take, let alone the testing and support required. Appreciate all that you have put into this project, as have found your code to be the best script out there for this type of extra tracking.
Dear Stephane. I will be waiting for that Asynchronous gaAddons.js version as well. Thanks a lot in advance for doing a great job.
Great idea on the script. I cannot get it to work, however...
I am using the latest GA code - it's in the header.
At the end of the page we pasted in your code, including the link to 'http://www.google-analytics.com/ga.js, which doesn't make a lot of sense to me?
(We modified the UA- number to match ours.)
Still nothing shows up in Analytics. What else should we have to do?
thanks!
lsmith this won't work, I'm afraid you'll have to wait for the async version of gaAddons or find someone who can help you with your implementation.
the script seems to work great thanks. However, we seem to have one problem with the downloads. Most files appear twice in the reports, as the forward slash doesn't always get appended after the word download, e.g.
/downloadsite_files/barcode_tutorial.pdf
/download/site_files/barcode_tutorial.pdf
Is there anything we can do so all files have the exact same path?
The question was raised how to track opened/viewed emails in Google Analytics. To do so, insert a pixel into your email. The pixel you can get from free providers like: http://email-tracking-with-google-analytics.com/
That worked well for me.
Is there a way to use this tracker in Blogger? I'm really not familiar with html coding or anything like that, so if you could let me know the steps i would have to take to get this installed that would be great!
Tracy: Check http://immeria.net/gaAddons for a newer version of the script and instructions as well as Blogger thread about integrating Google Analytics at http://www.google.com/support/forum/p/blogger/thread?tid=288a9d460e545ef1&hl=en
Please note: I can't provide free extensive support for your specific integration of gaAdddons. Above info might be enough to get you started but if you don't know HTML or JavaScript enough you should be able to easily find a consultant who will be happy to help you :)
Post a Comment