Home / analytics / Tracking Web hits to PDFs with Google Analytics

Tracking Web hits to PDFs with Google Analytics

Many business owners get lost in the heavy data of Google Analytics, and often are less interested in bounce rates and browser statistics than they are with particular content they surface. That works great as long as you only care about page hits, but what about documents, newsletters, PDF whitepapers, etc.? An easy hack is to create a page for each document, but you’re not here because you like easy hacks (are you?). Welcome to the world of taking control of your Google Analytics, my friends…

Here’s some sample code on tracking PDFs, video, image files (anything other than HTML or server-processed pages). This a simple takeover of your own anchor tag that drops a quick client-side event in there for google to track, just before serving up your PDF.

< a href="http://www.example.com/files/map.pdf" onclick="javascript: pageTracker._trackPageview('/downloads/map'); ">

I’m not entirely clear on whether or not the link used in your javascript has to actually exist. If anyone figures it out before I get around to it, please post here!

In the mean time, here’s a link to the Google Analytics support page addressing this exact approach.