3

I am trying to integrate adobe analytics in an amp page. But the parameters that I want to pass, I want them to be picked up dynamically using an ajax call. I am picking up the values using an amp-list. The ajax response is somewhat like below:

{
  "items": [
    {
      "user_type": "site_user",
      "user_id": "anonymous"
    }
  ]
}

In the amp-analytics section I am trying to read the dynamic values of user_type and user_id using curly braces syntax. My code snippet looks like this:

<amp-analytics type="adobeanalytics_nativeConfig">
    <script type="application/json">
    {
        "requests": {
            "base": "${base}",
            "iframeMessage": "${base}/stats.html?user_type={{user_type}}&user_id={{user_id}}"
        },
        "vars": {
            "host": "${host}"
        }
    }
    </script>
</amp-analytics>

But instead of getting the values in the stats.html iframe request, the same syntax with curly braces itself is getting passes as values in the query parameters. This is what I am getting when the amp-analytics tag is defined outside the amp-list block. When I am putting the entire amp-analytics block within amp-list block, I do not see the stats.html call getting triggered. In browser console I am getting the below error:

No request strings defined. Analytics data will not be sent from this page. Ignoring event. Request string not found: iframeMessage

Both base and host are jstl variables and they are getting replaced with their proper values.

Can anyone please help on passing the dynamic values to structure the json iframe?

Bachcha Singh
  • 3,850
  • 3
  • 24
  • 38
Soumya Masani
  • 31
  • 1
  • 6

1 Answers1

0

For your Adobe Analytics AMP HTML integration, use the snippet below to pass your user_id and user_type variables to your stats.html page;

<amp-analytics type="adobeanalytics_nativeConfig">
  <script type="application/json">
    {
      "requests": {
        "base": "https://${host}",
        "iframeMessage": "${base}/stats.html?user_id=${user_id}&user_type=${user_type}"
      },
      "vars": {
        "host": "analytics.example.com",
        "user_id": "anonymous",
        "user_type": "site_user"
      }
    }
  </script>
</amp-analytics>

The interpolated ${base} variable will resolve into the base your defined host variable.

The host variable must be defined as a domain name other than the one serving your AMP HTML page; that's where your stats.html page must be hosted (as shared in the snippet, stats.html is located at the root of analytics.example.com the analytics domain name).

Your custom variables, just as your host variable, equally needs to be defined as under the vars object as illustrated above.

nyedidikeke
  • 6,899
  • 7
  • 44
  • 59