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.

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.

  1. Set up the UA - Production Tracking ID variable.
    1. Go to Variables > New.
    2. 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.
    3. Click Variable Configuration.
    4. Choose Constant, under Utilities.
    5. For the value, copy in your UA tracking ID as found in Google Analytics, e.g. UA-XXXXXXX-1.
    6. Click Save.
  2. Set up the UA - Production Settings variable.
    1. Go to Variables > New.
    2. Choose a name that clearly identifies the variable as the UA settings for the production website, e.g. UA - Production Settings.
    3. Click Variable Configuration.
    4. Choose Google Analytics Settings, under Utilities.
    5. For the Tracking ID, type or pick {{UA - Production Tracking ID}}.
    6. Click Save.
  3. 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.
  4. Set up the UA - Pageview tag.
    1. Go to Tags > New.
    2. Choose a name for the tag that suggests that it is a pageview for Universal Analytics, e.g. UA - Pageview.
    3. Click Tag Configuration.
    4. Choose Google Analytics: Universal Analytics, under Featured.
    5. Ensure that the Track Type is Page View.
    6. For Google Analytics Settings, select your settings variable, in this case UA - Production Settings.
    7. Under Triggering, click "Choose a trigger.."
    8. Select All Pages.
    9. Click Save.

You're done! Now preview your container, or refresh your preview, and test out your implementation.

This site is sandbox environment that initiates your GTM container and sends data to your connected platforms. Use a GTM container and connected platforms that you're comfortable passing demo data to.