Client IDs in AMP pages

In order for Google Analytics to determine that two distinct hits belong to the same user, a unique identifier, associated with that particular user, is sent with each hit via the Client ID field. The unique identifier is a randomly generated string.

For non-AMP pages Google Analytics uses a single, first-party cookie named _ga to store the Client ID (on the publisher domain).

For AMP pages, things are a bit different. Pages can be viewed via a browser in multiple ways causing Client ID generation and management to vary. Because of this, site/app metrics are impacted.

Client ID Scenarios

The various ways users might access an AMP page and the Client ID implications are as follows:

  1. Google Search: AMP page is accessed via a Google Search result and displayed inside an "AMP viewer".

    • In this case the user performs a Google Search and the selected search result is an AMP page. The google.com page contains an IFRAME that points to cdn.ampproject.org and the content is loaded from cdn.ampproject.org.
    • The Client ID is stored on google.com because google.com is the 1st party in this case. The Client ID passed from the AMP viewer to the page served off of cdn.ampproject.org so that it can be transmitted via AMP-analytics.
    • Cookies are only reused if the original AMP pages have the same origin, which is a combination of schema, host, and port.
  2. Proxy/Cache: AMP page is accessed from a proxy/cache.

    • In this case the user goes directly to cdn.ampproject.org.
    • The Client ID is stored on cdn.ampproject.org. When user revisits (within some time), the Client ID is reused. cdn.ampproject.org is the 1st party in this case.
    • Cookies are only reused if the original AMP pages have the same origin, which is a combination of schema, host, and port.
  3. Direct AMP: AMP page is directly visited on publisher domain.

    • In this case the user goes directly to publisher's domain to view an AMP page.
    • The Client ID is stored in cookie (_ga) and is used/reused regardless of whether the ID is in traditional or AMP format.
    • If a Client ID is generated by an AMP page, the Client ID follows the AMP format (amp- followed by a randomly generated string).
  4. Non-AMP: non-AMP page is accessed on publisher domain.

    • In this case the user directly views a non-AMP page on the publisher's domain.
    • The Client ID is stored in cookie (_ga) and is used/reused regardless of whether the ID is in traditional or AMP format.
    • If a Client ID is generated by a non-AMP page, the Client ID follows the traditional Client ID format.

Client ID Considerations

There are some consideration to take into account based on the scenarios described above.

Multiple Client IDs

In all the scenarios, the Client IDs used for a user depend on the domain the user visits, even if the user is accessing content from a single client/browser. As a result, a user who accesses a publisher's content as described in the scenarios above will be counted as three separate users in Google Analytics (one each for search, proxy/cache and publisher origin scenario).

Scenario interactions

The following list provides notes and considerations for how interactions are handled when a user accesses content from the same publisher via multiple scenarios:

Google Search & Direct, Google Search & Non-AMP, Proxy/Cache & Direct, and Proxy/Cache & Non-AMP

  • IDs are kept separate because one of the cases uses local storage which is not accessible from the other case.

Direct & Non-AMP

  • A single cookie is used for a given user. The format of the Client ID depends on whether the user's first visit was to an AMP page or a non-AMP page.

Using a single Client ID across AMP and non-AMP pages

Use of a single Client ID across AMP and non-AMP pages can be enabled via AMP Client ID integration. Once enabled, Google Analytics will start using a single Client ID on Google Search, Direct AMP and Non-AMP scenarios mentioned above. A few examples for how the Client ID is determined for a user are as follows:

  • When a new user who visits an AMP page on Google Search, they will start out by using an AMP Client ID. When this user subsequently visits a non-AMP page, the same Client ID will be retrieved from cookies on the publisher domain and used for non-AMP pages as well.
  • When a returning user who has visited both AMP and non-AMP pages visits an AMP or non-AMP page, the AMP Client ID will be used for that user going forward.
  • When a returning user who has never visited an AMP page visits a non-AMP page, the Client ID generated by analytics.js will continue to be used.