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
- Go to https://tagmanager.google.com and create an account
- Enter the url of your site as the container name and select Web
- 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).
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
- On the Accounts page, click on the Container Name
- On the left navigation, click "Tags", then click the "NEW" button
- Edit "Untitled Tag" with the name of your tag (ex: Google Analytics)
- Click "Tag Configuration" and under Featured, select "Universal Analytics"
- 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)
- Under "Track Type" in the dropdown select "Page View"
- Click "Triggering" and on the "Choose a trigger" screen, select "All Pages" and click "SAVE"
- 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
- On the Accounts page, click on the Container Name
Configure Built-In Variable
- On the left navigation, click "Variables", then under "Built-In Variables" click the "CONFIGURE" button
- Under "Clicks" check the box next to "Click Element" and "Click URL"
Create User-Defined Variable
- On the "Variables" page, then under "User-Defined Variables" click the "NEW" button
- Edit "Untitled Variable" with the name of your variable (ex: files)
- Click "Variable Configuration" and under "Page Variables", select "Custom JavaScript"
- 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
- On the left navigation, click "Triggers", then under "Triggers" click the "NEW" button
- Edit "Untitled Trigger" with the name of your trigger (ex: Download Link)
- Click "Trigger Configuration" and under "Click", select "Just Links"
- Check the box next to "Wait for Tags" and "Check Validation"
- 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)
- Under "This trigger fires on" select "Some Link Clicks"
- 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)
Create Tag
- On the left navigation, click "Tags", then under "Tags" click the "NEW" button
- Edit "Untitled Tag" with the name of your tag (ex: Downloads)
- Click "Tag Configuration" and under "Featured", select "Universal Analytics"
- 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)
- Under "Track Type" in the dropdown select "Event"
- 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)
- 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)
- Click "Triggering" and on the "Choose a trigger" screen, select "Download Link" and click "SAVE"
- Click "PUBLISH" in the upper right to make the tag live, click "PUBLISH" again and then click "CONTINUE"
Set Up Outbound Link Tag
- On the Accounts page, click on the Container Name
Configure Built-In Variable
- On the left navigation, click "Variables", then under "Built-In Variables" click the "CONFIGURE" button
- Under "Clicks" check the box next to "Click URL" (skip this step if "Click URL" is already listed under "Built-In Variables")
Create Triggers
- On the left navigation, click "Triggers", then under "Triggers" click the "NEW" button
- Edit "Untitled Trigger" with the name of your trigger (ex: Outbound Links)
- Click "Trigger Configuration" and under "Click", select "Just Links"
- Check the box next to "Wait for Tags" and "Check Validation"
- 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)
- Under "This trigger fires on" select "Some Link Clicks"
- 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)
Create Tag
- On the left navigation, click "Tags", then under "Tags" click the "NEW" button
- Edit "Untitled Tag" with the name of your tag (ex: Outbound Links)
- Click "Tag Configuration" and under "Featured", select "Universal Analytics"
- 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)
- Under "Track Type" in the dropdown select "Event"
- 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)
- 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)
- Click "Triggering" and on the "Choose a trigger" screen, select "Outbound Links" and click "SAVE"
- Click "PUBLISH" in the upper right to make the tag live, click "PUBLISH" again and then click "CONTINUE"