How to Track Referral Traffic Using AMP Client ID API in Google Analytics

How to Track Referral Traffic Using AMP Client ID API in Google Analytics

Launched by Google, Accelerated Mobile Pages, or AMP, has been an important initiative towards ensuring much quicker loading speed for the mobile content. It does so by laying out stringent guidelines and limitations for the content as well as for the developers that need to be complied with for optimizing the code to receive all the fast speed benefits. A key component in these efforts towards optimization is the need to employ lighter versions of Google Tag Manager and Google Analytics for the AMP pages. It’s worth noting that Google Tag Manager and Google Analytics tools have limited features and options for configuration. They also have many compatibility issues with the JS versions of standard websites.For your information, you can recognize an AMP content on your mobile device by a small icon that features a lightening bolt within a circle, this icon marks the content as AMP content.

AMP content can be self-hosted on your own domain. However, AMP content being viewed directly within the search results of Google is what’s most popular. Google search results AMP content is actually nothing but a copy of the AMP content self-hosted on your own domain which gets uploaded to Google AMP Cache automatically. It is Google AMP Cache that enables quick and robust hosting performance. What complicates the matter even further is the fact that the AMP cache version appearing in Google search lies within an <IFRAME>, or Google AMP Viewer; there’s a different URL associated with this version as well and the AMP Cache version could link to this URL directly.

Notable Issues with AMP and Google Analytics

Earlier users had quite a different method in which they arrived at a website via searching on Google. With the AMP project, the path that users have to follow now has changed significantly. Superficially, the current process may seem easy and intuitive, however, the entire process that starts from search leads to AMP, and finally ends at website actually undergoes multiple 1st and 3rd party technologies and hosts. This changed process poses certain issues for Google Analytics, such as:

  • As of now, there are several configuration options available in Universal Analytics that are not offered in AMP Google Analytics, including important options like cross-domain tracking and e-commerce.

  • The storage mechanism for client ID for a website is different in AMP Google Analytics and Universal Analytics. The client ID is not shared between Google-hosted AMP and self-hosted content. Google-hosted AMP also doesn’t share the client ID with AMP cache-hosted content that’s not viewed in an <IFRAME> Google search viewer. What this means is that same user who is crossing from AMP while searching for something in Google and arriving at your website will not be recognized by Google Analytics out-of-the-box.

  • Your user and session metrics face danger from the AMP Google Analytics data in a case where website data and AMP were to be combined in the same property. Tracking AMP to a separate property is also not a solution since this causes a gap in the Google Analytics data between the site and the search. In the AMP property, the search would get credit, and the same user would appear in site data as a referral from AMP Cache.

The Service of Google AMP Client ID API

This is a service that helps with unique identification and analysis of user experience across both AMP and non-AMP versions of the content. In this service, Google Analytics utilizes AMP Client ID to associate several website events to a particular user as they visit AMP pages through a Google AMP viewer.

So how does this service help with your data collection efforts? Unique identification of users across non-AMP and AMP pages means that when these uniquely identified users will return to your website, you’ll be able to assess and gauge their behavior with much greater accuracy through the session and user related metrics.

How to Setup Google AMP Client ID API?

To start using the Google AMP Client ID API service, there are 2 mandatory requirements that you need to fulfill. These requirements involve doing 2 code changes: one code change needs to be done on AMP pages and one code change needs to be done on non-AMP pages.

Few things that you should note as you implement this API service:

  • Collect the data within the same GA property to ensure the utility of Client ID API.

  • Sub-domain treatment will be the same for AMP and non-AMP pages. Referral exclusion should be used as per need.

1st Step:

In the first step, you need to opt-in for the service on the AMP pages.

In the <head> of your every AMP page, insert the above-mentioned code.

Keep in mind the below 3 guidelines when you use GA for your AMP pages:

  • Adding amp-analytics element to the <body> section of HTML.

  • Setting type attribute to googleanalytics.

  • Defining the tracking configuration as per your requirement.

Remember to use AMP-compliant tags in Google Tag Manager, in case you are using the Tag Manager.

2nd Step:

In the second step, you need to opt in for the service on the non-AMP pages.

Below are mentioned different instructions for implementing GA, go with the ones that align the most with your needs. The common objective in all these sets of instructions is that the useAMPclientID parameter should be set as true in the 1st call to the create function of Analytics. Also, you should verify the accurate functioning of the session stitching with the help of Setup Verification section.

Case 1: You are using gtag.js

In this case, you need to add the below code in your GA tracking code:

gtag('config', 'UA-XXXXX-Y', {'use_amp_client_id': true});

Case 2: You are using analytics.js

In this case, you need to add the below code in your GA tracking code:

ga('create', 'UA-XXXXX-Y', 'auto', {'useAmpClientId': true});

Case 3: You are using a 3rd party tag manager

You need to add a useAmpClientId parameter and set it as true for the Analytics create-tracker code. Check how to accomplish the same in your particular tag management system.

Case 4: You are using Google Tag Manager

If you already have one or more published containers, then follow the below steps. With GA Settings variable, you need to do just one change to upgrade all the related tags.

  • Open the desired container in Google Tag Manager and then click on Variables.

  • Open the GA Settings variable that needs to be edited. Click Variable Configuration card.

  • Go to Fields to Set in More Settings.

  • Click + ADD FIELD.

  • Keep the Field Name as useAmpClientId. Keep the Value as true.

  • Save the configuration changes that you’ve just made to the variable.

  • If you have more variables in your container, then follow the above-mentioned steps for all the pertinent GA Settings variables.

  • It’s now time for the container to be published.

In case you’re not using GA Settings variable, then you’ll need to change individual tags. Here’s how to do so:

  • Open the desired container in Google Tag Manager. Click on Tags.

  • Select the tag that needs to be edited and click on Tag configuration card.

  • Go to Fields to Set in More Settings.

  • Click + ADD FIELD.

  • Keep the Field Name as useAmpClientId. Keep the Value as true.

  • Save the configuration changes that you’ve just made to the tag.

  • Follow the above-mentioned steps for all the pertinent GA tags.

  • It’s now time for the container to be published.

3rd Step:

In the 3rd step, you’ll learn about employing referral exclusion as needed. AMP content is displayed to users by Google with the help of Google AMP Cache. To prevent any session breakage by the cached AMP sub-domains delivered by Google, what you must do is add a referral exclusion with the domain: It is also advised in the case where you are delivering AMP contents from several sub-domains, that you treat any given AMP sub-domain differently from the other one. If this is the case for you, then you should mention the cached versions of the sub-domains that are currently being specified in referral exclusion for your site. That way you’ll be able to maintain certainly defined referral exclusions across non-AMP and AMP websites.

So for instance, if there’s already a referral exclusion for the sub-domain, go ahead and define a referral exclusion for For your information, referral exclusions related to AMP can be specified in Analytics ADMIN together with the rest of your referral exclusions.

How to Verify that Your Setup of Google AMP Client ID API Service is Functioning Properly?

Following is a sequence of steps that you can follow to ensure the accurate working of the Google AMP Client ID API that you’ve just set up:

  • Launch the incognito mode of Google Chrome browser. Now enable mobile emulator in Chrome DevTools.

  • Perform such a search on that you get AMP page from your website as a result.

  • Click on the search result that’s displaying the AMP page from your website. This page should be delivered through the Google AMP Cache and presented in the Google Search AMP viewer.

  • Go to the Network tab in Chrome DevTools and filter for the string collect in order to learn the GA network request for the AMP pageview.

  • Go with the network request that’s directed to There will be a Headers tab for this request on which you should scroll to Query String Parameters in order to discover the client ID. Make a note of the cid parameter. You know that your AMP pages have been accurately opted-in if you see that the client ID is beginning with the amp- prefix.

  • Clear all the network requests by clicking on Clear.

  • Now you need to confirm that you’ve also accurately opted-in for your non-AMP pages. For this verification, you have to ascertain that the cid parameter that you had noted earlier persists even when you visit a non-AMP page. On your AMP page, find and click on a link that leads to a non-AMP page delivered by your domain. Filter for the string collect again to discover the client ID. Choose a network request that leads to Now see that the cid parameter value that you had noted earlier is the same as the cid query-parameter value.

  • In case the values of cid are not matching, execute the Analytics debugger and see whether the 1st call to ga("create" has the useAmpClientId: true parameter. Search for 'Running command: ga("create"' after opening Chrome DevTools.


If you want to have a positive impact on your online search ranking and your traffic to generate more conversions then you must hire us as a digital marketing company.