googleanalytics / ga-dev-tools

A showcase of demos and tools built with the various Google Analytics APIs and Libraries.
https://ga-dev-tools.web.app/
Other
1.39k stars 557 forks source link

Cannot get an event's custom parameter value; instead I get the string "Array" #1797

Open aroncal opened 8 months ago

aroncal commented 8 months ago

What page is this happening on https://ga-dev-tools.google/ga4/query-explorer/ And same thing goes with the node package @google-analytics/data version 4.3.0

Describe the bug With the GA4 API in node, I'm trying to get the the "lead_id" custom parameter's value for each lead submitted with gtag. I get the string "Array" for the value of the even't custom parameter, instead of the value, like this:

{
  "dimensionHeaders": [
    {
      "name": "customEvent:lead_id"
    },
    {
      "name": "sessionDefaultChannelGroup"
    },
    {
      "name": "landingPage"
    },
    {
      "name": "city"
    },
    {
      "name": "country"
    }
  ],
  "metricHeaders": [],
  "rows": [
    {
      "dimensionValues": [
        {
          "value": "Array",
          "oneValue": "value"
        },
        {
          "value": "Organic Search",
          "oneValue": "value"
        },
        {
          "value": "/",
          "oneValue": "value"
        },
        {
          "value": "Istanbul",
          "oneValue": "value"
        },
        {
          "value": "Türkiye",
          "oneValue": "value"
        }
      ],
      "metricValues": []
    },
]

To Reproduce In GA4 i have defined a custom dimension, with "scope=Event" and "event parameter=lead_id":

image

With gtag (GA4) I send a "generate_lead" event with a custom parameter, like this (GA debugger output):

Processing GTAG command: ["event", "generate_lead", {currency: "EUR", value: 1, lead_id: "8209"}]

I check with the GA debugger that the event is correctly sent: image

Then, with the node package or the query explorer, I make the following request:

  let requestBody = {
    property: `properties/${process.env.PROPERTY_ID}`,
    dateRanges: [{startDate: '2daysAgo', endDate: '2daysAgo'}],
    dimensionFilter: {
      andGroup: {
        expressions: [
          {
            filter: {
              fieldName: "hostName",
              stringFilter: {
                value: hostName
              }
            }
          },
          {
            filter: {
              fieldName: "eventName",
              stringFilter: {
                value: "generate_lead"
              },
            }
          }
        ]
      }
    },
    dimensions: [
      {name: "customEvent:lead_id"},
      {name: "sessionDefaultChannelGroup"},
      {name: "landingPage"},
      {name: "city"},
      {name: "country"},
    ]
  };

Expected behavior I expect to get the lead's id (8209 in the example), like this:

{
  "dimensionHeaders": [
    {
      "name": "customEvent:lead_id"
    },
    {
      "name": "sessionDefaultChannelGroup"
    },
    {
      "name": "landingPage"
    },
    {
      "name": "city"
    },
    {
      "name": "country"
    }
  ],
  "metricHeaders": [],
  "rows": [
    {
      "dimensionValues": [
        {
          "value": "8209",
          "oneValue": "value"
        },
        {
          "value": "Organic Search",
          "oneValue": "value"
        },
        {
          "value": "/",
          "oneValue": "value"
        },
        {
          "value": "Istanbul",
          "oneValue": "value"
        },
        {
          "value": "Türkiye",
          "oneValue": "value"
        }
      ],
      "metricValues": []
    },
]