Search code examples
jsongoogle-analyticsamp-htmlgtag.js

AMP Analytics "destinationDomains" not working in Linker config


I am trying to enable a linker string for links to my domains from my AMP site.

The current config is working only for links to the "canonical" domain at present, which is the default behavior.

I am also trying to enable it for links that are sent to my app's domain.

I've tried many variations of the code below (including using non-valid JSON array strings, as set out in the documentation here: https://ampbyexample.com/advanced/joining_analytics_sessions/#destination-domains) however this does not seem to work.

I am hoping this is a syntax or config issue but I am starting to have doubts. This is my code:

<amp-analytics type="gtag" data-credentials="include">
<script type="application/json">
{
   "vars": {
      "gtag_id": "AW-XXXXXX",
      "config": {
         "UA-XXXXX-X": {
            "groups": "default"
         },
         "AW-XXXXXX": {
            "groups": "default"
         }
      }
   },
   "linkers": {
     "enabled": true,
     "proxyOnly": false,
     "destinationDomains": [ "amp.mydomain.com", "www.mydomain.com", "app.altdomain.ly" ]
   },
   "triggers": {
      "trackPageview": {
         "on": "visible",
         "request": "pageview"
      }
   }
}
</script>
</amp-analytics>

I've also tried setting it out with a nested <paramName> object as follows, but I get the same result (works on canonical only):

...
    "linkers": {
        "Linker1": {
            "ids": {
                "_cid": "CLIENT_ID"
            },
            "proxyOnly": false,
            "destinationDomains": [ "amp.mydomain.com", "www.mydomain.com", "app.altdomain.ly" ],
            "enabled": true
        }
    }
...

Solution

  • Since you are using gtag, I think you might need to use the GTAG's configuration to configure the domains. Instructions are available here.

    Basically, the config looks like this:

    <amp-analytics type="gtag" data-credentials="include">
    <script type="application/json">
    {
      "vars" : {
        "gtag_id": "<GA_TRACKING_ID>",
        "config" : {
          "<GA_TRACKING_ID>": {
            "groups": "default",
            "linker": { "domains": ["example.com", "example2.com"] }
          }
        }
      }
    }
    </script>
    </amp-analytics>