11 Feb 2008 |
|
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 automaticallyThe 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:
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. Comments (281)
![]()
...
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?
...
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.
...
Seems a simple and great solution to tracking downloads. I have added the code and am just waiting for Analytics to process.
...
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.
...
hi david
...
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.
...
Hi,
...
Hi David T and Don
...
Thanks David.
...
Hi super015 and Danny
...
I added the code, but I am getting an error:
...
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?
...
super015 & Mark,
...
Hi David T and Mark
...
Hi David T and Mark
...
Last post should read "hrefs[ l ] has an href attribute". Brian http://www.vkistudios.com
...
Why do you make the following suggestion:
...
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
...
sorry that should be www.uconnucedd.org
...
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?
...
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.
...
David, the PDF and external tracker worked for a day and now it has stopped working.
...
Thank you very much David, it works perfect for us!
...
Yes, GA Reports do not appear to help much here but ...
...
Hello,
...
Hi Sebastian
...
Hello,
...
Hi Sebastian
...
Hello,
...
Sure thing Sebastian.
...
Hi David.
...
Hi David.
...
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?
...
Hi all.
...
Hi everyone.
...
Brian
...
Hi June
...
Dave,
...
David,
...
I'm also getting the error:
...
@David and Kevin
...
Hi
...
Hi Will
...
Sorry Will - I forgot to provide an example:
...
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?
...
Great script, use it a lot.
...
what a great script!
...
Hi Win,
...
This is just what I need, but I'm new to Joomla and GA and have two basic questions:
...
Hi Jeff
...
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?
...
@ Brian Katz
...
hi there, thanks for this script. i've seen a few other variations, but this seems to work.
...
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.
...
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.
...
@Jeff
...
@Eric
...
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.
...
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.
...
Hello,
...
Hi,
...
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.
...
Hi David,
...
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")
...
I installed GA via your helpful info. Thanks very much for that.
...
Quote=
...
Hi,
...
The script is wonderful.Hats off to all who has contributed to this script.
...
Hi,
...
This sounds great but I cannot get it to work... I would realy appreciate if you could take a brief look at this page
...
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
...
Just checked again on the status of .doc, .docx, .xls, .xlsx, and .pdf.
...
Using this code, i'm looking at content statistics for an external page, and the time on page is
...
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.
...
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!
...
Hey!
...
Hi All,
...
Just wanted to bump my question...
...
Thank you very much! I tried many different ways to solve this and it works great. Only drawback is tracking of PDFs and the like from sources outside the website (i.e., e-mail links and links on other sites). Still need the log files for that.
...
Hi There,
...
Hi, I'm not a JS expert, so please bear what may seem like some dumb questions, but :
...
Hi. I wish I could get your code to work on our pages. I have been messing with this for over a month now. I've been unable to get Google's page tracking code to track our pdfs and I can't get this code to work either. I've waited days (weeks) and searched top content for the pdfs. We have about 3,500 exits on the pages that load only pdfs so I know they're being viewed, but we're still not getting a count. I'm unfamiliar with scripting so it's probably something I did, but could it have anything to do with the fact that our home page is an aspx and we use includes (the code is in the header include). Our URL is http://trs.illinois.gov. Thank you for your help.
...
Thanks so much!
...
One of my clients had this built into their original site and it works great. I am now trying to modify their GA installation to track pageviews across two domains per the instructions here: http://www.google.com/support/...swer=55503
...
I have added the code accprding to the instructions but its been more than 48 hours nothing has been indexed. can any one tell what could be the reason
...
I have added the code in my home page http://dj-jitesh.com/ but i am not able to get the records of download in GA. It might be possible that i am missing something, kindly help me if you can to let me know where i am wrong.
...
I have a .pdf portfolio at http://www.designplus.ro/3D/DesignPlus_3D.pdf and a single page site http://www.designplus.ro
...
We have a link to a PDF that we would like to track. Is it possible to track the downloads without having to make changes to the code, by simply tracking the PDF as a goal? E.g. using a regular expression on .pdf? I have been doing so on another webpage, but can't seem to make it work on this site...
...
I have a problem with this script. I host work-in-progress pages on my website (domain 1) and upload 'live' pages to the client's site (domain 2) when approved. Google analytics has been set up to montitor domain 2, but the ("UA-xxxxxxx-x") obviously exsists on mirror pages on both sites. When I check the report of downloads, filename.xls downloads are reported that have never been uploaded to the client's site. Is there any way to isolate the development site domain/url from the reports?
...
We've just added it to our website www.ContestListing.com and we are curious about results.
...
Thanks! I'm the Web Analyst for my Company. I also use Site Catalyst which tracks the same downloads out the box, and multiple other analytic applications.
...
Hello,
...
http://www.prekybostinklas.lt/...-BUSHMENAS
...
Great article and script. I have ported it to jQuery for those already using jQuery on their site. Exercise caution as this code has not been widely tested yet. This code has a footprint of less than 50% of original code:
...
I have a web page which consists mainly of thumbnail images which are linked to a .html file which opens in a new but resized window using the javascript "onClick" command.
...
I'm wondering if this script will work for advertising purposes.
...
We host all our download files on a different server and subdomain. What would be the best way to modify this script to see the subdomain as a part of our parent domain. So that it tracks the downloads and external links correctly. Analytics has been setup to see the two domains as the same thing.
...
Any experience installing for Drupal?
...
Hi
...
Hi,
...
Hi David,
...
Hi David,
...
Hi
...
Hi
...
Four instructions below on how to track downloads:
...
In a previous e-mail I gave four different URL helpful in setting up tracking, including how to track downloads, and this company seems to be checking it out before posting it.
...
Hi- I installed your auto tracking code just before the ga.js. I just want to make sure that it's OK to use your tracking code with the new "asynchronous" Google code that is inserted just before , not . The older code (before Dec 2009, which they still use on initial setup) is inserted at the bottom of the head.
...
Sorry- your message box didn't accept script characters. Lets try again:
...
This approach does not work in iWeb since when using an HTML snippet, iWeb creates a separate .html page that gets called in to the parent html page. So essentially gatag.js is tracking an empty page!
...
With the google analytics changes on May 19, which make async coding the default, I guess gatag.js no longer works?
...
Will this work with Joomla Sites? I just added your code to MedicareSherpa.com. I am actually going to add this code to my day job at TuftsMedicarePreferred.org. I found your code analyzing Medicare.gov. Honestly, this is a huge help and I can't wait to start tracking results, i thought i was going to have to this for every page and pdf. What a time saver. I am definitely a new fan.
...
David
...
Hi, THANK YOU!!!
...
hi
...
One query David T,
...
Good Day,
...
I fould this link regarding the Google Analytics async update. Would anyone be able to suggest how to update the scripts mentioned on this page to work with the new async format?
...
I believe I've updated the script to work for the Google analytics async tracking. I also tried to add a section for "tel:" links. I don't think the mailto or tel links are working, but I believe document links (pdf, etc) are. I haven't waited to see yet what shows up in Google analytics, but I'm receiving the _utm.gif file for the tracking of the pdfs, according to Chrome debugging. When I click the mailto or tel links, it gives an error in chrome debugging "Failed to load resource". I'll see tomorrow what, if anything, shows up in Google analytics. FYI, my website is all4dancestudio.com and I'm currently using this script specifically because the interface of my host officelive.com, doesn't allow me to edit the html of the onclick's directly. Hope this helps someone...
...
links from mail, tel, and documents wokring with new async tracking:
...
Hi there. I am having what seems to be a common problem with installing the gatag.js correctly. I have placed it directly above the Google Analytics code as instructed, but it isn't yielding any results (pdf downloads primarily) in the GA dashboard.
...
Hi everyone, I just wanted to ask Im not a web developer but I maintain the website of the company where I work. I want to track the downloads made by visitors of our public documents. I read your solution but i don quite understand how to paste this code. The website work in (CMS) There is one box that ask me straight for the google analytics code. Is in this box where I have to put the long text you recommend? plus the code that start with UA-? also in the code you paste there is one link www.yoursite.com do I have to change it for the URL of the site of the company?
...
Hi David,
...
Has anyone been able to modify this script to work with the new Asynchronous tracking code? It uses _gaq.push(['_trackPageview', 'yourfile.pdf']); rather than pageTracker._trackPageview('yourfile.pdf'). My JS skills just aren't cutting it to make the modifications needed.
...
Hi. Thank you so much for providing this!
...
Hi..This is great! A very useful tool to keep track of our website usage..
...
PEOPLE!!! No one supports this script anymore, NOR will it work w/the now default, GA asynchronous code !!!
...
This is very helpful to understand how this works. However, I wonder if you have considered how to handle "direct downloads"--i.e. situations where a document is directly linked from another website or shared through an email. In that case, the user will never be on a web page where the javascript can execute. Web log file analysis tools like analog, webtrends, etc. will show that GA underreports file downloads if you have a lot of this kind of thing going on.
...
Anthony,
...
In regard to step one of installing the code segment in the "script" folder. I'm assuming the code needs to be pasted into a .txt or possibly .js document that will be uploaded to the "script" folder.
...
Hi,
...
hello
...
Hi there,
...
We're going to be adding some tracked downloads on our site at http://www.e-mphasis.com/, we'd appreciate a few clicks at some point to test it. Thanks
...
Sorry that link came out wrong, try http://www.e-mphasis.com
...
Inserted your code and js file to pick up download events on our website when using Google analytics. However, we discovered on a given day Urchin is picking up 13,000 download events and your code is only referencing 21 when viewed via Google Analytics. Can you help us determine why your code is not picking up all download events?
...
This solution tracks "clicks to PDF downloads" but does anyone know of a solution which will track PDF downloads?
...
Just wanted to say thanks so much for the script, the tutorial, and the ongoing troubleshooting in these comments. I just came across this and installed it no problem. I was able to go into GA and find the information I want because of the comments here.
...
Have a question. I am new at this stuff and from what i have heard so far is that with this code you could track downloads on your site. My question is that if you have a download page on your site and you want to keep track of all the files that are being downloaded on that page of your site only, is it necessary to add the code in all pages of your site?
...
Thank you very much. This script has been extremely useful.
...
I'm quite sure this does not work
...
Thank you very much. This script has been extremely useful.
...
There is a new Asynchronous Google Analytics tracker and tracking file downloads is slightly different.
...
I am using on my site http://www.asianventure.com
...
Hi,
...
Hi, |






Wow! Awesome, exactly what I was looking for! Thanks!
so not sure what to do. Hope you can help. 