Problems with Google Analytics Code for Tracking PDFs
After struggling for nearly a week to install the asynchronous code for Google Analytics, I thought it would be good to share what I've learned. Hopefully this will save you a few sleepless nights. When I switched to the asynchronous tracking code, everything appeared to be working correctly. But for some reason PDF downloads and visits to external websites weren't showing up in the analytics.
According to the Google help documentation (How do I track files (such as PDF, AVI, or WMV) that are downloaded from my site?), an "onclick" event like the following needs to be added to the downloadable file / external website link:
<a href="/newsletter/2010spr.pdf" onclick="javascript:pageTracker._trackPageview('/newsletter/2010spr.pdf');">
While searching for a solution, I stumbled across a Google Chrome plug-in (Google Analytics Tracking Code Debugger) used to validate your tracking code. Using the plug-in, I discovered that the Google help documentation failed to mention one crucial piece of information; you need to define "pageTracker". After a little searching I found another page (Google Analytics Installation Guide) that talks about defining "pageTracker".
With "pageTracker" now defined, the Google Chrome plug-in said that everything was working. But for some reason the code still wasn't working. I used several computers to open PDFs and visit external links. Then I checked Google Analytics an hour or so later to see if they show up. For some reason one of the clicks went through, but that was it. After a few more days of failures and posting on the Google Analytics discussion board I finally realized that the tracking code provided by Google doesn't work.
Instead you want to call the tracking code directly:
<a href="/newsletter/2010spr.pdf" onclick="javascript:_gaq.push(['_trackPageview', '/newsletter/2010spr.pdf']);">
I have no idea why the Google Chrome plug-in said everything was fine, maybe there is a bug on Google's side that prevents the analytics service from accepting results.
0 Comments
There are currently no comments.
Leave a Comment