Google Tag Manager

Written by: Anne Holz | IANR Media

Google Tag Manager is a tool that allows you to easily add Google and third-party tags on your site without having to edit the source code (note: Using Google Tag Manager in UNLcms may conflict with existing GA code and should not be used. If using in the UNL.edu Framework on non-UNLcms sites the framework GA code should be removed). When using Google Tag Manager there's no need to separately add Google Analytics Tracking Code on your site. Instead, you'll set up a tag for Google Analytics in Google Tag Manager. 

Assuming you already have a Google Analytics account, you can begin using Google Tag Manager by creating a Google Tag Manager account, adding two snippets of code on your site and setting up tags.

Create Google Tag Manager Account

  1. Go to https://tagmanager.google.com and create an account
  2. Enter the url of your site as the container name and select Web
  3. Agree to the terms of service and follow the instructions to copy and paste the two Google Tag Manager code snippets. One snippet goes in the <head> and the other goes in the <body> of your site's source code. The container code includes a unique ID in the format GTM-XXXXXXXX (the ID should match the Container ID displayed on the Accounts page for your site).Google Tag Manager code snippets

Once the container code is in place you can begin setting up tags. The first tag you'll want to set up is a Google Analytics tag so that you can track pageviews in your Google Analytics account. 

Set Up Google Analytics Tag

  1. On the Accounts page, click on the Container Name
  2. On the left navigation, click "Tags", then click the "NEW" button
  3. Edit "Untitled Tag" with the name of your tag (ex: Google Analytics)
  4. Click "Tag Configuration" and under Featured, select "Universal Analytics"
  5. Enter your site's "Tracking ID" (this can be found in your Google Analytics account on the Admin>Property>.js Tracking Info>Tracking Code page)
  6. Under "Track Type" in the dropdown select "Page View"
  7. Click "Triggering" and on the "Choose a trigger" screen, select "All Pages" and click "SAVE"Google Analytics All Pages Trigger
  8. Click "PUBLISH" in the upper right to make the tag live, click "PUBLISH" again and  then click "CONTINUE"

You can check that pageviews are tracking properly by viewing the REAL-TIME overview report in your Google Analytics account. If pageview tracking is working, you'll see at least 1 "active user on the site" while you click around it.

The next two tags you'll want to set up are for tracking downloads and external links. The standard Google Analytics tracking code doesn't track downloads and external links. Before Google Tag Manager, tracking these required a developer to add additional code on your site. With Google Tag Manager you can track downloads and outbound links simply by configuring tags in the tool.

Set Up Downloads Tag

  1. On the Accounts page, click on the Container Name

Configure Built-In VariableGoogle Tag Manager Click URL Variable

  1. On the left navigation, click "Variables", then under "Built-In Variables" click the "CONFIGURE" button
  2. Under "Clicks" check the box next to "Click Element" and "Click URL"

Create User-Defined Variable

  1. On the "Variables" page, then under "User-Defined Variables" click the "NEW" button
  2. Edit "Untitled Variable" with the name of your variable (ex: files)
  3. Click "Variable Configuration" and under "Page Variables", select "Custom JavaScript"
  4. Enter the code below into the Custom JavaScript box and click "SAVE" (code is from Macro Magic For Google Tag Manager)

    function() {
    var ext = {{Click Element}}.pathname.split(".");
    return ext.length>1?ext.pop():'html';
    }

Create Triggers

  1. On the left navigation, click "Triggers", then under "Triggers" click the "NEW" button
  2. Edit "Untitled Trigger" with the name of your trigger (ex: Download Link)
  3. Click "Trigger Configuration" and under "Click", select "Just Links"
  4. Check the box next to "Wait for Tags" and "Check Validation"
  5. Under "Enable this trigger when..." in the dropdowns select "Page URL" then "matches Reg Ex" and in the text box enter ".*" (do not include the quotes)
  6. Under "This trigger fires on" select "Some Link Clicks"
  7. Under "Fire this trigger when..." in the dropdowns select "Click URL" then "matches Reg Ex" and in the text box enter "^.*\.(csv|doc|exe|flv|pdf|ppt|tar|txt|wav|wma|wmv|wpd|xls|zip)$"  and click "SAVE" (do not include the quotes, add or remove file extensions from the list to include only the ones you want to track) Google Tag Manager Download Trigger

Create Tag

  1. On the left navigation, click "Tags", then under "Tags" click the "NEW" button
  2. Edit "Untitled Tag" with the name of your tag (ex: Downloads)
  3. Click "Tag Configuration" and under "Featured", select "Universal Analytics"
  4. Enter your site's "Tracking ID" (this can be found in your Google Analytics account on the Admin>Property>.js Tracking Info>Tracking Code page)
  5. Under "Track Type" in the dropdown select "Event"
  6. For Category enter "Downloads", for Action click the "+" icon and select "Click URL", for label click the "+" icon and select "Page URL" (these correspond with the labels in Google Analytics Event reports, by selecting these options you'll be able to view the link to the downloaded file and the link to the page it was downloaded on)
  7. Under "Non-Interaction Hit" select "True" in the dropdown ("True" will prevent hits from artificially decreasing your bounce rate and inflating your pageviews with clicks that go to files instead of actual web pages)Google Tag Manager Download Tag
  8. Click "Triggering" and on the "Choose a trigger" screen, select "Download Link" and click "SAVE"
  9. Click "PUBLISH" in the upper right to make the tag live, click "PUBLISH" again and then click "CONTINUE"

Set Up Outbound Link Tag

  1. On the Accounts page, click on the Container Name

Configure Built-In Variable

  1. On the left navigation, click "Variables", then under "Built-In Variables" click the "CONFIGURE" button
  2. Under "Clicks" check the box next to "Click URL" (skip this step if "Click URL" is already listed under "Built-In Variables")

Create Triggers

  1. On the left navigation, click "Triggers", then under "Triggers" click the "NEW" button
  2. Edit "Untitled Trigger" with the name of your trigger (ex: Outbound Links)
  3. Click "Trigger Configuration" and under "Click", select "Just Links"
  4. Check the box next to "Wait for Tags" and "Check Validation"
  5. Under "Enable this trigger when..." in the dropdowns select "Page URL" then "matches Reg Ex" and in the text box enter ".*" (do not include the quotes)
  6. Under "This trigger fires on" select "Some Link Clicks"
  7. Under "Fire this trigger when..." in the dropdowns select "Click URL" then "does not match Reg Ex" and in the text box enter ".*yoursite\.com.+" replacing "yoursite" with your site's domain and click "SAVE" (do not include the quotes)Outbound Links

Create Tag

  1. On the left navigation, click "Tags", then under "Tags" click the "NEW" button
  2. Edit "Untitled Tag" with the name of your tag (ex: Outbound Links)
  3. Click "Tag Configuration" and under "Featured", select "Universal Analytics"
  4. Enter your site's "Tracking ID" (this can be found in your Google Analytics account on the Admin>Property>.js Tracking Info>Tracking Code page)
  5. Under "Track Type" in the dropdown select "Event"
  6. For Category enter "Outbound Links", for Action click the "+" icon and select "Click URL", for label click the "+" icon and select "Page URL" (these correspond with the labels in Google Analytics Event reports, by selecting these options you'll be able to view the outbound link and the link to the page it was clicked on)
  7. Under "Non-Interaction Hit" select "True" in the dropdown ("True" will prevent hits from artificially decreasing your bounce rate and inflating your pageviews with clicks that go to files instead of actual web pages)
  8. Click "Triggering" and on the "Choose a trigger" screen, select "Outbound Links" and click "SAVE"
  9. Click "PUBLISH" in the upper right to make the tag live, click "PUBLISH" again and then click "CONTINUE"

Page Feedback

Was this article helpful?