Blast Analytics and Marketing

Analytics Blog

Supporting Leaders to EVOLVE
Category: Google Analytics

How to Track Downloads & Outbound Links in Google Analytics

March 22, 2013

It has been almost 2 years since we published our wildly popular post, How to Track Downloads in Google Analytics. Since Google Analytics does not track file downloads, email, telephone or other outbound link clicks automatically, we saw an opportunity to File Downloadsprovide this code to the community. In our original post, we provided some explanations and code examples for tracking file downloads in Google Analytics using event tracking.

We decided to revisit our original post and provide a valuable code update that improves performance, makes tracking downloads more manageable and easier to extend.

Dynamically Track Downloads & Other External Links

For those who have a lot of links and would like to dynamically detect clicks on links to file downloads, we have provided updated code below. As before, this code requires the jQuery JavaScript library to be set before the code.

We have updated the code to make it more manageable and easier to extend. In addition, we are using the jQuery on() method for attaching the click event handler to links. Since we are using the on() method you will need to use jQuery v1.7+. If you are using an earlier version of jQuery the .live() method can be used instead.

The primary benefit of using the on() method is performance. Instead of looping through all ‘a’ elements on a page after the page loads (takes processing power on pages with lots of links), we instead listen for any clicks on the ‘a’ elements and invoke our custom JavaScript on the fly.

Again, feel free to customize this code to suite your needs. It can be placed in its own .js file and should be placed in the <head> of your pages. This script automates the following:

  • Tracks file downloads as events for the following extensions: .zip, .exe, dmg, .pdf, .doc, .docx, .xls, .xlsx, .ppt, .pptx, .mp3, .txt, rar, wma, mov, avi, wmv, flv, wav (again feel free to modify the list)
  • Tracks outbound clicks as events if the href value contains http:// or https:// and the domain value doesn’t match the current domain
  • Tracks mailto email clicks
  • Tracks Tel telephone clicks

The script sets download, email and tel link clicks as interaction events while the external site clicks are non-interaction which can be adjusted if desired.

As before, the script will detect if the link is opening in a new window or not and automatically uses setTimeout() for 400ms if you are not. This is to allow time for the hit request to process before taking the user to the new page.

Inline Download & Other External Links Tracking

If you’d rather not use the above method to place a single javascript file on your site and automate the tracking for all link elements, you can use the manual inline approach by tagging each link element individually. The inline approach can be time consuming and is not scalable.

The original syntax for adding the code inline remains the same.

New window/tab
For links that open a new window or tab (such as using target=”_blank” for example) you will want to use the code below:

In current window
For links that open within the same window, replacing the current page, you will want to use the code below:

These type of links require a slight delay to allow time for the hit request to process before taking the user to the new page.

Detailed Download & External Link Reports

After all of your hard work you will have event tracking reports with neatly organized data around file downloads, external link, email link, and telephone link clicks. From these reports you can gauge the usage and usefulness of your file downloads and various links.

By diving into the download category and selecting event label as the primary dimension you are able to see a report on all of the individual files downloaded from your site.

Lastly, since events are associated with the page they were fired on, you are able to apply a secondary dimension of page to find out which page contained the download or external link click that occurred.

If you need assistance with outbound link analysis, setup of this tracking code or any other analytics help, don’t hesitate to comment below or contact our Google Analytics Consulting Experts.

Ryan Chase
About the Author

Ryan is a Senior Analytics Consultant at Blast Analytics & Marketing. He is passionate about helping businesses improve their usage of data to make better decisions. He has experience across industries and analytics platforms to help set and meet long term business goals.

Connect with Ryan on LinkedIn. Ryan Chase has written on the Blast Digital Customer Experience and Analytics Blog.

HIPAA and Analytics White Paper CTA

Featured White Paper

Healthcare Analytics and HIPAA: Ways to Minimize Risk and Ensure Compliance

The rise in digital data and analytics adds complexity and risk for healthcare organizations. Those that don’t comply with data privacy requirements, including Health Insurance Portability and Accountability Act (HIPAA), could face heavy fines, civil action lawsuits, and even criminal charges. Not to mention loss of patient trust.

Download the White Paper

Ready To Do More With Your Data?

If you have questions or you’re ready to discuss how Blast can help you EVOLVE your organization, talk to an Analytics Consultant today.

Call 1 (888) 252-7866 or contact us below.