How to Track AMP Pages in Google Analytics
Accelerated Mobile Pages (AMP) are incredible for providing a lightning-fast user experience, but they can create a massive headache in your Google Analytics account. If you’ve noticed inflated user counts and broken session data, you're not alone. This guide will walk you through exactly how to set up proper tracking for your AMP pages in Google Analytics 4, so you can unify your data and get an accurate picture of your users' journeys.
Why Is Tracking AMP Pages So Confusing?
The core of the problem lies in how AMP pages are delivered. Most of the time, users don't access the AMP page directly from your server. Instead, they access a cached copy served by Google from its own Content Delivery Network (CDN), typically on a domain like google.com/amp/ or cdn.ampproject.org.
Here’s why that’s a problem for analytics:
- Different Domains = Different Users: By default, Google Analytics identifies a unique user with a "Client ID" stored in a browser cookie. This cookie is tied to a specific domain. A user visiting an AMP page on cdn.ampproject.org gets one Client ID. If they then click a link to your main site (e.g., yourwebsite.com), they get a second, different Client ID.
- Inflated User Counts: In this scenario, Google Analytics sees one person as two distinct "users," artificially inflating your user metrics.
- Broken Sessions: The user's journey is broken in two. The session on the AMP page ends, and a brand new session starts on your main website, often appearing as "Direct" or "Referral" traffic from cdn.ampproject.org instead of the original source like organic search. This completely messes up your attribution.
Think of it like this: a customer visits a pop-up shop of yours in a large mall (the AMP cache) and then walks into your main flagship store down the street (your website). Without a way to connect these two visits, your flagship store's staff would see a new customer walk in off the street, having no idea they just came from your pop-up. We need to give them a way to recognize it's the same person.
The Solution: The AMP Linker and Client ID API
Thankfully, there's a specific solution built for this exact problem: the AMP Client ID API. This feature works by doing two key things:
- It obtains the Client ID from Google's AMP cookie cache.
- It uses a "Linker" to decorate any links pointing from your AMP page to your main site. This means it appends a parameter to the URL containing the user's Client ID.
When the user lands on your main site, your Google Analytics tag can read this special URL parameter and unify the session, recognizing that it's the same user continuing their journey from the AMP page. This stitches the two separate visits into a single, cohesive session.
How to Set Up AMP Tracking in Google Analytics 4
Setting this up in GA4 requires adding some code to your AMP pages and configuring a setting in your GA4 property. Let’s go step-by-step.
Step 1: Make Sure You Have the amp-analytics Component
Your AMP pages must include the <amp-analytics> component. You enable this by adding the following script tag to the <head> section of your AMP page's HTML, if it isn't already there:
<script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>Step 2: Add the GA4 Configuration Code
Next, you need to add the actual <amp-analytics> code to the <body> of your AMP page. This code block tells the page how to send data to your specific GA4 property and, most importantly, enables the session unification feature.
Place this code snippet within the <body> tags:
<amp-analytics type="googleanalytics">
<script type="application/json">
{
"vars": {
"measurementId": "G-XXXXXXXXXX"
},
"triggers": {
"pageview": {
"on": "visible",
"request": "pageview"
}
},
"transport": {
"beacon": true,
"xhrpost": true
},
"linkers": {
"enabled": true
}
}
</script>
</amp-analytics>Let's break down the important parts:
"measurementId": "G-XXXXXXXXXX": This is a critical line. ReplaceG-XXXXXXXXXXwith your actual GA4 Measurement ID. You can find this in your GA4 property under Admin > Data Streams > [Your Web Stream]."linkers": { "enabled": true }: This is the key that unlocks the whole thing. It tellsamp-analyticsto activate the domain linker, which will automatically add the Client ID information to outbound links from your AMP page.
Step 3: Configure Your Domains in the GA4 Admin Panel
Telling your AMP page to add the tracking parameter is only half the battle. You also need to tell your main website's GA4 tag to look for that parameter and treat it correctly. Otherwise, it will just be ignored.
Here’s how to do that:
- Navigate to your Google Analytics 4 property.
- Click on Admin (the gear icon at the bottom left).
- In the Property column, click on Data Streams.
- Click on your web data stream.
- Under the Google tag section at the bottom, click on Configure tag settings.
- On the next screen, click Configure your domains under the Settings section.
- Click Add condition.
- Set the Match type to "Contains" and for the Domain, enter: ampproject.org.
Note: If you serve AMP pages from your own subdomain (e.g., amp.yourwebsite.com) or another CDN, you should add that domain here as well. Adding ampproject.org is the most common requirement.
- Click Save.
This setting officially tells GA4, "Any traffic coming from a domain that contains ampproject.org that has linker parameters in the URL should be considered part of the same user journey, not a new referral."
How to Verify Your AMP Tracking is Working Correctly
After implementing the changes, you need to confirm that everything is working as expected. Don't just set it and forget it!
Method 1: Check the Click-Through URL
The easiest way to check is to simulate a user's journey.
- Find one of your AMP pages in Google search results on a mobile device (or use the Chrome DevTools device emulator and find an AMP URL).
- Click on a link from that AMP page that leads to your main (non-AMP) website.
- Look closely at the URL in your browser's address bar once the new page loads. It should now have a parameter appended to it that looks something like
_gl=1*abcde*...
If you see that _gl parameter, the linker is successfully decorating the URLs. That’s a huge win!
Method 2: Use the GA4 Realtime Report
The Realtime report in GA4 is another great way to test the setup.
- Open the Realtime report in your GA4 property.
- On a separate device (like your phone using cellular data, not WiFi, to ensure a clean session), perform the same journey: visit an AMP page, then click a link to your main site.
- Watch the Realtime report. You should see your activity (page views, events) appear under a single user stream. Ideally, you won't see a new user pop up when you transition from the AMP cache to your main domain.
Common Mistakes to Avoid
- Using an Old Universal Analytics Code: The setup for Universal Analytics (UA) was slightly different. Double-check that you're using the GA4 configuration with
"measurementId"and not the old UA style with"trackingId". - Forgetting to Configure Domains in GA4: This is the most common mistake. If you only implement the code on your AMP site and neglect to update the settings in the GA4 admin, session stitching will fail.
- Serving AMP From a Custom Subdomain: If your AMP pages are served from a subdomain like
amp.yourwebsite.com, remember to also addyourwebsite.comto the Configure your domains section in GA4 Admin. The linker is needed to stitch sessions across different subdomains on your own site as well.
Final Thoughts
By correctly implementing the amp-analytics component with the AMP Linker and configuring your GA4 data stream, you can finally solve the longstanding problem of broken sessions from AMP pages. This ensures your data is clean, your user counts are accurate, and your marketing attribution reflects the true customer journey, from initial search click to final conversion.
Once you have clean, unified data flowing into Google Analytics, the next hurdle is making sense of it all, especially when you need to combine it with performance data from other platforms like your ad networks, CRM, and e-commerce store. This is exactly what we built Graphed for. We securely connect directly to your Google Analytics and other tools, letting you use simple conversational language to create dashboards and reports. Instead of grappling with GA4's interface, you can just ask, "Show me a report of sales conversions that originated from AMP page organic traffic this quarter," and get an answer instantly.
Related Articles
How to Connect Facebook to Google Data Studio: The Complete Guide for 2026
Connecting Facebook Ads to Google Data Studio (now called Looker Studio) has become essential for digital marketers who want to create comprehensive, visually appealing reports that go beyond the basic analytics provided by Facebook's native Ads Manager. If you're struggling with fragmented reporting across multiple platforms or spending too much time manually exporting data, this guide will show you exactly how to streamline your Facebook advertising analytics.
Appsflyer vs Mixpanel: Complete 2026 Comparison Guide
The difference between AppsFlyer and Mixpanel isn't just about features—it's about understanding two fundamentally different approaches to data that can make or break your growth strategy. One tracks how users find you, the other reveals what they do once they arrive. Most companies need insights from both worlds, but knowing where to start can save you months of implementation headaches and thousands in wasted budget.
DashThis vs AgencyAnalytics: The Ultimate Comparison Guide for Marketing Agencies
When it comes to choosing the right marketing reporting platform, agencies often find themselves torn between two industry leaders: DashThis and AgencyAnalytics. Both platforms promise to streamline reporting, save time, and impress clients with stunning visualizations. But which one truly delivers on these promises?