4
votes

This used to work before but now when I add the following code snippet, from the Google Analytics AMP integration page, it does not make a network collect call for Google analytics https://developers.google.com/analytics/devguides/collection/amp-analytics/#extending_googleanalytics

<amp-analytics type="googleanalytics" id="analytics1">
<script type="application/json">
{
  "requests": {
    "pageviewWithCd1Cd3": "${pageview}&cd1=${cd1}&cd3=${cd3}"
  },
  "vars": {
    "account": "UA-XXXXX-Y"
  },
  "triggers": {
    "trackPageviewWithCustom" : {
      "on": "visible",
      "request": "pageviewWithCd1Cd3",
      "vars": {
        "title": "Classic Cars",
        "cd1": "registeredUser",
        "cd3": "automotive"
      }
    }
  }
}
</script>
</amp-analytics>

I replaced the account with a real account starting with UA

I also have the analytics script tag included in the head tag:

<script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>

The pageview does fire a request to collect but the cd1 and cd3 do not get included in the query params nor does the values of cd1 and cd3 get passed in the query params of the URL.

Have others noticed this same issue starting November 17th onwards?

3
Could you add a URL sample? - kul3r4
It turned out to be a Chrome bug in that it did not show the XHR request to analytic's collect endpoint because it was redirected. - Encore PTL
Analytics for AMP pages are not visible in regular GA Debug tool , we need to check in Google Tag Manager. Regarding the above example 'title' param is showing fine but 'cd1' , 'cd3' are not concatenated to the active url . yes same issue with me as well. - Lalit srikar

3 Answers

1
votes
0
votes

This worked for me - using dp=${newPageName} where 'newPageName' is custom url

<amp-analytics type="googleanalytics" id="analytics1">
<script type="application/json">
{
  "requests": {
    "pageviewWithCustomPageCd1Cd3": "${pageview}&dp=${newPageName}"
  },
  "vars": {
    "account": "UA-XXXXX-Y"
  },
  "triggers": {
    "trackPageviewWithCustom" : {
      "on": "visible",
      "request": "pageviewWithCustomPageCd1Cd3",
      "vars": {
        "title": "Classic Cars",    
        "cd1": "registeredUser",
        "cd3": "automotive",
        "newPageName": "sample.html?amp=1&cd1=${cd1}&cd3=${cd3}"
      }
    }
  }
}
</script>
</amp-analytics>
0
votes

If somebody ends up here looking for solution how to send custom dimensions for AMP, that's what finally worked for me:

<amp-analytics type="googleanalytics" id="analytics1">
    <script type="application/json">
      {
          "vars": {
              "account": "UA-XXX-XXXX"
          },
          "triggers": {
            "trackPageview": {
              "on": "visible",
              "request": "pageview",
              "extraUrlParams": {
                  "cd1": "dimension1Value",
                  "cd2": "dimansion2Value"
               }
            }
          }
      }
    </script>
</amp-analytics>

Documentation link