How to track pageviews with Google Tag Manager

Author:

Tracking pageviews using Google Tag Manager (GTM) allows you to monitor the traffic to your website without having to manually insert tracking code on each page. GTM simplifies the process by enabling you to manage tags from a centralized interface. Here’s a step-by-step guide on how to track pageviews with Google Tag Manager:

1. Set Up Google Tag Manager Account

If you haven’t set up a GTM account yet, follow these steps:

  • Go to the Google Tag Manager website.
  • Sign in with your Google account.
  • Create a new account and container by clicking the “Create Account” button.
    • Fill in your account name (typically the name of your business or website).
    • Choose the container’s name, which should usually be your website’s domain.
    • Select the target platform (e.g., Web, iOS, Android).
  • Install the GTM container code on your website. GTM will provide you with two snippets of code: one for the <head> and one for the <body> sections of your website. Paste these codes in the appropriate places in your website’s HTML.

2. Link Google Tag Manager to Google Analytics

To track pageviews, you’ll need to link GTM to Google Analytics (GA):

  1. Create a Google Analytics account (if you haven’t already):
    • Go to Google Analytics.
    • Create an account and set up a new property for your website.
    • Retrieve the Tracking ID from your Google Analytics account.
  2. Set up the Google Analytics tag in GTM:
    • Open your Google Tag Manager container.
    • Click Tags in the left-hand menu.
    • Click New to create a new tag.
    • Click on Tag Configuration and select Google Analytics: GA4 Configuration (for Google Analytics 4) or Universal Analytics (for older versions of GA).
    • For GA4:
      • Enter your Measurement ID from Google Analytics 4.
      • Set the trigger to All Pages (this ensures that every pageview is tracked).
    • For Universal Analytics:
      • Choose Page View as the track type.
      • Enter your Tracking ID.
      • Set the trigger to All Pages.
  3. Save the tag.

3. Configure Triggers for Pageview Tracking

The default trigger in GTM is All Pages, which tracks every pageview. Here’s how to ensure it’s correctly configured:

  • Navigate to Triggers in the GTM interface.
  • Click New to create a new trigger.
  • Select Page View as the trigger type.
  • Choose All Pages if you want to track every page visited on your site.

For more specific triggers:

  • Choose Some Page Views and define conditions based on page URL, page path, or other parameters (for instance, only tracking specific URLs or categories).

4. Test Your Tag Setup

Before publishing your tag, it’s important to test that the tag is firing correctly:

  1. Preview mode:
    • In the top-right corner of your GTM interface, click the Preview button.
    • This opens a new tab called Tag Assistant in your browser.
    • Enter your website’s URL in the preview window and click Connect.
    • Browse through your website and check the Tag Assistant tab to ensure the Google Analytics pageview tag is firing correctly.
  2. Debugging:
    • On your website, the Tag Assistant should show the GTM events as you browse. Look for a “Pageview” event, and under Tags Fired, verify that your Google Analytics tag fired on each page.
    • If the tag did not fire, return to GTM to troubleshoot. Ensure the correct trigger is assigned to the tag.

5. Publish Your Changes

Once you’ve confirmed the tag is firing correctly:

  1. Exit preview mode.
  2. In the top-right corner of GTM, click the Submit button.
  3. Provide a name and description for your changes (e.g., “GA Pageview Tracking”).
  4. Click Publish.

Your tag is now live, and Google Analytics will start tracking pageviews across your website.

6. View Pageviews in Google Analytics

Now that pageview tracking is active, you can monitor your website traffic directly in Google Analytics:

  1. Go to Google Analytics.
  2. Navigate to ReportsEngagementPages and screens (in GA4) or BehaviorOverview (in Universal Analytics).
  3. You should start seeing pageviews recorded in real-time or as users visit different pages.

7. Advanced Pageview Tracking Options

For more advanced pageview tracking configurations, you can set up custom pageviews and virtual pageviews.

Virtual Pageviews

Virtual pageviews are useful when you want to track events that aren’t traditionally pageviews (such as clicks or form submissions) but want them recorded as pageviews in Google Analytics. This can be set up with custom triggers.

Example for Virtual Pageviews:

  • Create a new trigger based on an event, like a button click.
  • Set a tag in GTM to fire a Google Analytics pageview when that event occurs.

To set up virtual pageviews:

  1. Create a new Tag in GTM.
  2. Choose Universal Analytics (or GA4), and for track type, select Pageview.
  3. In the Page Path or Page URL field, enter a custom URL (e.g., /thank-you or /virtual-pageview).
  4. Set a trigger based on the event you want to track (e.g., Click or Form Submission).
  5. Save and publish the tag.

Virtual pageviews will appear in Google Analytics as if a user visited the custom URL you defined.

8. Troubleshooting Tips

  • Tag Not Firing: If the tag isn’t firing on pageviews, double-check the trigger setup and ensure that you’ve selected All Pages or the correct condition under Some Pages.
  • Duplicate Pageviews: If you notice duplicate pageviews being tracked, ensure that you haven’t accidentally set up multiple triggers that overlap.
  • No Data in Google Analytics: There might be a delay in data appearing in Google Analytics. Also, confirm that the tracking ID is correctly entered in GTM and that the correct property is being used in GA.

Conclusion

Tracking pageviews with Google Tag Manager is an efficient way to manage your website’s analytics without manually adding code. By following the steps outlined above, you can easily set up pageview tracking, test its implementation, and start gathering data in Google Analytics. This data is crucial for understanding user behavior, optimizing content, and improving overall website performance.