Tracking pageviews with Google Tag Manager (GTM) is a crucial step for understanding user behavior on your website. Here’s a step-by-step guide on how to set up pageview tracking using GTM and Google Analytics:
1. Set Up Google Tag Manager
- Go to the Google Tag Manager website and sign in with your Google account.
- Click on “Create Account” and enter your account name, country, and container name (usually your website’s name).
- Choose “Web” as the target platform and click “Create.”
- After creating your container, GTM will provide you with a snippet of code.
- Copy the code snippets and paste them into your website’s HTML, right after the opening
<head>
tag and immediately after the opening<body>
tag.
2. Set Up Google Analytics
-
- Go to the Google Analytics website and sign in with your Google account.
- Click on “Start Measuring” and follow the prompts to create an account and a property for your website.
- You’ll receive a tracking ID (e.g., UA-XXXXXXXXX-X) or a Measurement ID (for GA4).
3. Configure Google Analytics Tag in GTM
- Access GTM:
- Log in to your Google Tag Manager account and select your container.
- Create a New Tag:
- Click on “Tags” in the left-hand menu and then “New.”
- Click on “Tag Configuration” and select “Google Analytics: Universal Analytics” (for GA3) or “Google Analytics: GA4 Configuration” (for GA4).
- Configure the Tag:
- For Universal Analytics (GA3):
- Choose “Page View” as the Track Type.
- Enter your Google Analytics Tracking ID (UA-XXXXXXXXX-X) in the “Tracking ID” field.
- For Google Analytics 4 (GA4):
- Enter your GA4 Measurement ID in the “Measurement ID” field.
- For Universal Analytics (GA3):
- Set the Trigger:
- Click on “Triggering” and select the “All Pages” trigger. This will fire the tag on every pageview.
- Click “Add” to apply the trigger.
- Save the Tag:
- Give your tag a name (e.g., “GA Pageview Tag”) and click “Save.”
4. Publish Your Container
-
- Click on “Submit” in the top right corner of the GTM interface.
- Add a version name and description for your changes (e.g., “Initial setup of GA pageview tracking”).
- Click “Publish” to make the changes live on your website.
5. Verify the Setup
- Use GTM Preview Mode:
- In GTM, click on the “Preview” button to enter debug mode.
- Open your website in a new tab. The GTM debug panel will appear, showing which tags are fired on each page.
- Navigate through your website to ensure the GA pageview tag is firing correctly.
- Check in Google Analytics:
- Open Google Analytics and go to the “Real-time” report.
- Visit your website and check if the pageviews are being tracked in real-time.
- Navigate through different pages to confirm that pageview data is being recorded accurately.
By following these steps, you can successfully set up and track pageviews on your website using Google Tag Manager and Google Analytics, providing you with valuable insights into user behavior and website performance.