Google Analytics on AMP Story

471 Views Asked by At

can anyone help me to put google analytic code on amp story? Amp-story does not support GA code? I have put it like this.

<amp-analytics type="gtag" data-credentials="include">
    <script type="application/json">
        {
            "vars" : {
              "gtag_id": "G-XXXXXXXXXX",
              "config" : {
                "G-XXXXXXXXXX": { "groups": "default" }
              }
            }
        }
    </script>
</amp-analytics>

But it seems does not work.

2

There are 2 best solutions below

1
On BEST ANSWER

I have got the issue. Amp Story does not support Google Analytic 4 yet. If we use UA-XXXXXXX-X this code it works but G-XXXXXXXXXX does not work.

1
On

Please add AMP analytic script first. Following is the google sample AMP snippet.

<script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>
<amp-analytics type="gtag" data-credentials="include">
<script type="application/json">
{
  "vars" : {
    "gtag_id": "<GA_MEASUREMENT_ID>",
    "config" : {
      "<GA_MEASUREMENT_ID>": { "groups": "default" }
    }
  }
}
</script>
</amp-analytics>

Also read following. https://developers.google.com/analytics/devguides/collection/amp-analytics enter image description here