Tracking clicks to pdf files requires custom code. Without the code, you should not see any views to pdf files in web analytics reports, but this is not always the case. One additional simple code customization explains the mystery.
<a onclick="_gaq.push(['_trackEvent', 'Document', 'PDF',
Click here to view PDF</a>
For sites with a large number of pdf files, it’s worth the investment to set up custom code in a jquery file to automatically track all clicks to pdf’s (as well as other documents, as specified). Many varieties of the code exist – such as this solution provided by Adam Buchanon.
While walking one client through the various requirements and options for setting up tracking, and in an attempt to demonstrate the lack of any pdf tracking at all on their site, I performed a filter on ‘pdf’ in the standard content reports. The results returned – much to my surprise -- a long list of pdf documents. I went to the site to view a random selection of pdf documents. I could see that there were no tags firing to track the click to the pdf. How was it possible to see page views in the reports to pdf’s without any code on the site, and without data passing to Google Analytics?
Finally, after some brainstorming with a very talented colleague, we noticed that all of the visits to the pdf documents were from search and referrals (suspicious). We finally decided to go to the site to view the specific pdf files listed in the content report. We discovered that all of the pdf addresses listed produced 404 errors. Without code adjustments to the 404 error template, web analytics reports record pageviews to the URL requested, instead of tracking the 404 error. Sometimes the error status may show up in the page title, but sometimes it does not (the page title may be blank).
For Google Analytics, modify the trackPageview line of code to record the 404 error along with the page requested:
Therefore, the Google Analytics Tracking code on a 404 error page should be:
var _gaq = _gaq || ;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script'); s.parentNode.insertBefore(ga, s);
In addition to explaining ‘mystery’ pdf tracking, error template customization produces extremely actionable reports for managing broken links, revealing where 301 redirects need to be set up, and improving customer experience.