Search code examples
google-tag-manageramp-html

Passing along keys with whitespace through GTM AMP Variables


I'm trying to pass along the value of "content id" as an AMP variable in GTM. However, I'm having trouble getting it to pick up the value [presumably] due to the whitespace in the key:

<amp-analytics config="http://example.com/config.json">
<script type="application/json">
{
  "requests": {
    "pageview": "https://example.com/...
  },
  "vars": {
    "content id": "ABC123",
    "author": "John Smith"
  ...

Other keys (e.g. author) successfully return values. I've tried post%20id among other combinations, even directly referring to the value as a CD (bypassing GTM variables). Does anyone have any insight into AMP/GTM's handling of AMP Article vars with whitespace?


Solution

  • You cannot use space in variable name, you can use URL encoded version like this:

    <script type="application/json">
    {
      "vars": {
        "content%20id": "ABC123",
        "author": "John Smith"
        }
    }
    </script>
    

    Then in GTM use the same content%20id variable.

    But of course best way is just use something like content_id