Track link and download clicks in Google Analytics

By default, Google Analytics (GA) only tracks page views for the pages the GA tracking code is installed on (complicated, I know). It doesn’t track interactions with the page or content that cannot include or evaluate JavaScript. This came up because I was curious to know how many people were clicking on the zip of my current weather widget for WordPress. I knew GA could be scripted to track interactions with a page relatively easily, but I couldn’t remember how.

A quick Google search later, I found some documentation and a script to dynamically add link tracking from Blast Analytics & Marketing. I liked the concept of the script, but (like every coder) there were a couple of things I wanted to change. While doing that, I thought of a couple more, and, the next thing I knew, I had several variations on a theme (all of which are available on GitHub).

To use, choose one of the files below and add it to the page/site you want to track via the standard script element (near the foot of the document is probably best). As of 19 April 2013, it requires jQuery 1.7+ to run, but I’m working on a pure JS implementation.


This is probably the version most people will want to use. It tracks clicks as events for the following link types:

  • External links (Different host than current site or marked rel="external")
  • File links (Executables, zip archives, PDFs, etc.)
  • Email links (mailto:)
  • Telephone links (tel:)

Tracked clicks will show up in Google Analytics under “Content” > “Events” in the following ways:

Event Category
External, email and telephone links will all have the category “Link clicks.” File links will have the category “Downloads.”
Event Action
External, email and telephone links are all labeled as such. File links are labeled with the file extension plus “download.” For instance, PDF download.
Event Label
External links are labeled with the URL of the link. File links are labeled with the file name. Email links are labeled with the email address of the link, and telephone links are labeled with the telephone number of the link.

Get ga-click-tracking-events.js on GitHub


This version is for people who want to inflate their pageviews! It’s very similar to ga-click-tracking-events.js, except PDF and text documents are not tracked as events, they are tracked as pageviews. (Note: Google recommends using event tracking, not virtual pageviews.)

The event tracking is the same as above, but clicks on PDF and text documents will show up in Google Analytics under “Content” > “Site Content” as pages. The page path is artificial. It’s constructed from the file extension plus the file name, for instance /PDF/PDF-file-name.pdf.

Get ga-click-tracking-events-pages.js on GitHub


This is a stripped-down version of ga-click-tracking-events.js that only tracks clicks on file links as events. This is the version for people who don’t care about tracking clicks on external, email and telephone links because, really? create some new content instead. ;)

Get ga-click-tracking-downloads.js on GitHub

Leave a Reply