Tracking Pageviews, Including GA, in GTM
This sandbox will let you test out your Google Tag Manager knowledge in a safe place, without having to constnatly set up your own testing environments. Or, worse, doing it live.We want to track pageviews in Google Analytics on all pages so that we know where users are on the website.
There are several ways to do this, but we'll focus on the most generally applicable solution for now.
Explanation
Pageviews are very simple to set up and I'll leave that discussion for the Setup task. One consideration that will eventually make you use more complex setups for pageviews is that you don't always want to have the same behaviour on a Production (Live) website as you would on a Staging (Development, UAT, etc.) website. This topic can get very complex, so I'll just leave you with the basics for now.
Google Tag Manager Setup
- Set up the UA - Production Tracking ID variable.
- Go to Variables > New.
- Choose a name for the variable that clearly identifies it as the universal analytics (UA) Tracking ID for the production environment, e.g. UA - Production Tracking ID.
- Click Variable Configuration.
- Choose Constant, under Utilities.
- For the value, copy in your UA tracking ID as found in Google Analytics, e.g. UA-XXXXXXX-1.
- Click Save.
- Set up the UA - Production Settings variable.
- Go to Variables > New.
- Choose a name that clearly identifies the variable as the UA settings for the production website, e.g. UA - Production Settings.
- Click Variable Configuration.
- Choose Google Analytics Settings, under Utilities.
- For the Tracking ID, type or pick {{UA - Production Tracking ID}}.
- Click Save.
- Note that Google Tag Manager sets up an "All Pages" Page View trigger by default, so, while we almost always set up triggers, in this case we don't have to do any additional work.
- Set up the UA - Pageview tag.
- Go to Tags > New.
- Choose a name for the tag that suggests that it is a pageview for Universal Analytics, e.g. UA - Pageview.
- Click Tag Configuration.
- Choose Google Analytics: Universal Analytics, under Featured.
- Ensure that the Track Type is Page View.
- For Google Analytics Settings, select your settings variable, in this case UA - Production Settings.
- Under Triggering, click "Choose a trigger.."
- Select All Pages.
- Click Save.
You're done! Now preview your container, or refresh your preview, and test out your implementation.