How to sync CLIENT_ID across different serving methods of amp pages?

253 Views Asked by At

An AMP page can be served from google search cache inside an iframe using the amp cache/proxy, or directly from amp cache/proxy, or directly from the page URL. How can I sync the amp-analytics CLIENT_ID across these all methods?

I can sync direct amp and non-amp page since the cookie would be saved on the same domain. How to do it in other cases?

1

There are 1 best solutions below

0
On

Have you tried using AMP Variable Substitutions? Here - https://github.com/ampproject/amphtml/blob/master/spec/amp-var-substitutions.md#client-id

i.e. -

Example usage: ${clientId('fallback-cookie-name')}
Example value: amp-Us3yaeQyR2DKATQH1pTZ6kg140fvuLbtl5nynbUWtIodJxP5TEIYBic4qcV

From the documentation ( https://amp.dev/documentation/guides-and-tutorials/optimize-and-measure/configure-analytics/analytics_basics/ ) -

AMP manages reading and writing of the client ID in all cases. This is particularly notable in the case when a page is served via a cache or otherwise shown outside the viewing context of the publisher's original site. In this circumstance, access to the publisher site's cookies is unavailable.

When an AMP page is served from a publisher's site, the client ID framework that AMP uses can be told about a fallback cookie to look for and use. In this case, the cid-scope-cookie-fallback-name argument of the clientId variable is interpreted as a cookie name. The formatting may appear as either CLIENT_ID(cid-scope-cookie-fallback-name) or ${clientId(cid-scope-cookie-fallback-name)}