"Helping businesses operate more effectively online"

11

Feb

2008

How to track downloads in Google Analytics automatically
Written by David Towers   

Google Analytics download tracking We use Google Analytics here because it is a great tool to help us understand our visitors. Today we're going to talk about a way to track if visitors download files or click on links to external websites.

Tracking this sort of behaviour may be really important to see if people are interacting with the web site the way intended. For example, businesses that have their brochures or product catalogues downloadable as PDF's.

The official Google Analytics help says that any link can be monitored if this script is added in the link:

onclick="pageTracker._trackPageview('/file_name.file_extension')

Adding this script to every download link on your website can be a laborious task.

Tracking downloads automatically

The simple solution we found is to use a JavaScript that automatically attaches event listeners to files which are downloaded from your web pages.

What sort of downloads can you track automatically?

Using the javascript you can track the following file extensions:

  • doc, eps, jpg, png, svg, xls, ppt, pdf, xls, zip, txt, vsd, vxd, js, css, rar, exe, wma, mov, avi, wmv, mp3
In addition to tracking these downloads, the JavaScript will also track clicks on links to external websites and include these in your Google Analytics statistics.

How do you install the tracking JavaScript?

Is it really that simple?

Yes, but note that this tracker is written for Google Analytics new tracking code which uses the lighter ga.js. If you are using the old tracking code with urchin.js you can still track file downloads but not using this link tracking JavaScript. Check out this site for more information on tracking download links with the old tracking code.

How might download statistics be useful?

Taking the example of a business that has its product catalogues downloadable as PDF's: If through Google Analytics they can see that users are not downloading their catalogues they might consider redesigning the web pages to give more prominence to these downloads.

Another example could be a software company wanting to measure how many users download their software from their web site. Using this JavaScript they could measure the number of downloads and even set up goals in Analytics to measure the conversion rate.

How will you use the statistics generated by this Javascript? Please post any comments or questions you have about this JavaScript in the comments below.


145 Comments
0
Bobwill
February 12, 2008
Votes: +3

I have a question after reading your suggestion. Could I add your code to the front of the ga.js code and then just do the following in my html file or would this mess up the loading or would there be some other modifications to make?

< script src="http://www.mysite.com/scripts/ga.js" type="text/javascript">

report abuse
vote down
vote up
63
David T
February 12, 2008
Votes: +4

Hi Bobwill,

I'm not sure I've understood your question... The idea of this code is simply to add it before the analytics code on each web page...

Implementation is really simple because you can just search through your entire site replacing your standard analytics code:

< script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://
ssl." : "http://www.");
[removed](unescape("< script src='" gaJsHost "google-
< /script >"));
< /script >
< script type="text/javascript">
var pageTracker = _gat._getTracker("UA-0000-1");
pageTracker._initData();
pageTracker._trackPageview();
< /script >

with:

< script type="text/javascript" src="http://www.yoursite.com/script/
< /script >
< script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://
ssl." : "http://www.");
[removed](unescape("< script src='" gaJsHost "google-
< /script >"));
< /script >
< script type="text/javascript">
var pageTracker = _gat._getTracker("UA-0000-1");
pageTracker._initData();
pageTracker._trackPageview();
< /script >

Does that clarify it?

report abuse
vote down
vote up
0
Bobwill
February 12, 2008
Votes: -1

OK, I misunderstood your explanation. The statement on your web site says "To use, place this file on all pages just above the Google Analytics tracking code." To me that meant all the "js" code (the file) needed to be inserted as the top of the "ga.js" code. Your saying to place a line of code that loads the "gatag.js" script at the beginning of the "ga.js" script. I guess I am dense. I will try to make it work.

report abuse
vote down
vote up
63
David T
February 12, 2008
Votes: +0

Glad it's clear now, thanks for your comments. Hope you get it working!

report abuse
vote down
vote up
0
JP
February 23, 2008
Votes: +1

Excellent Excellent Excellent Article!!!! Great Job Indeed!!!!

report abuse
vote down
vote up
63
David T
February 23, 2008
Votes: +1

Hi JP!

Welcome to Good Web Practices! Thanks for posting your encouragaing message! smilies/smiley.gif

report abuse
vote down
vote up
0
eagleeye
February 23, 2008
Votes: +2

Seems a simple and great solution to tracking downloads. I have added the code and am just waiting for Analytics to process.

Will be using this to track downloads of PDF brochures and application forms.

Maybe I missed something but where in Analytics will this be displayed? The little graphics at the top are too small to make out.

report abuse
vote down
vote up
63
David T
February 24, 2008
Votes: +0

Welcome to Good Web Practices Eagleeye!

It's great you've installed the script.

So the statistics for the downloads and external links will appear as content items. E.g. Within Google Analytics navigate to the "Content" section then select "Top content". The PDF's will be listed in here along with your websites pages. If you can't see the PDF files use the "Find URL" box and enter pdf then press "Go". This will bring up all the stats for your PDF downloads!

This script is a great way to track PDF brochure downloads, we've actually put it to use for the same purpose on other sites! Please let us know how you get on!

report abuse
vote down
vote up
64
Alex A
February 24, 2008
Votes: +2

Remember you can also set Analytics to have the download of files set up as particular goals for your website. This can be very useful to view your success rate!

report abuse
vote down
vote up
0
eagleeye
February 26, 2008
Votes: +0

So far I have added the script to one site and it has recorded a few PDF downloads and clicks on external links. It seems to be doing the job. I will add it to our main site and see how it compares with the onclick code we are currently using.

Alex A - we are already using goals to monitor specific downloads we want to track. I don't see the above code as replacing this but more as an easier way to monitor all downloads and clicks on external links.

report abuse
vote down
vote up
63
David T
February 27, 2008
Votes: +2

Delighted to learn that you have added this tracking script to one of your websites and it has worked eagleeye! Thanks for giving us the update!

report abuse
vote down
vote up
0
Raju
March 06, 2008
Votes: +0

hi david
i read your article, well i implemented the way you have explained it, but when i insert the onClick code in the link, my page got scattered around, i just want to track how many people are downloading my zip file.
Can you pls help me in this?
raju

report abuse
vote down
vote up
63
David T
March 07, 2008
Votes: +0

Hi Raju welcome to Good Web Practices!

You don't need to add the onClick code to the link!

The only thing you need to do is add the Javascript code before your analytics code. The Javascript automatically adds the tracking for downloads so that you don't need to add it to each link. You just need to follow the instructions above... There is a discussion about someone having problems adding the code here: http://groups.google.com/group...3be1899603

Hope you'll get it working Raju!

report abuse
vote down
vote up
0
super015
March 13, 2008
Votes: +1

we have built in a document repository so that true URLs and file names are obfuscated. This means that the filepath is in the db and you simply get a pointer, so that Competition_FAQ.pdf is actually a URL like http://[url]/download/12345.

It seems that the best way to track this is to add "|download" to the line

var isDoc = path.match(/(? :doc|eps|jpg|png|svg|xls|ppt|pdf|xls|zip|txt|vsd|vxd|js
|css|rar|exe|wma|mov|avi|wmv|mp3|download|forward)($|&)/);

Is that correct?

report abuse
vote down
vote up
0
Danny
March 14, 2008
Votes: -1

Will this be able to track and uniquely identify the downloads if they are loaded via a javascript pop up window ?

I have my site setup so that our PDF catalogs open in a new pop up window.
example url:

report abuse
vote down
vote up
0
Danny
March 14, 2008
Votes: +0

my sample url seems to have been blocked somehow...but it is a basic javascript pop up [removed]pic('catalogs/golight.pdf')

will it be able to track a url like this ?

report abuse
vote down
vote up
0
Don
March 15, 2008
Votes: +0

Hi,
Would this code work with any stats package that uses a paste in javascript snippet to do it's counting? What would the other package have to do to mesh up with your code?

I ask because I'm testing some others in WordPress.
GA is nice but it takes way too long to find the data I want and I don't need most of what it provides.

report abuse
vote down
vote up
63
David T
March 19, 2008
Votes: +0

Hi Super015, Danny and Don! Thanks very much for your posts.

With regards to the implementation of this code, you'll find the answers to the majority of your questions here: http://groups.google.com/group...3be1899603

Super015, if your download link is http:///download/12345, the download will be included in the stats as "external/http:///download/12345" This means your downloads are tracked without needing to edit the javascript.

Danny, if the downloads are loaded via a javascript window, I'm afraid that this javascript won't be able to track the downloads. You could ask ShoreTel about how to do this on the Google Analytics forums.

Don this script is designed to work with Google Analytics. I'm surprised Analytics hasn't met your needs, I'd encourage you to stick with GA as once you get familiar with the setup its fantastic.

report abuse
vote down
vote up
82
Brian Katz
March 21, 2008
Votes: -1

Hi David T and Don

David - I am yet to implement it but its clearly a great piece of code,

Don, if you need your analytics almost instantaneously you may have to spend $$$ on SiteCatalyst or use something like AWStats
(http://awstats.sourceforge.net/)

The code should work with any JS-based tracking code that implements link tracking. Just substitute the call to pageTracker._trackPageview for the equivalent in the other package.

However, YGWYPF - in analytics apps that you pay for it might be unnecessary - eg SiteCatalyst allows you to track specified extensions automatically.

Brian Katz
www.vkistudios.com

report abuse
vote down
vote up
0
super015
March 25, 2008
Votes: +0

Thanks David.

When I go to Google Analytics and look up content > overview or content > drilldown, I do a search for anything with "download" in the URL and they are not showing up. Do I need to remove the edit I made to the isDoc variable?

Thanks again

report abuse
vote down
vote up
82
Brian Katz
March 26, 2008
Votes: +1

Hi super015 and Danny

super015, at a glance it seems like the mod to isDoc will not work because it requires that the URL must *end* with one of the extensions - note the ($|&) at the end of the regex pattern.
However, David's code, I understand, is intended where you cannot modify all the code on a site.

There must be a single piece of server-side code generating your URLs - that should be changed to generate the complete tag you need.

Danny, if your downloads are opening in another window, is that window being tracked - if it is, you will probably not want to trigger a _trackPageview because you would be counting 2 pageviews for the "download"

Brian

report abuse
vote down
vote up
0
Mark Freeman
March 27, 2008
Votes: +0

I added the code, but I am getting an error:

Error: uncaught exception: [Exception... "Component returned failure code: 0x804b000a [nsIDOMNSHTMLAnchorElement.hostname]" nsresult: "0x804b000a ()" location: "JS frame :: http://webauthoring.tercenim.com/gatag.js :: :: line 20" data: no]

Any ideas?

report abuse
vote down
vote up
0
super015
March 28, 2008
Votes: +0

Brian, thanks for the info. I'm no longer that technical and am very rusty on regex. I do know that with our repository, every document path ends in a 5-digit number (e.g., /forward/12345 or /download/54321). How could I modify the isDoc regex for this?

report abuse
vote down
vote up
82
Brian Katz
March 28, 2008
Votes: +2

super015 & Mark,

Mark, in what environment are you executing the script?

super015,
I'm an Analyst with enough JS to be dangerous smilies/smiley.gif

On the assumption that *all* your downloads are in the form described and that the urls end as you indicated above, it looks safe to change the Regular Expression pattern to

/(?:document|forward)/(?:[0-9]{5})(?:$|&|?)/


You want to be careful not to match URIs other than those intended, so that pattern limits matches to 5th digit either ending the URI or being followed by a query string or a &

If you want to test various scenarios, use The RegEx Coach (http://weitz.de/files/regex-coach.exe)

Brian
http://www.vkistudios.com/people.html

report abuse
vote down
vote up
0
Brian Katz
March 28, 2008
Votes: +1

Hi David T and Mark

I did not look closely at Mark's error that closely but I got a similar error totally unrelated to gatag.js. It was within FireFox's code, or more likely, one of its add-ons (Web Developer)
I returned to look at Mark's error and see that unlike mine, it refers to line 20 of gata.js itself.

Mark, what are the values of all variables before line 20?

Brian
http://www.vkistudios.com/people.html

Oh! Mark - what browsers have you tested this in and in which one(s) does the error show up?

report abuse
vote down
vote up
0
Brian
March 29, 2008
Votes: +1

Hi David T and Mark

I've now encountered that error too:
Error: uncaught exception: [Exception... "Component returned failure
code: 0x804b000a [nsIDOMNSHTMLAnchorElement.hostname]" nsresult:
"0x804b000a ()" location: "JS frame ::
http://www.goodwebpractices.com/script/gatag.js :: :: line 20" data: no]

It occurs if the page contains anchors that have no href attribute at all.

There will have to be a test to see if hrefs[i] has an href attribute.

Brian
http://www.vkistudios.com

PS I'm going to be at the eMetrics Summit in Toronto next week - if you're going to be there, visit me at VKI Studios' Exhibitor's booth


report abuse
vote down
vote up
0
Brian
March 29, 2008
Votes: +1

Last post should read "hrefs[ l ] has an href attribute". Brian http://www.vkistudios.com
-

report abuse
vote down
vote up
0
super015
April 01, 2008
Votes: +1

OK I've figured out my question with a little but of regex brushup.

All of our links go to either download/ or forward/ with a 5-digit id number after the slash. Ergo the regex is:

var isDoc = path.match(/(?:download|forward)(/d{5})/);

report abuse
vote down
vote up
0
Travis Knutson
April 02, 2008
Votes: +0

I put this in and PDFs and downloads work great, but I can't seem to find external links. Am I missing something on where to look in top content?

report abuse
vote down
vote up
0
Erik Vold
April 08, 2008
Votes: -1

Why do you make the following suggestion:
Add the following JavaScript code just before your Google Analytics tracking code:

< script src="http://www.yoursite.com/scripts/gatag.js" type="text/javascript" > < /script >

??

The order doesn't really matter from what I can tell, did I miss something?

Also, gatag.js should really be as close to the tag as possible, because if ga.js were called right after the tag, and you placed gatag.js before ga.js, then gatag.js wouldn't work at all, because document.getElementsByTagName("a") would return an empty array, even though there maybe links on the page.

report abuse
vote down
vote up
0
Erik Vold
April 08, 2008
Votes: +0

I meant to say: 'gatag.js should really be as close to the [end body tag] as possible, because if ga.js were called right after the [start body tag],...'

report abuse
vote down
vote up
0
RobP.
April 23, 2008
Votes: +0

I've tried the script on our website but I don't see any PDF's in my Stats online. Am i looking in the wrong place maybe or do I have to setup something like a goal or filters to view the stats online in Google? Thanks

report abuse
vote down
vote up
63
David T
April 23, 2008
Votes: +0

Hi everyone, thanks for posting.

RobP. and Erik, you need to wait a couple of days after installing the stats to see them.

The statistics for the downloads and external links will appear as content items. To see the external pages: navigate to the "Content" section then select "Top Exit Pages". The external pages will be listed in here along with other exit pages. If you can't see the external page use the "Find URL" box and enter external then press "Go". This will bring up all the external pages the script has tracked.

report abuse
vote down
vote up
0
RobP.
April 24, 2008
Votes: +0

Unfortunately still nothing. I have had it on our site for over 2-3weeks now. I don't know what I'm doing wrong I've checked everything I could think of. Can you check the source on any of my pages to see if it's in there correctly? The only change I made was where the gatag.js is stored which is the js folder vs. scripts. That wouldn't make any diff. would it? Site: www.uconucedd.org

report abuse
vote down
vote up
0
RobP.
April 24, 2008
Votes: +0

sorry that should be www.uconnucedd.org

report abuse
vote down
vote up
63
David T
April 24, 2008
Votes: +0

Hi Rob! Just checked out your page. You have got the link to gatag wrong! You've made a mistake in the path. Change from this:

../js/gatag.js

to this:

http://www.uconnucedd.org/js/gatag.js

That will work.

BTW I'd recommend you remove your old google tracking code and taglinks!

report abuse
vote down
vote up
0
RobP.
April 29, 2008
Votes: +0

That was just the homepage. The others used a diff. template which I did update previously to the correct path. But I'll update the home page too. Thanks. But do you think that the hompage if incorrect would stop the other pages that have pdf's from showing up in the reports?

Thanks Again!

report abuse
vote down
vote up
63
David T
April 29, 2008
Votes: +0

Hi Rob,

I'm sure we will be able to get it working on your site!

I checked the tag you added and you've done it wrong again: " < http://www.uconnucedd.org/js/gatag.js "

report abuse
vote down
vote up
0
RobP.
April 29, 2008
Votes: +0

DOH!! :-D

report abuse
vote down
vote up
0
Declan
April 29, 2008
Votes: +0

I'd like to post a link on an external site that goes directly to my .zip file for download. How do I track that? It works great if you get the link from one of my existing pages.

How can I get it so that the zip file gets measured if it is downloaded directly from external sites?

report abuse
vote down
vote up
0
Richard N
April 29, 2008
Votes: +0

Declan why don't you send them to the webpage that contains the .zip file first? Then all they have to do is click the download button and you'll be able to track it using this script.

Have you got the updated ga.js installed?

report abuse
vote down
vote up
63
David T
April 29, 2008
Votes: +0

Hi Richard N - thanks for your good advice - it's always better to get people to the webpage as you can track them better... But it does happen that people hotlink files.

Hi Declan. Using Gatag.js you will be able to track on "site 2" how many people go to download the zip file on "site 1" because "site 2" will record how many people click on the link to download the zip file as the link will be included as an external link in the content stats.

If you want to see on "site 1" how many times the zip file has been downloaded from external sites, I would suggest checking the server log files to see how many times the zip was downloaded... Most hosting have AWstats installed which you could use to check this. Otherwise, take Richard N's suggestion and send the users to the html page. :-)

report abuse
vote down
vote up
0
Richard N
April 30, 2008
Votes: +1

Wow, I installed the script yesterday and now I can actually find out which PDF files and external websites are the most popular. It certainly is worth downloading and installing.

David T, have you guys got a paypal account for donations?

report abuse
vote down
vote up
63
David T
April 30, 2008
Votes: +0

Hi Richard! Delighted the script has worked as hoped! We'd appreciate any donations, here is how you can donate:
http://www.goodwebpractices.com/donate.html
Thanks again Richard.

report abuse
vote down
vote up
0
ben
May 05, 2008
Votes: +0

If I use target="_blank" to open a file in a new window, I get a script error:

urchinTracker is not defined
urchinTracker(file_path);

Has anyone else had this problem?

report abuse
vote down
vote up
63
David T
May 06, 2008
Votes: +0

Hi Ben! I've not had this error no... If you provide a link we could perhaps check that out for you?

report abuse
vote down
vote up
0
ben
May 09, 2008
Votes: +0
report abuse
vote down
vote up
0
Richard N
May 09, 2008
Votes: +0

David, the PDF and external tracker worked for a day and now it has stopped working.

Can you see anything wrong with the tracker on www.rockingham.wa.gov.au? The links on the right hand side should be mostly externals and PDFs are under the Employment section.

report abuse
vote down
vote up
63
David T
May 09, 2008
Votes: +0

Hi Richard, try putting gatag.js just above the analytics code, so below externalsitesPDF.js. What is externalsitesPDF.js by the way?

Where in Analytics are you looking for to see how many pdfs have been downloaded?

Ben, the error occurs in IE, not in Firefox. I notice you edited the script, might it be because you changed something? Otherwise the other option would be to get ride of target="_blank"...

report abuse
vote down
vote up
0
stefan
May 11, 2008
Votes: +1

Thank you very much David, it works perfect for us!

I can see downloaded pdf and hits on external links. It even tracks if someone hits the back button, like: /external//history.go(-1)

We have most clicks on: /external//
What is happening in that case? Is it our "home?"

Saludos

report abuse
vote down
vote up
0
Richard N
May 12, 2008
Votes: +0

Hi David

Thanks for that, I think I had duplicated the javascript by accident, it looks to be working now.

I was looking under Top Content and typing in pdf and external as the filter criterion.

Cheers

Richard

report abuse
vote down
vote up
0
David
May 24, 2008
Votes: +0

How Can I track Adsense clicks ?

I want to know which ads was clicked .

thanks in advanced

report abuse
vote down
vote up
63
David T
May 24, 2008
Votes: +0

Hi David, as far as I know, it's not possible to track which Adsense ads are clicked...

report abuse
vote down
vote up
0
Brian Katz
May 27, 2008
Votes: +0

Yes, GA Reports do not appear to help much here but ...

The HTTP Header sent when clicking an AdSense link on a content network site identifies the advertising site as the referrer.

So you should be able to detect the referrer with JavaScript using document.referrer and add that to one of the variables sent to Google
(eg as a parameter to the Request URI using _trackPageview() or set the User Defined value using _setVar(), etc)

If using a PageView-based field like Request URI you will need a filter to override a visit-based field (like Campaign Source) to the referrer so that you can segment your AdWord reports by that field.

You might also be able to use Geo and other automatically available segmentation to narrow things down a bit.

Brian Katz
http://www.vkistudios.com

report abuse
vote down
vote up
0
Jesse Kanclerz
May 30, 2008
Votes: +0

This is working great on my Joomla installation!

How about a tutorial on how to track feedburner email subscriptions? I.E. Subscriptions that are done through the on-site form, and not by clicking a link.

report abuse
vote down
vote up
0
David T
June 04, 2008
Votes: +0

Brian thanks for contribution on this post...

Thanks for the suggestion Jesse!

report abuse
vote down
vote up
0
Justin
June 09, 2008
Votes: +0

Hi, I would like to track mp4 download, do I simply have to add mp4 in this list:

path.match(/(? :doc|eps|jpg|png|svg|xls|ppt|pdf|xls|zip|txt|vsd|vxd|js
|css|rar|exe|wma|mov|avi|wmv|mp3)

or is there something else to do ?

report abuse
vote down
vote up
63
David T
June 09, 2008
Votes: +0

Hi Justin, yeah it really is that simple, you just need to add mp4 to the list. smilies/smiley.gif

report abuse
vote down
vote up
0
Justin
June 09, 2008
Votes: +0

Great! Thanks for this fast answer smilies/wink.gif

report abuse
vote down
vote up
0
David T
June 09, 2008
Votes: +0

You're welcome!

report abuse
vote down
vote up
0
Sebastian
June 11, 2008
Votes: +0

Hello,

need help:
I Track on two Accounts and modified the gatag.js,
but im so bad in JavaScript - it dosn't works.

Here ist my Script:
http://www.rsb-online.de/common/scripts/gatag.js

My well working Google Tracking Code:
Look at the html Code of http://www.rsb-online.de.

Good Blog - Stay Tuned Guys!
Sebastian

report abuse
vote down
vote up
0
bk
June 12, 2008
Votes: +0

Hi Sebastian

Would you please give us a bit more detail:
1) what changes did you make
2) what is not working - is it giving you errors on the page or is it not showing up in GA?

Thanks
Brian Katz
VKI Studios - Google Analytics Authorized Consultants
http://www.vkistudios.com

report abuse
vote down
vote up
0
Sebastian
June 12, 2008
Votes: +0

Hello,

2) It ist not showing up in GA.

1) I change

this line
if (typeof(pageTracker) == "object") pageTracker._trackPageview(mailto);

to this line
if (typeof(firstTracker) == "object") firstTracker._trackPageview(mailto);

AND

this line
if (typeof(pageTracker) == "object") pageTracker._trackPageview(lnk);

to this line
if (typeof(firstTracker) == "object") firstTracker._trackPageview(lnk);

This is my third guess AND NOW IT WORKS!
Sure it for first time it only works on the
fist account but i think if i add this line:
if (typeof(secondTracker) == "object") secondTracker._trackPageview(lnk);
Comes the data on the second Account too.
I post the result...

Sebastian

report abuse
vote down
vote up
0
Brian K
June 12, 2008
Votes: +0

Hi Sebastian

If secondTracker was created with a different UA account number it should be sending data to a completely different account.

If you don't get the results you want, we will need to know how the 2 tracker objects (firstTracker and secondTracker) were created.

Brian Katz
VKI Studios - Google Analytics Authorized Consultants
http://www.vkistudios.com

PS. If you get errors, tell us exactly what they are.

report abuse
vote down
vote up
0
Sebastian
June 18, 2008
Votes: +0

Hello,

now it works. I track on two accounts and with a little change of the gatag.js the external data comes correct to the two accounts.

Change this line:
if (typeof(pageTracker) == "object") pageTracker._trackPageview(lnk);

too this 2 lines:
if (typeof(firstTracker) == "object") firstTracker._trackPageview(lnk);
if (typeof(secondTracker) == "object") secondTracker._trackPageview(lnk);


AND

This line:
if (typeof(pageTracker) == "object") pageTracker._trackPageview(mailto);

too this 2 lines:
if (typeof(firstTracker) == "object") firstTracker._trackPageview(mailto);
if (typeof(secondTracker) == "object") secondTracker._trackPageview(mailto);


Hope somebody can need this.
Thanks Brian.
Sebastian

report abuse
vote down
vote up
0
Brian K
June 19, 2008
Votes: +1

Sure thing Sebastian.

This brings up a point of the tools we use to help diagnose and fix errors in our analytics.

As far as the JS side is concerned I regard the following as vital - and they are all part of or add-ons to FireFox:
1) the Error Console (Tools menu)
2) WebDevelopers Tool bar extension
3) Firebug extension
4) WASP (http://wasp.immeria.net)
5) LiveHTTPheaders extension

All extensions at https://addons.mozilla.org

Brian Katz
VKI Studios - GAACs
www.vkistudios.com

report abuse
vote down
vote up
0
Andrew N
June 20, 2008
Votes: +0

Hi David,

just wanted to say thanks for a fine piece of work. Now our stats have become even more valuable.

- Andrew.

report abuse
vote down
vote up
0
Karo
June 24, 2008
Votes: +0

This is absolutely great. It's a very nice script and so easy to use. Thanks David!

report abuse
vote down
vote up
0
Tim Froling
June 27, 2008
Votes: +1

Hi David.
Trying to get client's (their staff) to add 'onclicks' to links in a CMS is near impossible. I knew there had to be a better way. Trouble is I knew what I wanted and the methodology but don't have the js skills. So off I went looking, GBG (God bless Google) I found your solution. I does exactly what I want and works a treat. Thanks!

report abuse
vote down
vote up
63
David T
June 28, 2008
Votes: +1

Andrew, Karo and Tim, I'm delighted you have found this script so useful! smilies/smiley.gif

report abuse
vote down
vote up
0
dan
July 01, 2008
Votes: +0

Hi David.
Trying to get client's (their staff) to add 'onclicks' to links in a CMS is near impossible. I knew there had to be a better way. Trouble is I knew what I wanted and the methodology but don't have the js skills. So off I went looking, GBG (God bless Google) I found your solution. I does exactly what I want and works a treat. Thanks!

report abuse
vote down
vote up
0
June
July 13, 2008
Votes: +0

I added your code to a web site this a.m. and so far, no download tracking has shown up on GA. But after reading here, it seems the download tracking doesn't show up for a few days. Why does the download tracking take longer than page tracking? When the download tracking does show up in GA, does it show up under the date the download actually occurred or does it show up on the date the tracking hits GA? If it shows up on a date different than it occurred, doesn't this affect conversion metrics?

report abuse
vote down
vote up
0
Antonio
July 13, 2008
Votes: +0

Hi all.
I've tried to use gatag.js to track some downloads but I don't get any expected report.

I work on 2 websites on which I'd like to track some links.

First http://www.finistereproduction.ch/kino.php
I have a "lightbox" effect opening a home made swf video-player. I'd like to know if people watch the videos. I have no reports about these links

On another site http://www.dawnprog.com/audio.php
I have audio players. Same problem as above. In a restricted access section of this site, I propose mp3 and ogg file downloads. I'd also like to track these downloads.

I've edited the gatag.js file to include swf and ogg files survey.

I can't make this work. I've waited 48h to have the reports but no results. Could anyone tell me if something is wrong in my code.

Thanks,
Antonio

report abuse
vote down
vote up
0
June
July 14, 2008
Votes: +0

Like Antonio, I've waited 48 hrs + ss well and tracking not working for me either. The site I'm trying to track is a oold fusion site. But GA works fine on the CF site, so assumed this js code would as well.

report abuse
vote down
vote up
63
David T
July 14, 2008
Votes: +0

Hi Dan, Antonio and June!

@Dan - glad you found the solution so helpful!

@Antonio - Here at GoodWebPractices we are using the gatag.js script and are able to track how many views we get of jpgs when using lightbox. I'm not sure if it's possible to track SWF's with Analytics - we've never needed to so far. Perhaps you could try asking ShoreTel about this at the Google Analytics forums: http://groups.google.com/group...ing/topics ShoreTel might be able to tell you if that's possible... Sorry you've had problems with that

@June - The statistics will appear as content items and should be showing now if you installed the script correctly. To see downloads in Analytics go to Content > Top Content > Search: "the file you want to see" This should work. The date shown will be the date the files were downloaded.

report abuse
vote down
vote up
117
Brian Katz
July 15, 2008
Votes: +0

Hi everyone.
The problem mentioned in the last few posts has inspired a blog post and a solution at http://blog.vkistudios.com/ind...-with-WASP

Brian Katz
VKI Studios - Google Analytics Authorized Consultants
http://www.vkistudios.com/analytics.html

report abuse
vote down
vote up
0
June
July 15, 2008
Votes: +0

David

I installed your code about 60 hours ago. Content still not showing up. I give up. Nice idea though. I will now try to decipher what google has on their site for laboriously adding code to every link. smilies/angry.gif

report abuse
vote down
vote up
0
June
July 15, 2008
Votes: +0

Brian

The problem with you "solution" is if you have more than 100 pages it requires purchasing a solution that does not integrate with GA. I can't imagine anyone with less than 100 pages tracking anything that's not in their accounting software. smilies/smiley.gif 100 pages/links seems to be the magic number for companies offering free software.

report abuse
vote down
vote up
117
Brian Katz
July 15, 2008
Votes: +0

Hi June
The greatest value of the tool is not in the scanning but in showing what data is being sent to Google.

I very rarely use WASP to scan.

In your case, you would click on a link that should be affected by gatag.js and seeing what data is being opened. For testing purposes Ctrl+click on the link so it opens in another tab so you can see what WASP says was sent to Google in the original tab. If the pageview is not being sent, don't wait for Google - it will never show up there.

Chances are there is a JavaScript error. Check that out in FireFox's Error Console.
Brian Katz
VKI Studios - Google Analytics Authorized Consultants

report abuse
vote down
vote up
0
June
July 15, 2008
Votes: +0

Brian,

Thanks, I'll try that and let you know.

BTW, I tried to post comment on your blog, but could not get past the encryption code. code just kept refreshing every time I hit post.

report abuse
vote down
vote up
0
Conner
July 15, 2008
Votes: +0

Dave,

Can the gatag.js code be implemented side-by-side with links that use the trackPageview onclick call? I have a legacy site i'm supporting which has numerous links that require the trackPageview onclick method -- but going forward I'd like to be using a pure gatag.js or similiar solution. Is this possible?

My understanding is that for the onclick code to work, the ga.js has to be initialized before any method calls. Conversely, your code needs to be run after any 'a' tags, but before the ga.js, correct?

Is there a resolution I'm not seeing?

report abuse
vote down
vote up
0
June
July 15, 2008
Votes: +0

David,

Lo and behold the tracking showed up last night, about 60+ hours after putting code on the site (I only mention how long in case other ppl get frustrated, too).

However, the content tracking did not show up on the day the downloads were made on the 12th but showed up on the 14th. Also, it not only tracked downloads, but tracked external links as well.

BTW, I appreciate ppl like you who post solutions like this. As a web designer/developer it allows me to offer more value to my clients as I build their site. It also helps you because once the client starts asking for help on GA, I'll have to send them elsewhere and I'll look first to you and Dan for that referral! Also, have made donation to you for using your code. Cheers!

report abuse
vote down
vote up
0
June
July 16, 2008
Votes: +0

Ooops, I said Dan, I mean Brian. smilies/smiley.gif

report abuse
vote down
vote up
63
David T
July 16, 2008
Votes: +0

@Brian - Nice post re: Wasp, thanks for letting us all know about that!

@June - Fantastic to learn that the tracking showed up! This script is a great tool, am glad you've found it useful. Thank you very much for the donation, it's much appreciated.

@Conner - I haven't tried using gatag.js with the trackPageview onclick. I don't see why it wouldn't work. My recommendation would be to give a try and see how you get on.

report abuse
vote down
vote up
0
Jody
July 17, 2008
Votes: +0

Hi David - can one simply add other extensions to this. We want to be able to track downloads for RSS and XML files. Can we simply add xml to the extension list?

Let me know, thanks.

Jody

report abuse
vote down
vote up
0
Kevin
July 23, 2008
Votes: +0

I'm also getting the error:
Error: uncaught exception: [Exception... "Component returned failure
code: 0x804b000a [nsIDOMNSHTMLAnchorElement.hostname]" nsresult:
"0x804b000a ()" location: "JS frame ::
http://www.goodwebpractices.com/script/gatag.js :: :: line 20" data: no]



Is there a solution to this?

report abuse
vote down
vote up
117
Brian Katz
July 23, 2008
Votes: +0

@David and Kevin
This is the error for which we provided the fix.
Its encountered when a page has a link (anchor tag tag) without an href such as one that names an anchor on a page.
David, shall I post the script on our blog and refer them to this blog?
Brian

report abuse
vote down
vote up
0
Kevin
July 25, 2008
Votes: +0

So do you mean that there is an updated version of gatag.js? If so where can I get that?

There are way too many anchor tags throughout the site for me to update them all with an href.

report abuse
vote down
vote up
0
Kevin
July 25, 2008
Votes: +0

Also one more question: this script looks like it is working great for pdf's, but the numbers are way too low for mp3's. Does this script work if someone right-clicks and saves a file?

report abuse
vote down
vote up
63
David T
July 25, 2008
Votes: +0

Hi Kevin and Brian.

Brian is right, he has found a fix for the script. I have been working on a new post, but it isn't ready yet. In the mean time I have updated the script, so if you download the script now, it will work without the error:

http://www.goodwebpractices.com/downloads/gatag.js

Thanks again and watch out for a new post coming soon.

Thanks for your patience on this Brian,

David

report abuse
vote down
vote up
0
Will
August 05, 2008
Votes: +0

Hi

Great script! But now that the downloads are been tracked how do I see them in Google Analytics? If I go to 'Content' and then search for (containing '.doc') as well as getting .doc files I am getting .pdf's in folders called 'doc'. Is there a handier way?

report abuse
vote down
vote up
117
Brian Katz
August 05, 2008
Votes: +1

Hi Will
the containing field (in-line filter) uses Regular Expressions) so the . means any character.

'Escape' the . and search for .doc and it will look for the dot literally.

Brian Katz
VKI Studios - Google Analytics Authorized Consultants
http://www.vkistudios.com/analytics.html

report abuse
vote down
vote up
0
Will
August 06, 2008
Votes: +0

Thanks for the reply.

What exactly do you mean by:
"'Escape' the . and search for .doc and it will look for the dot literally." 'Escape'?

report abuse
vote down
vote up
117
Brian Katz
August 06, 2008
Votes: +2

Sorry Will - I forgot to provide an example:

escape means preceding the character to be escaped with a

as in .doc

That means that the . will not have mean "any character" but will be regarded literally.

It will still find strings that contain ".doc" anywhere in the string - if you want to force it to find file names *ending* in ".doc" use
.doc$, where $ means the end of the string.

If you want to find all documents in the doc folder search for /doc/

Brian
Brian

report abuse
vote down
vote up
0
Will
August 08, 2008
Votes: +0

Thanks a million Brian! I will try that tomorrow morning.

report abuse
vote down
vote up
0
Arthur
August 14, 2008
Votes: +0

I might be missing something easy, here; this is my first time venturing into my site. I tried to navigate to the http://www.mysite.com/scripts/ but it says the requested URL/scripts is not found on the server. Is there something I am doing wrong? Or is there another place I can upload that code?

report abuse
vote down
vote up
129
Paul
August 20, 2008
Votes: +1

Great script, use it a lot.

How about identifying documents in the virtual page view, just like external links are?

I changed this line:
if (e.hostname != location.host) lnk = "/external/" + e.hostname + lnk;

For this:
lnk = (e.hostname != location.host) ? "/external/" + e.hostname + lnk : "/document" + lnk;

It gets the job done.

Paul

report abuse
vote down
vote up
0
Win
September 05, 2008
Votes: +0

what a great script!

It saves me lots of time. However, I got some problems with that. I did install tracking scripts as per instructions, but in Google Analytics, I found the following entries in the Top Content.

/outgoing//
/outgoing/void(0)/

so anyone has any idea why that's happened.

It will be really appreciated if someone gives me a hand.

report abuse
vote down
vote up
0
Paul
September 10, 2008
Votes: +0

Hi Win,



From my experience, this happens when you are using a JS function in the href tag.

Are you using something like this? :

< a rel="nofollow" href="/void(0)" onclick="someFunction()" >My link< /a >

Is you are, the "void(0)" is identified as an outgoing link. You could consider the following instead:

< a rel="nofollow" href="/ # " onclick="someFunction();return false;" >My link< /a >

[Remove the spaces in the code]

Cheers

report abuse
vote down
vote up
141
Jeff Krukin
September 13, 2008
Votes: +0

This is just what I need, but I'm new to Joomla and GA and have two basic questions:

1)If I want to add the GA script that is added to the link, where does it go exactly? For example, a PDF's link is "http://www.jeffkrukin.com/Human Space Connection.pdf" and I'm wondering if I would just put a blank space after the "f" and the the GA script.

2)If I want to use your tracking script, you say to install it to the scripts subdir (in my case that's /templates/ja_antares/scripts). In which file? I don't know which file contains the GA tracking code (the person who installed it is traveling right now), or how to identify that code within the file.

Thank you.

report abuse
vote down
vote up
117
Brian Katz
September 13, 2008
Votes: +0

Hi Jeff
1) Links can be manually tagged as follows - this is the one from your website:
< a rel="nofollow" href= " Human Space Connection.pdf" ; target= "_blank" ; onclick= " pageTracker._trackPageview('Human Space Connection.pdf') " >< strong > Read it < /strong >< /a >
I see that your GA script blocks are near the bottom of the page, which is the recommended spot.
pageTracker is created on line 525 of your page: var pageTracker = _gat._getTracker ( " UA-3..."
That should be ok most of the time but if a frequent visitor clicks on the link (which is near the top of the page) before the whole page has loaded and ga.js is received from google-analytics.com, an error will be generated.

As you can see, its not rocket science smilies/grin.gif

2) To use the script and invoke it on a page:
Copy the auto tagging script gatag.js into your scripts folder and then add the following line before the end < /body > tag:
< script type= " text/javascript " src= " /templates/ja_antares/scripts/gatag.js < /script >
It should go at the bottom of the page because it will not apply to links that appear after the call to gatag.js.
As in 1), it does not matter if pageTracker has been created at the time the script is called, because the script only needs pageTracker when the user clicks on the link.

Hope that helps

Brian Katz
VKI Studios - Google Analytics Authorized Consultants
http://www.vkistudios.com/analytics.html

report abuse
vote down
vote up
141
Jeff Krukin
September 13, 2008
Votes: +0

Brian, thank you very much for the quick response. As I'm not a rocket scientist, please let me know which file in the scripts folder contains the GA script so I know where to place the auto tagging script gatag.js. You say copy it to my scripts folder, but doesn't it need to go in a file in that folder?

It has occurred to me that another reason to use this approach rather than appending tracking code after the PDF is that people may choose not to download the file if they notice the tracking code in the URL.

Thank you.

report abuse
vote down
vote up
0
Jack Bremer
September 16, 2008
Votes: +0

@ Brian Katz
"it does not matter if pageTracker has been created at the time the script is called, because the script only needs pageTracker when the user clicks on the link."
I think I have figured it out now - it doesn't actually change the link codes, it rewrites something invisible so that when clicked it calls in GA?
I have been scouring the source of the page for an hour or so, looking for automatically inserted onclicks but now I think I've got it sussed...
Will check stats in a day or so - if this works, we're onto a winner! smilies/cool.gif

report abuse
vote down
vote up
0
eml tin
September 19, 2008
Votes: +0

hi there, thanks for this script. i've seen a few other variations, but this seems to work.

however, if someone right-clicks (control-click on Mac) and saves the file to disc, it's not counted, because on javascript onClick is never called.

anyone have a solution for that?

report abuse
vote down
vote up
142
Brian Katz
September 20, 2008
Votes: +0

Hi Eml
Our JavaScript and Greasemonkey guru suggests using the onmouseup event.

While it may be as likely that the user actually downloads the document because they can dismiss the context menu, it isn't very different.

Brian

report abuse
vote down
vote up
0
Eric
September 26, 2008
Votes: +0

I'm seeing the same issues with "right-clicksave" as not being tracked. Any solutions yet? Does onmouseup work?

report abuse
vote down
vote up
141
Jeff Krukin
September 27, 2008
Votes: +0

Per my question above on Sept. 12 and Brian's response, I would appreciate clarification of his recommendation that I "Copy the auto tagging script gatag.js into your scripts folder." Don't I need to copy text to a specific file within this folder? In this folder I have two files; index.html and ja.script.js, and neither contains an end < /body > tag as indicated by Brian.

Thank you.

report abuse
vote down
vote up
0
lee
September 29, 2008
Votes: +0

hi i really like the idea for this but i cant seem to get it to work. ive put your code in the footer above teh google tracking code and ive made sure it is the new google tracking code. am i doing anything wrong? how long does it take for it to appear in analytics? it has been days so far.

report abuse
vote down
vote up
142
Brian Katz
September 30, 2008
Votes: +1

@Jeff
I'm not sure how the confusion was created but apologize for any part I played in it.

You have a scripts folder and these notes assume that anyone using gatag.js will have one too.
If you are simply keeping all your scripts in the root or some other folder - that folder is what I refer to as your "scripts folder".

One needs to have the gatag.js file in your scripts folder along with your other .js files.

Right-click the link to the gatag.js file at the top of this page, and save it as gatag.js on your computer.

If one simply clicks (left click) the link to the gatag.js file at the top of the page, it will open the file in your browser. Copy and paste all the text into an empty file and save it as gatag.js on your computer.

In either case copy that gatag.js file to the scripts folder on your web server

Add a script tag with a src= reference to the gatag.js file to load gatag.js as has been done with other scripts in the same folder.

Test: To test quickly if its really working, insert the line:
alert("Loading gatag.js");
at the top of the gatag.js file and reload the web page referencing gatag.js. - It should immediately pop up a dialog box with the above message.
Immediately remove that line and resave the file - your visitors don't want to see your laundry smilies/smiley.gif

Another way to test this and all other code is WASP (actually W.A.S.P.)
- see http://blog.vkistudios.com/ind...-with-WASP

The script tag referencing gatag.js is required on every page that has links you need tagged (download, email and external).

Brian Katz
VKI Studios - Google Analytics Authorized Consultants
http://www.vkistudios.com/analytics.html



report abuse
vote down
vote up
142
Brian Katz
September 30, 2008
Votes: +0

@Eric
I've not tested the onmouseup event code, but don't see why it should not work.

@Lee
If you post a link to your page, we can see your code and help you. GA data is showing up within an hour or two but does not "settle down" until the following day once all processing is completed.

Brian Katz - Web Analyst - VKI

report abuse
vote down
vote up
141
Jeff Krukin
September 30, 2008
Votes: +0

Thank you, Brian. I don't know how I didn't understand what in hindsight was your very clear direction to copy the gatag.js file to the scripts folder, rather than copy the text of the gatag.js file into another existing file.

report abuse
vote down
vote up
0
lee
September 30, 2008
Votes: +0

@Brian
i was being stupid i had set up the site so it didnt track my visits! it is working fine smilies/smiley.gif

report abuse
vote down
vote up
0
Annie
October 20, 2008
Votes: -1

It seems I'm now able to send posts : did you get my email ?

report abuse
vote down
vote up
0
NWO
October 29, 2008
Votes: +0

So.. this looks like a well written and useful script, but I still can't get any of the outbound link tracking to show up. The script is being called and downloaded properly in the page (verified using firebug) but it's been a week and still nothing for "/external/" is showing in GA. Reverting back to direct onclick calls for the outbounds still shows plenty of traffic, but nothing shows just using this script.

report abuse
vote down
vote up
0
NWO
November 06, 2008
Votes: +0

Nevermind.. figured it out. The gatag script must be placed near the end of the body of your pages. If you still want to be able to use individual onclick events with GA then the GA script must still be at the top. Seems to be working fine so far with this setup.

report abuse
vote down
vote up
0
Josh
November 22, 2008
Votes: +1

Hello,

I added the code about a week ago, but there seemed to be issues with GA. I then moved GA to the head of my page, and kept your script near the bottom. I only seemed to be getting results for outbounds to .htm links. The many Mp3s I have don't seem to be showing up. Tonight I moved your script up to just before GA at the top of the page, and I guess tomorrow I'll see if it changes anything.
How important is it where the script is? I'm using an older WYSIWYG program to create my site. I couldn't find www.joshholliday.com/scripts, so I created a folder on the site called Scripts, and uploaded it there. Thanks for the help!!!

report abuse
vote down
vote up
0
RajuPP
November 22, 2008
Votes: +0

Hi,
i have placed the js before the GA code in my header file. But I have a very basic question as to how I will be able to track the clicks, especially the outbound clicks? Through Google Analytics only? if so, how exactly? Sorry for the noobish question

report abuse
vote down
vote up
0
Josh
November 23, 2008
Votes: +0

...quick update. The reason it's just showing the .htm links is that I put the GA code on those pages. So for some reason, this one isn't working at all.

report abuse
vote down
vote up
0
Kevin
November 27, 2008
Votes: +0

I have had the script installed on a site for a while now. However, I am confused about how to understand the stats for external links.

If I goto top content in analytics and then "Find page containing" external I get a list of external links, which is fine.

However where I am confused is in the last week the stats state "29 pages containing "external" were viewed a total of 1,750 times"

where

/external// accounts for 1236
/external/ accounts for 284

I also get

/external//history.go(-1) and
/external/history.go(-1)/
(not sure why I get the trailling / )

then the other 25 entries are real links.

Can anone explain what /external// and /external/ are, and why they are proportionally high.

report abuse
vote down
vote up
0
Brian
December 13, 2008
Votes: +0

Ive done as instructed on this page. Ive had it up and going for 3 days. Had multiple contacts download PDF and DOC file. I cannot find them anywhere in GA.

Help?
www.theburmeisters.com/resume

report abuse
vote down
vote up
0
David
December 14, 2008
Votes: +0

Hi David,

I've been stumbling around for a week looking for something like this - gatag.js - fantastic - so time saving - well done for making it available.

Just wondering if there's been any resolution to Danny's question of March the 19th 08

"Danny, if the downloads are loaded via a javascript window, I'm afraid that this javascript won't be able to track the downloads. You could ask ShoreTel about how to do this on the Google Analytics forums."

my site http://www.davidburr.com.au I believe comes under this category although I'm new to this and may be wrong - I hope so.

I'd like to be able to implement the gatag.js script on each of my pages that have links to movies which open in new windows but am a little unsure as to whether these windows fall into the same category as Danny above.

Regards - David B

report abuse
vote down
vote up
0
Pete F
December 22, 2008
Votes: +0

Will this work in a fully Flash site? I think I have the code added correctly but I am not receiving data in GA. Any ideas?

http://spikeadvertising.com/

report abuse
vote down
vote up
0
Isha
December 31, 2008
Votes: +0

I need to track pdfs that are dynamically generated using ASP.net page. Please advice! My .net page generates pdfs using the following code based on the element id. I am assuming registering the script using Page.ClientScript.RegisterClientScriptInclude(Me.GetType(), sFileName.ToString(), "/js/gatag.js")
would do the job but please advice if this would track the documents correctly.


If Not element.IsText Then
'Write input bytes into MemoryStream if not text

'Re-build file from bytes in memory
Dim msPDF As New MemoryStream
msPDF.Write(element.ContentBytes, 0, element.ContentBytes.Length)
msPDF.Seek(0, SeekOrigin.Begin)

'Write memory to response
With Response
.ClearContent()
.ClearHeaders()
.ContentType = element.ContentType
.AppendHeader("Content-Disposition", "attachment; filename=" & sFileName)
.BinaryWrite(msPDF.ToArray())
End With

'Close the stream - Release memory for cleanup
msPDF.Flush()
msPDF.Close()
msPDF = Nothing
Else
'Text - Just write to browser
With Response
.ClearContent()
.ClearHeaders()
.ContentType = element.ContentType
.AppendHeader("Content-Disposition", "attachment; filename=" & sFileName)
for (var l = 0; l < hrefs.length; l++) {
// try {} catch{} block added by erikvold VKI
try{
//protocol, host, hostname, port, pathname, search, hash
if (hrefs[l].protocol == "mailto:") {
startListening(hrefs[l],"click",trackMailto);
} else if (hrefs[l].hostname == location.host) {
var path = hrefs[l].pathname + hrefs[l].search;
var isDoc = path.match(/.(?:pdf)($|&|?)/);
if (isDoc) {
startListening(hrefs[l],"click",trackExternalLinks);
}
} else {
startListening(hrefs[l],"click",trackExternalLinks);
}
}
catch(e){
continue;
}
}
}

function startListening (obj,evnt,func) {
if (obj.addEventListener) {
obj.addEventListener(evnt,func,false);
} else if (obj.attachEvent) {
obj.attachEvent("on" + evnt,func);
}
}

function trackMailto (evnt) {
var href = (evnt.srcElement) ? evnt.srcElement.href : this.href;
var mailto = "/mailto/" + href.substring(7);
if (typeof(pageTracker) == "object") pageTracker._trackPageview(mailto);
}

function trackExternalLinks (evnt) {
var e = (evnt.srcElement) ? evnt.srcElement : this;
while (e.tagName != "A") {
e = e[removed];
}
var lnk = (e.pathname.charAt(0) == "/") ? e.pathname : "/" + e.pathname;
if (e.search && e.pathname.indexOf(e.search) == -1) lnk += e.search;
if (e.hostname != location.host) lnk = "/external/" + e.hostname + lnk;
if (typeof(pageTracker) == "object") pageTracker._trackPageview(lnk);
}

report abuse
vote down
vote up
0
Dena
January 15, 2009
Votes: +0

Thanks for this! I wasn't looking forward to placing the tracking code on each item. This is outstanding.

Installed it on a test page yesterday and have stats today.

Now to install it site-wide.

report abuse
vote down
vote up
0
MarketingGuy
February 03, 2009
Votes: +0

I installed GA via your helpful info. Thanks very much for that.

Am new to Joomla and mixed up on finding folders; i.e. when to use cpanel vs admin, etc.

Site working well so far; http://rtcemarketing.com, but unsure where to go for the simple path to find and add to scripts folder. Please clue me in.

Also, I'm with SiteGround and they have awstats on the site. What is the difference, as it's not easy like here to find support from them. Should I use what your script enables, use awstats, or GA?

Thanks very much
MarketingGuy

report abuse
vote down
vote up
0
wildwabbit
February 09, 2009
Votes: +0

Quote=

So the statistics for the downloads and external links will appear as content items. E.g. Within Google Analytics navigate to the "Content" section then select "Top content". The PDF's will be listed in here along with your websites pages. If you can't see the PDF files use the "Find URL" box and enter pdf then press "Go". This will bring up all the stats for your PDF downloads!

---------------

Is "Find URL" box = "Find Page" box ?

report abuse
vote down
vote up
0
Dave
March 09, 2009
Votes: +0

Great article.

Would that work if I wanted to track clicks on a JavaScript pop-up?

Per example, if I had a form within a JavaScript popup, and I wanted to know how many people reached the form.

Thanks!

report abuse
vote down
vote up
0
Rob
March 12, 2009
Votes: +0

Thanks for this easy script!

We're implementing this but only want to have EXE downloads filter down through to the reporting end.

What is the best way to modify the JS to do this cleanly?

....

var isDoc = path.match(/(? :exe)($|&)/); ??

Many thx
R.

report abuse
vote down
vote up
0
Paul
March 16, 2009
Votes: +0

Hi,

We have implemented the code for automatic tracking on www.ordina.nl.

Does anyone know whether it should work to track downloads on pages like:
http://www.ordina.nl/Downloadcentrum/~/media/Files/Kennis/Whitepapers/folder siebel.ashx?forcedownload=1

Thanks!
Paul

report abuse
vote down
vote up
210
Sumit Mahajan
March 17, 2009
Votes: +1

The script is wonderful.Hats off to all who has contributed to this script.

Only wanted to mention one thing about the implementation which seems to be little confusing.I am really sorry if i have offended someone.

I have just called this script thru include file which is already calling GA code.called this script above the GA code call.It worked.

Question: I hope siteoverlay will also work for external links.

Once again want to thanks all.

report abuse
vote down
vote up
0
GaryMac
March 20, 2009
Votes: +1

Fantastic. Really amazed at this. I have over 2000 PDF's on my site. Now they are tracked.

Big thanks and best wishes from Sweden!

report abuse
vote down
vote up
0
Alan S. Flint
April 16, 2009
Votes: +0

Hi,

I was delighted to find your suggestion regarding tracking downloads (in my case .mp3 & .rm audio files), and have started to implement your script across my site. So that we do not end up with confusion, where I had already done it, I am gradually going though the site and removing the on-click Google code. I had not tagged every file, and when I found your suggestion I rejoiced, shouted "thank goodness" I don't have to continue tagging every file link."

However, I have now realised that I may still have an issue. What do I do about the 'streaming' links, mainly with an .m3u extension, pointing of course to the actual .mp3 file? Your script does not register calls upon .m3u files, so what should I do?

Do I have to go back and re-tag the .m3u files with an on-clik tag, or an event tag, or something similar?

Any suggestions? Your help would be very much appreciated.

report abuse
vote down
vote up
0
Peter
April 17, 2009
Votes: +0

This sounds great but I cannot get it to work... I would realy appreciate if you could take a brief look at this page
http://www.rockwool.dk/råd+og.../download

and let me know why the exe file or other pdf' on the site are not tracked...

Thanks in advance

Peter

report abuse
vote down
vote up
0
Paul1
April 23, 2009
Votes: +0

Yesterday, I installed the script and added some extensions not in the original stack -- docx and xlsx, for example. I then ran a test on 5 separate downloads -- .doc, .docx, .xls, .xlsx, and .pdf

Today, I looked at my G.A reports and only 2 of the download types show up -- .doc and .xls. The .docx and .xlsx did not appear on the Content report. Nor did the .pdf.

So I was wondering. Since all of the hits that G.A. normally records are page views anyway -- that is, .htm, .html, .aspx, .php etc. -- why not code your script to do the reverse -- track everything but the file types that G.A. tracks. In other words, make the regex stack an exception list as opposed to an inclusion list. This way we would not have to constantly update the script as new file types evolve.

report abuse
vote down
vote up
0
Dukes Online
April 23, 2009
Votes: +0

Great article! Thanks for the info it was very helpful.

report abuse
vote down
vote up
0
Paul1
April 24, 2009
Votes: +0

Just checked again on the status of .doc, .docx, .xls, .xlsx, and .pdf.

The .doc, .xls, and .pdf downloads show-up. But the .docx and .xlsx do not.

It makes me suspicious of the accuracy and effectiveness of the script.

(FYI, this form gets chopped off in IE7 such that the "Add Comment" button did not appear in my browser.)

report abuse
vote down
vote up
0
chris
May 05, 2009
Votes: +0

Using this code, i'm looking at content statistics for an external page, and the time on page is
00:05:56 , bounce rate is 62.33% and exit rate is 54%.

I thought by definition a link to an external site should have an exit rate of 100%. And how is it measuring the time on page, if it's an external link?

cheers

report abuse
vote down
vote up
0
AliW
May 12, 2009
Votes: +0

Hi David,
thanks for this excellent script!

Is there anyway that it could track links that use the following:
'http://www.somewebsite.com/loader.cfm?csModule=security/getfile&pageid=46700'
where the pageid is unique to each document.

Thanks

report abuse
vote down
vote up
0
karel zeman
June 11, 2009
Votes: +0

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.

report abuse
vote down
vote up
0
Audiate
June 11, 2009
Votes: +0

>>If you can't see the PDF files use the "Find URL" box and enter pdf then press "Go".

I can't see a 'Find URL' box anywhere... where on the page is it?
thanks,

report abuse
vote down
vote up
0
Rob Gaedtke
June 12, 2009
Votes: +0

This is a great script. A programmer, Ryan Dyess over at Twelve Horses made some modifications making the tracking in google analytics a bit easier to manage. I will be posting the updated version in the next couple of days but wanted to drop a line and say thanks!

Rob Gaedtke

report abuse
vote down
vote up
0
STC Webmaster
June 15, 2009
Votes: +0

Once the code has been implemented. How can I check if it was installed correctly? The only change I made for testing is the path name of the folder from /scripts/ to /js/. I have referenced the src= accordingly.

report abuse
vote down
vote up
0
Anze
June 18, 2009
Votes: +0

Hey!

I have "a problem" tracking clicks on my images (lightbox; photo gallery). It's like that:

1) Have a page with photos on it.
2) On it are just thumbnails.
3) I'm using lightbox photo gallery, so that when someone clicks on a thumbnail, he/she can see the full-size photo.
4) I would like to track those clicks (checked several pages in the past days, tried writing different codes into HTML, but nothing seems to work).

Code (with thumbnail + full size photo) looks like that:





What & where do I need to write tracking code, so that Google Analytics will show me the number of clicks on my photos?

Thank you in advance for your help!

report abuse
vote down
vote up
0
Nick
June 24, 2009
Votes: +0

Hi All,

Thanks to all who contributed to this article and comments. I thought you might be able to help me.

I've been hunting around for a script whereby I could initiate a Google Analytics Track Event, irrespective of if a browser is used to download a podcast mp3 file. So non browser devices will be tracked

I currently can use GA to track browser click throughs, feedburner to track rss subscriptions, but I want to track the downloads themselves. I don't have access to the log files on my media host (free bandwidth), but can run scripts on my website host.

What I would like to do is have something like the following happen.

1. request comes for www.mysite.com/media/load.php?f=example.mp3
2. this raises php trackevent to GA for 'example.mp3' and redirects to
http://media.mysite.com/example.mp3 the file for download

My current load.php script looks like the following.



Currently at the INSERT POINT i can do something like the following

$f = fopen('log.txt','w+');
fwrite($f,'$Destination_URL');
fclose($f);

But I would prefer to have a GA trackevent to allow me to us the GA interface rather than a scappy log file to monitor downloads.

Anyone got any ideas how to do this, or can you direct me to another example.

Thanks
Nick



report abuse
vote down
vote up
276
Audiate
June 30, 2009
Votes: +0

Just wanted to bump my question...
"navigate to the "Content" section then select "Top content". The PDF's will be listed in here along with your websites pages. If you can't see the PDF files use the "Find URL" box and enter pdf then press "Go". This will bring up all the stats for your PDF downloads!"
...I can't find a 'Find URL' box anywhere on my Google Analytics page. Can anyone else out there help? thanks,

report abuse
vote down
vote up

Write comment
 
  smaller | bigger
 

busy
 
Created by David Towers of Beetham Tower Manchester