Search code examples
google-analyticsgoogle-apigoogle-tag-managergoogle-analytics-apigoogle-analytics-4

How to send event parameters for a tag through the google tag manager API


With this query i can create a GTM event tag for Google Analytics 4. i would like to pass some event parameters aswell. I feel that im really close because the API seems to recognize the eventParameters key, it tells me that its value its invalid.

"vendorTemplate.parameter.eventParameters[0]: The value is invalid.\n",

If i change this eventParameters key to something else, the query goes through (obviously without taking into consideration my eventParameters) so i know that this code has to be close.

The documentation is really shallow so building queries with the GTM api its been very trial and error until now.

When i get this working i'll probably make a sample for automating trigger and tag creation for GA4 migrations

`

{
  "name": "test2",
  "type": "gaawe",
  "parameter": [
    {
      "type": "template",
      "key": "eventName",
      "value": "hey"
    },
    {
      "type": "tagReference",
      "value": "LocalTag",
      "key": "measurementId"
    },
    {
      "type": "list",
      "key": "eventParameters",
      "list": [
        {
          "type": "template",
          "value": "page_title",
          "key": "page_title"
        }
      ]
    }
  ]
}

`


Solution

  • The parameters is a array

    Here is the example:

        {
          "type": "MAP",
          "map": [
            {
              "type": "TEMPLATE",
              "key": "name",
              "value": `${parameterName}`
            },
            {
              "type": "TEMPLATE",
              "key": "value",
              "value": `${parameterValue}`
            }
          ]
        }
    

    And if you want to pass a variable to the value Just add the "{{" , "}}" as you used in GTM UI.

    Like {{DataLayer-Ecommerce}}

    So yes you are very close to it.