{"id":4290,"date":"2017-11-25T13:42:32","date_gmt":"2017-11-25T13:42:32","guid":{"rendered":"https:\/\/ampforwp.com\/tutorials\/?post_type=ht_kb&#038;p=4290"},"modified":"2018-04-05T11:45:28","modified_gmt":"2018-04-05T11:45:28","slug":"set-google-amp-client-id-api","status":"publish","type":"ht_kb","link":"https:\/\/ampforwp.com\/tutorials\/article\/set-google-amp-client-id-api\/","title":{"rendered":"Setting up Session Stitching and Google AMP Client ID API"},"content":{"rendered":"<h3>About the AMP Client ID API:<\/h3>\n<p>Google\u2019s 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\u00a0<a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/amp-analytics\/client-id\">AMP Client ID<\/a>\u00a0to determine that multiple site events belong to the same user when those users visit AMP pages via a\u00a0<a href=\"https:\/\/support.google.com\/websearch\/answer\/7220196\">Google viewer<\/a>. Associating events and users provides features like user counts and session-based metrics.<\/p>\n<p>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.<\/p>\n<p>The API automatically sets the ID and expiration of the ID for each publisher. End users can opt out for individual publishers.<\/p>\n<h3>Setup:<\/h3>\n<h4>1. AMP<\/h4>\n<p>In AMP options Panel, select Google Analytics as the Analytics Type.<\/p>\n<p>If you are using GTM then enable the GTM support and add &#8216;googleanalytics&#8217; as\u00a0Analytics Type from AMP options Panel.<\/p>\n<h4>2. NON-AMP<\/h4>\n<h5><strong>If you use Google Tag Manager<\/strong><\/h5>\n<p>The following steps should be completed on your existing published tag container(s).<\/p>\n<ol>\n<li>Navigate to\u00a0<strong>Tag Configuration &gt; Fields to Set<\/strong>.<\/li>\n<li>Set\u00a0<code>useAmpClientId<\/code>\u00a0to\u00a0<strong>true<\/strong>.<\/li>\n<li>Save the new tag configuration.<\/li>\n<li>Submit the tag.<\/li>\n<li>Publish the container.<\/li>\n<\/ol>\n<h5>If you use analytics.js<\/h5>\n<p>Include the following in your Analytics tracking code:<\/p>\n<p><code>ga('create', 'UA-XXXXX-Y', 'auto', {'useAmpClientId': true});<\/code><\/p>\n<p>Resources:<\/p>\n<h3>Session Stitching, the Advanced Class<\/h3>\n<p>The above outline to address session stitching should allow you to capture all of your users, but it does leave some issues. What it\u2019s doing is taking data from two different sources and tie them together with a Client ID. At this point, you\u2019ll be abe to see what\u2019s coming through AMP pages vs. regular pages. There are still some shortcomings:<\/p>\n<ul>\n<li>You can\u2019t see the difference between your own hosted AMP pages vs. Google CDN hosted pages.<\/li>\n<li>If you segment to determine transaction sources, the AMP pages will show as a web data source with zero sessions and some transactions.<\/li>\n<\/ul>\n<p>The following steps will help address those issue.<\/p>\n<p>1. The first additional step is to make sure that \u2018ampproject.org\u2019 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 \u2026 rather than being over-ridden by the Referral from the CDN.<\/p>\n<p><a href=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/exclude-ampproject-org.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-4307\" src=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/exclude-ampproject-org.jpg\" alt=\"exclude-ampproject-org\" width=\"692\" height=\"285\" srcset=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/exclude-ampproject-org.jpg 692w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/exclude-ampproject-org-300x124.jpg 300w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/exclude-ampproject-org-50x21.jpg 50w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/exclude-ampproject-org-60x25.jpg 60w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/exclude-ampproject-org-100x41.jpg 100w\" sizes=\"(max-width: 692px) 100vw, 692px\" \/><\/a><\/p>\n<p>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.<\/p>\n<p>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\u2019ve 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 \u2018ampproject.org\u2019 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.<\/p>\n<p>3. Create a Hit-level custom dimension called \u201cAMPDOC_HOST\u201d in the Google Analytics property: This enables you to segment traffic that started in CDN versus AMP hosted page.<\/p>\n<p><a href=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/amp-doc-host.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-4308\" src=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/amp-doc-host.jpg\" alt=\"\" width=\"703\" height=\"124\" srcset=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/amp-doc-host.jpg 703w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/amp-doc-host-300x53.jpg 300w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/amp-doc-host-50x9.jpg 50w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/amp-doc-host-60x11.jpg 60w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/amp-doc-host-100x18.jpg 100w\" sizes=\"(max-width: 703px) 100vw, 703px\" \/><\/a><\/p>\n<p>4. Set the pageview in Google Tag Manager for the AMP Container to include the custom dimension set the \u201cDimension Value\u201d to \u201cAMPDOC_HOST\u201d:<\/p>\n<p><a href=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/amp-doc-host-page-tag.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-4309\" src=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/amp-doc-host-page-tag.jpg\" alt=\"amp-doc-host-page-tag\" width=\"705\" height=\"457\" srcset=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/amp-doc-host-page-tag.jpg 705w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/amp-doc-host-page-tag-300x194.jpg 300w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/amp-doc-host-page-tag-50x32.jpg 50w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/amp-doc-host-page-tag-60x39.jpg 60w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/amp-doc-host-page-tag-100x65.jpg 100w\" sizes=\"(max-width: 705px) 100vw, 705px\" \/><\/a><\/p>\n<p>Note: \u201cAMPDOC_HOST\u201d 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.<\/p>\n<p>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 \u201ccdn\u201d by landing page:<\/p>\n<p><a href=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/filter-on-cdn-landing-pages.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-4310\" src=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/filter-on-cdn-landing-pages.jpg\" alt=\"filter-on-cdn-landing-pages\" width=\"700\" height=\"280\" srcset=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/filter-on-cdn-landing-pages.jpg 700w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/filter-on-cdn-landing-pages-300x120.jpg 300w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/filter-on-cdn-landing-pages-50x20.jpg 50w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/filter-on-cdn-landing-pages-60x24.jpg 60w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/filter-on-cdn-landing-pages-100x40.jpg 100w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/a><\/p>\n<p>6. Then, finally, exclude \u201ccdn\u201d and include \u201camp\u201d in the filter to view AMP landing pages:<\/p>\n<p><a href=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/final-amp-filtering-setup.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-4311\" src=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/final-amp-filtering-setup.jpg\" alt=\"final-amp-filtering-setup\" width=\"697\" height=\"500\" srcset=\"https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/final-amp-filtering-setup.jpg 697w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/final-amp-filtering-setup-300x215.jpg 300w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/final-amp-filtering-setup-50x36.jpg 50w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/final-amp-filtering-setup-60x43.jpg 60w, https:\/\/ampforwp.com\/tutorials\/wp-content\/uploads\/2017\/11\/final-amp-filtering-setup-100x72.jpg 100w\" sizes=\"(max-width: 697px) 100vw, 697px\" \/><\/a><\/p>\n<h3>Final Notes on Session Stitching<\/h3>\n<p>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 \u201cthe 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.\u201d<\/p>\n<h3>Resources<\/h3>\n<p><a href=\"https:\/\/www.stonetemple.com\/amp-tech-guide\/\">https:\/\/www.stonetemple.com\/amp-tech-guide\/<\/a><\/p>\n<p><a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/amp-analytics\/client-id\">https:\/\/developers.google.com\/analytics\/devguides\/collection\/amp-analytics\/client-id<\/a><\/p>\n<p><a href=\"https:\/\/support.google.com\/analytics\/answer\/7486764\">https:\/\/support.google.com\/analytics\/answer\/7486764<\/a><\/p>\n<p><a href=\"https:\/\/support.google.com\/analytics\/answer\/6343176?hl=en&amp;ref_topic=7378717\">https:\/\/support.google.com\/analytics\/answer\/6343176?hl=en&amp;ref_topic=7378717<\/a><\/p>\n<div id=\"div-1\" class=\"hkb-feedback\">\n\t\t\t<strong class=\"ht-mobile-exit__title\">Ask your Questions Directly!<\/strong><br>\n\t\t\t<div class=\"hkb_widget_exit__content\" style=\"font-size: 14px;\">If you can't find the solutions in this article, then just ask us in the comments and we will answer it for you!<\/div>\n\t\t\t<a href=\"https:\/\/ampforwp.com\/support\/#contact\" id=\"button\" target=\"_blank\" rel=\"noopener noreferrer\"><button>Yes, I have a Question<\/button><\/a>\n\t\t<\/div>","protected":false},"excerpt":{"rendered":"<p>About the AMP Client ID API: Google\u2019s 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\u00a0AMP Client ID\u00a0to determine that multiple site events belong to the same user when those users visit AMP&#8230;<\/p>\n","protected":false},"author":5,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":[],"ht-kb-category":[34],"ht-kb-tag":[25,80],"_links":{"self":[{"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb\/4290"}],"collection":[{"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/comments?post=4290"}],"version-history":[{"count":5,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb\/4290\/revisions"}],"predecessor-version":[{"id":4313,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb\/4290\/revisions\/4313"}],"wp:attachment":[{"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/media?parent=4290"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb-category?post=4290"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/ampforwp.com\/tutorials\/wp-json\/wp\/v2\/ht-kb-tag?post=4290"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}