By default, Google Analytics is unable to track PDF documents. This is due to PDF’s not being able to run JavaScript code when viewed in a browser (or downloaded).  So to get around this, we can add a little bit of code to the website in order for PDFs to show up in Google Analytics.

What you’ll need:

  • Access to your JavaScript file.
  • Familiarity with JavaScript and adding code to it.
  • jQuery

In your JavaScript code, add the following:

So what’s going on here? Essentially this code loops through all the <a> tags that contain “pdf”. Then adds a Google Custom Event code to that link tag. When a user clicks on the link, an event push is sent to Google Analytics to track.


Blog Author Jonathan Volks

About Jonathan Volks

Jon has over 10 years of both front-end and back-end web programming and development. Currently he is a Senior Web Programmer at Skidmore College maintaing the marketing website. In his free time he enjoys hiking in the Adirondacks, hockey games with the Adirondack Thunder, and creating outragious fan theories about Westworld. Calling it right now, Stubbs is a host with Teddy's memories.