Virginia Tech® home

How Do I ... Track Document Downloads in Analytics

The following information can be used to setup document download tracking events within Google Analytics, using Google Tag Manager.

First, click on the Variables link in the left-side panel and then click on the Configure button for the Built-In Variables. Make sure the checkbox next to Click URL is turned on then close the panel.

It is highly recommended that you create the Trigger, before you create the Tag when doing this in Google Tag Manager.

  1. Log in to Google Tag Manager
  2. Under "Workspace" select "Triggers" from the left column menu
  3. Click the "New" button
  4. Type a name for the Trigger in the top-left, e.g. "File Download Trigger"
  5. Click the "Choose a trigger type to begin setup..." button
  6. Choose the Click trigger for "Just Links"
  7. Select the "Wait for Tags" checkbox and leave the default settings
  8. Select the "Check Validation" checkbox
  9. Set the first pulldown to "Page URL"
  10. Set the second pulldown to "matches RegEx"
  11. Set the field value to  .*  (period asterisk)
  12. Select the "Some Link Clicks" radio button
  13. Set the first pulldown to "Click URL"
  14. Set the second pulldown to "matches RegEx (ignore case)"
  15. Set the field value to ^.*\.(pdf|doc|docx|xls|xlsx|ppt|pptx|txt)$
  16. Click "Save"

NOTE: Yes, there are a lot of special characters in the regular expression. It starts with a carat ( ^ ) and ends with a dollar sign ( $ ). You may add more file types to the list by adding the extension characters with a pipe ( | ) between them, e.g.,


GTM Document Download Trigger
Image of the Google Tag Manager Trigger configuration

Once you've created the Trigger, you can now create the Tag.

  1. Click on "Tags" in the left column menu
  2. Click "New"
  3. Click the "Choose a tag type to begin setup..." button
  4. Click on "Universal Analytics"
  5. Set "Track Type" to "Event"
  6. Set "Category" to "Document Download"
  7. Set "Action" to "Click"
  8. Set "Label" to "{{Click URL}}" using the button to the right of the field.
  9. Click the pulldown for Google Analytics Settings and choose the analytics ID variable you may have already created or choose New Variable.
        - If creating a new variable enter your Google Analytics UA number and name the variable before clicking the Save button.
  10. Click the "Choose a trigger to make this tag fire..." button
  11. Select the Trigger you just created
  12. Click "Save" in the top-right corner

Publish your container by clicking the Submit button, top-right.

    - You will be asked to name the version and add a description if desired. It is recommended you do this so others that may come after you know what's been done.

Add your Google Tag Manager ID to the Site Configuration tab under the site level properties in the CMS.

Publish the site level page in the CMS.

You may need to republish one of the top level pages of your site (like the home page) in order for the new Tag Manager information to become available to all pages.

GTM Document Download Tag
Image of the Google Tag Manager Tag configuration