How to Track AMP Pages in Google Analytics 4
Setting up Google Analytics 4 tracking for your AMP pages can feel like a headache, but it's critical for accurate reporting. Without it, you might be splitting user sessions in two, misattributing traffic, and making decisions based on messy data. This tutorial will walk you through a step-by-step process to correctly configure GA4 for AMP, ensuring your analytics reflect the truth.
Understanding the AMP Tracking Challenge
Before we dive into the fix, let's quickly break down why tracking Accelerated Mobile Pages (AMP) in GA4 isn't straightforward. The core of the problem lies with two things: where your AMP content is hosted and how Google Analytics identifies users.
When someone finds your AMP page through Google Search, they aren't actually visiting your website domain. They are viewing a cached version of your page served directly from Google's domain (like google.com/amp/ or a similar URL on the ampproject.org domain). This is what makes AMP pages load so incredibly fast.
Meanwhile, Google Analytics identifies a unique user with something called a Client ID, which is stored in a cookie in the user's browser. When that user first arrives on your main website (e.g., yourwebsite.com) without going through AMP, GA4 creates a unique Client ID for them. But when they visit the AMP page on Google's domain, GA4 creates a different Client ID because the cookie is tied to google.com, not yourwebsite.com.
The result? When a user clicks from your AMP page in a Google search result to a regular page on your website, Google Analytics sees it as two separate users instead of a single continuous session. You lose the original source of the traffic (often showing up as a "self-referral") and your user counts get inflated. The whole user journey breaks.
The Solution: The AMP Linker and Cross-Domain Tracking
To fix this, Google created a feature for AMP called the "AMP Linker." It's a form of cross-domain tracking specifically tailored to this problem. When a user clicks a link from your AMP page (on Google's domain) to your main website (on your domain), the AMP Linker automatically adds a parameter to the destination URL. This parameter looks something like this: \_gl=1*abcde*...
That \_gl parameter carries the Client ID from the AMP session over to your main site. When your main site's GA4 tag sees this parameter, it understands that this is the same user and continues the session using the same Client ID. Voila! One user, one session, and your attribution data remains intact.
Getting this to work requires configuring a few settings correctly in both your Google Analytics 4 property and your Google Tag Manager container.
Part 1: Configure Your Google Analytics 4 Property
The first step is to tell GA4 which domains are part of your user's journey. By default, when traffic comes from one domain to another, GA4 sees it as a referral. We want to tell GA4 that traffic from Google's AMP cache to your own website isn't a new referral, it's the same person continuing their visit.
Follow these steps to set this up:
- Navigate to your Google Analytics 4 property.
- Click on the Admin gear icon in the bottom-left corner.
- In the Property column, click on Data Streams and select the web data stream for your website.
- Under the Google tag section at the bottom, click Configure tag settings.
- On the next screen, under Settings, click Configure your domains.
- Here, you'll set up rules for cross-domain measurement. Click the Add condition button.
- Set the Match type to "Contains" and enter your website's main domain (e.g.,
yourwebsite.com). It's important to enter only the root domain, withouthttpsorwww. - Click Add condition again. Set the Match type to "Contains" and enter
cdn.ampproject.org. - Click Add condition a third time. Set the Match type to "Contains" and enter
google.com. - Once you have all entries, your configuration should look something like this. Hit Save.
This tells GA4 that any sessions passing between these domains should be stitched together as a single journey, not treated as referrals from one another.
Part 2: Set Up AMP Linker in Google Tag Manager
Next, you'll configure your Google Tag Manager (GTM) container to enable the linker functionality. This is what activates the \_gl parameter magic. For this, you should already have a GTM container set up specifically for your AMP pages. If you haven't, you can follow Google's official guide to get that in place first.
Assuming your AMP container is ready, follow these steps:
Step 1: Enable the AMP Linker in Your GA4 Configuration Tag
Your GA4 setup in GTM relies on a master Google Analytics: GA4 Configuration tag. We need to modify this tag to enable cross-domain linking.
- In your AMP container in GTM, go to Tags and find your main GA4 Configuration tag. Click on it to edit.
- Expand the Fields to Set section and click Add Row.
- For the Field Name, enter
allowLinker. - For the Value, enter
true. Make sure it's lowercase. - Save the tag.
This simple field tells your tag that it's okay to look for and use the linker parameter if it exists in the URL.
Step 2: Create the Linker Trigger
Now, we need to create a trigger that listens for link clicks on your AMP page and tells GTM to decorate those URLs with the linker parameter.
- In GTM, navigate to Triggers and click New.
- Give your trigger a clear name, like "AMP Link Click Trigger."
- Under Trigger Configuration, choose the trigger type Link Click.
- This part is critical for AMP. Within the tag configuration, enable the checkbox labeled "Pass user identifier to main website" to enable the linker functionality. By ensuring this feature is active, GTM automatically handles the transmission of the user identifier, bridging the data between the AMP version of your page and your core website.
(Note: The exact checkbox label may vary depending on GTM interface updates, ensure that URL decoration/linker is enabled in your trigger configuration.)
How to Verify That Everything is Working
After you've configured GA4 and GTM and published your new GTM container version, you need to test it to make sure it's working.
The easiest way to check is to simulate how a user would find your page:
- Open a browser, then go to Google Search and find an AMP page on your site. Test after it is indexed, of course. This will be available on your search result page or, to do it faster just after making your edits, you can use the Google AMP Validator. Then load the page from an AMP URL.
- Click any button or menu item leading from the AMP page to one of your pages on your canonical domain. Then copy the link to the clipboard. This can be done with a right click, then a click to copy the address URL. Now, paste it in a browser and carefully look for a part that includes "
\_gl". If you can't locate it, the process is not working.
What If It's Not Working? Troubleshooting Tips
If you don’t see the \_gl parameter in your URL, here are a few things to check:
- Is your GA4 Configuration tag firing correctly? Use GTM's Preview mode on your AMP page to verify that your primary GA4 config tag is firing on page load. The Tag Assistant extension for Chrome is also helpful here.
- Re-check your configured domains in GA4: Go back to Admin > Data Streams > Configure tag settings > Configure your domains. Did you forget to include your domain? Have all required domains like
cdn.ampproject.organdgoogle.combeen added without typos? - Check your site setup: Ensure the GTM snippet is correctly installed on your pages (e.g., in the
<head>and<body>sections). - Check link attributes: Sometimes
target="_blank"attributes on your<a>links can prevent the process from working correctly. Review and adjust as needed.
Final Thoughts
Setting up AMP tracking in GA4 properly is not glamorous. However, doing so is essential to understanding your visitors accurately and making data-driven decisions. Correctly attributing visitors allows you to measure traffic across platforms like Facebook, SEO, and ad networks, becoming the foundation for informed marketing strategies and better content decisions.
Managing data efficiently sometimes takes up a lot of time. That's why our company offers a solution. You can join Graphed to automate this process, letting you focus on strategy rather than technical details. We built Graphed to quickly aggregate and visualize your data, saving you time and bolstering your decision-making process with powerful insights.
Related Articles
How to Enable Data Analysis in Excel
Enable Excel's hidden data analysis tools with our step-by-step guide. Uncover trends, make forecasts, and turn raw numbers into actionable insights today!
What SEO Tools Work with Google Analytics?
Discover which SEO tools integrate seamlessly with Google Analytics to provide a comprehensive view of your site's performance. Optimize your SEO strategy now!
Looker Studio vs Metabase: Which BI Tool Actually Fits Your Team?
Looker Studio and Metabase both help you turn raw data into dashboards, but they take completely different approaches. This guide breaks down where each tool fits, what they are good at, and which one matches your actual workflow.