Amphtml: AMP Analytics Client ID replacement inconsistent

Created on 27 Aug 2020  路  5Comments  路  Source: ampproject/amphtml

What's the issue?

I'm using amp-analytics with linkers - however, the variable substitution of CLIENT_ID(_) is different than when on a regular link.

For outbound links, I have the following setup:

    {
      linkers: {
        enabled: true,
        proxyOnly: false,
        amp_analytics: {
          ids: {
            cid: 'CLIENT_ID(_)',
            clientId: 'clientId(_)',
          },
          destinationDomains: ['*.pinterdev.com', '*.pinterest.com', 'pinterest.com'],
        },
      },
    };

I also have links in my document like this:

      <a
        className={css(styles.AnnotationPill__pillLink)}
        href={link}
        data-amp-replace="CLIENT_ID"
      >
        {annotation}
      </a>

These produce different results - a sample outbound link will have the following properties:

{
  "?amp_client_id": "amp-DBuTE-YADZ2S4e05_asrsw",
  "mweb_unauth_id": "7d93de3c",
  "amp_url": "https%3A%2F%2Fwww-dev-jdecaro.pinterdev.com%2Famp%2Fpin%2F666532813571229808%2F",
  "amp_analytics": "1*1deef19*cid*YW1wLURCdVRFLVlBRFoyUzRlMDVfYXNyc3c.*cid2*YW1wLURCdVRFLVlBRFoyUzRlMDVfYXNyc3c.*clientId*Y2xpZW50SWQoXyk."
}

amp_client_id is amp-DBuTE-YADZ2S4e05_asrsw, and the parsed amp_analytics key has cid of YW1wLURCdVRFLVlBRFoyUzRlMDVfYXNyc3c, and clientId of Y2xpZW50SWQoXyk

How do we reproduce the issue?

Use amp-analytics with the linkers attribute (documentation here) and create an a tag with data-amp-replace of CLIENT_ID(_). Click on that link and look at the search params.

What browsers are affected?

All

Which AMP version is affected?

Latest - 2008150009001

Bug

All 5 comments

Over to @zhouyx

Hi @jonluca, would you be able to provide a test page that exhibits this behavior? I am having trouble reproducing this bug on my end.

cid of YW1wLURCdVRFLVlBRFoyUzRlMDVfYXNyc3c

Hi @jonluca, this value that you are receiving is the correct CLIENT_ID (amp-DBuTE-YADZ2S4e05_asrsw); it is just encoded as per the linker format specified here. The linker feature will append the ids to the url as a query parameter, after encoding it partially.

If you are finding this value in the url, then you have two options:

  1. parse and decode the query string parameter yourself on the newly navigated page
  2. use the Cookie feature provided by amp-analytics to receive the linker-sent-values and write it to the window as a cookie

馃う That would do it! Thanks!

Was this page helpful?
0 / 5 - 0 ratings