Clicky

  1. Home
  2. How To
  3. Setting up Session Stitching and Google AMP Client ID API

Setting up Session Stitching and Google AMP Client ID API

About the AMP Client ID API:

Google’s AMP Client ID API lets you uniquely identify users who engage with your content on AMP and non-AMP pages. If you opt-in, Google Analytics uses the AMP Client ID to determine that multiple site events belong to the same user when those users visit AMP pages via a Google viewer. Associating events and users provides features like user counts and session-based metrics.

Use the API to retrieve user IDs associated with AMP-page activity and consolidate those with your own representations of those same users on your non-AMP pages. The consolidated information provides a more accurate picture of user journeys and use of your service.

The API automatically sets the ID and expiration of the ID for each publisher. End users can opt out for individual publishers.

Setup:

1. AMP

In AMP options Panel, select Google Analytics as the Analytics Type.

If you are using GTM then enable the GTM support and add ‘googleanalytics’ as Analytics Type from AMP options Panel.

2. NON-AMP

If you use Google Tag Manager

The following steps should be completed on your existing published tag container(s).

  1. Navigate to Tag Configuration > Fields to Set.
  2. Set useAmpClientId to true.
  3. Save the new tag configuration.
  4. Submit the tag.
  5. Publish the container.
If you use analytics.js

Include the following in your Analytics tracking code:

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

Resources:

Session Stitching, the Advanced Class

The above outline to address session stitching should allow you to capture all of your users, but it does leave some issues. What it’s doing is taking data from two different sources and tie them together with a Client ID. At this point, you’ll be abe to see what’s coming through AMP pages vs. regular pages. There are still some shortcomings:

  • You can’t see the difference between your own hosted AMP pages vs. Google CDN hosted pages.
  • If you segment to determine transaction sources, the AMP pages will show as a web data source with zero sessions and some transactions.

The following steps will help address those issue.

1. The first additional step is to make sure that ‘ampproject.org’ is added into the Referral Exclusion List under the Property Settings in the Admin section of the Google Analytics account. This should remove a majority of self-referrals from the CDN: This does not remove the records in GA. It removes the referral (source/medium) over-ride from the user moving from CDN to site on 2nd click. Therefore, if the traffic hits the CDN via google/cpc or google/organic it remains as that for the cross-Data Source navigation … rather than being over-ridden by the Referral from the CDN.

exclude-ampproject-org

This referral exclusion will help e-commerce (and other) sites maintain tracking of a user session from initial entry on an AMP page in the CDN all the way through to checkout.

2. Google also recommends that you add all subdomains of ampproject.org to your referral exclusion list as well. This step only applies if you’ve got subdomains on your site (or that are being used as PPC landing pages) that are coded in AMP. If the site does not have a need to specifically track/over-ride the referral currently when navigating between CDN and site then excluding ‘ampproject.org’ Referral covers any override from the CDN well enough. Google recommends excluding each subdomain but if you have a large number of subdomains in your setup, this may not be practical.

3. Create a Hit-level custom dimension called “AMPDOC_HOST” in the Google Analytics property: This enables you to segment traffic that started in CDN versus AMP hosted page.

4. Set the pageview in Google Tag Manager for the AMP Container to include the custom dimension set the “Dimension Value” to “AMPDOC_HOST”:

amp-doc-host-page-tag

Note: “AMPDOC_HOST” does not need to be defined as a variable in the variable settings. The value can be set just like it is in the above screenshot.

5. You are then able to view pages served up in the CDN vs AMP pages in the content reports. To view landing pages served up by the CDN, filter by “cdn” by landing page:

filter-on-cdn-landing-pages

6. Then, finally, exclude “cdn” and include “amp” in the filter to view AMP landing pages:

final-amp-filtering-setup

Final Notes on Session Stitching

Support for AMP by other analytics providers remains a work in progress for most. A Google spokesperson told me that the above outlined solution is available to third party analytics platforms, but that “the best place for info is still the Google Analytics solution, since the AMP team is still working on getting documentation up for other 3rd parties.”

Resources

https://www.stonetemple.com/amp-tech-guide/

https://developers.google.com/analytics/devguides/collection/amp-analytics/client-id

https://support.google.com/analytics/answer/7486764

https://support.google.com/analytics/answer/6343176?hl=en&ref_topic=7378717

Ask your Questions Directly!
If you can't find the solutions in this article, then just ask us in the comments and we will answer it for you!
Updated on April 5, 2018

    Are you still looking for a solution?

    Then fill out the below form and we will reach out to you within a few hours.

    Was this article helpful?

    Related Articles

    Comments

    1. Do I still need to pass through all these with your plugin?

      1. Hi Samy,

        Will you please explain what do you want so we will help you as soon as possible.

      1. Hi GIRISH MAHATO,

        Will you please elaborate more about your issue so that we will understand and help you.

    2. just show screenshot how to set useAmpClientId in GTM to Set up Google AMP Client ID API

      1. Hi Arul,

        Will you please elaborate more about your issue so that we will understand and help you.

    3. Hi There! I am using AMP on one of the site https://thedigitalislam.com/ but I am facing issues in properly tracking my user’s metrics. I have integrated the GA TAG in the Given Analytics section but it’s not working correctly. Please let me know how can I solve this issue.

    4. Thanks for the article, is there any way I can receive an update sent in an email every time you make a new update?

    5. Google Analytics 4 does not show any real traffic or any visitor from Amp pages. How to fix it. I want to set up GA4 for this site. https://bestmattresser.in/ If you have any tutorial for this setup please let me know.

    Leave a Comment