Skip to content

Analytics: gtag domain linker adds _gl query parameter even when navigating AMP internal links on origin #30176

@westonruter

Description

@westonruter

I'm not entirely sure this is a bug, but it feels like it.

On my WordPress site which is AMP-first, I have the Google Site Kit plugin running with Google Analytics configured like this (as provided by Site Kit):

<amp-analytics type="gtag" data-credentials="include">
    <script type="application/json">
        {"vars":{"gtag_id":"UA-123456-1","config":{"UA-123456-1":{"groups":"default","linker":{"domains":["weston.ruter.net"]}}}},"optoutElementId":"__gaOptOutExtension"}
    </script>
</amp-analytics>

From the homepage at https://weston.ruter.net/ if I then click on post for “Integrating with AMP Dev Mode in WordPress” which has the URL of https://weston.ruter.net/2019/09/24/integrating-with-amp-dev-mode-in-wordpress/ I am actually taken to a URL like:

https://weston.ruter.net/2019/09/24/integrating-with-amp-dev-mode-in-wordpress/?_gl=1~abcde5~

This happens for each internal link I click on my site. When I navigate around my site, each request includes a _gl query parameter, and then it gets stripped out with history.replaceState() when the page initializes (as far as I can tell).

As I understand, this is in order to measure customer journeys across domains. Nevertheless, I am not navigating across domains. I am navigating on my own domain.

Shouldn't this _gl query parameter only be added links for pages that are served on the AMP Cache over to the origin domain? The injection of this query parameter when navigating around on the origin server is problematic for a couple reasons:

  1. It is distracting for users who care about what is in the Location bar. I see I am navigated to some URL with a long random string, and then it disappears. That's somewhat disconcerting.
  2. It can interfere with full-page caching since no two page requests will have the same URL.
  3. It also breaks service worker caching of navigation requests, unless you figure out logic to explicitly strip out the _gl parameter when caching a response or looking up a previously-cached response.

This issue can also be seen on https://amp.dev/ when clicking on the “Blog” link in the nav menu. Instead of landing on https://blog.amp.dev/ I am actually taken to:

https://blog.amp.dev/?_gl=1~abcde5~

Here, however, the _gl query parameter is not stripped out because the domain linker functionality is not currently enabled. This was reported at ampproject/amp.dev#4292

In any case, should this _gl parameter be added to such links in the first place? Shouldn't it only happen if blog.amp.dev is included among the domains configuration for gtag?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions