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

Custom event GA4 - Event parameter key is missing


I am pushing an event from the server using an httpPost request in C#.

I'm not sure what is missing, but I don't see the 'event' parameter key when I push the event.

The event count appears to be correct.

Here is my JSON.

{"client_id":"server","events":{"name":"API_call","params":{"items":[{"method":"GetLicenceDetails"}]}}}

Here is my c# code to push the data. It's work well, and the GA4_Endpoint is properly formatted.

// endpoint : "https://www.google-analytics.com/mp/collect?measurement_id={0}&api_secret={1}";
    using (var httpClient = new HttpClient())
            {
              var data = SerializationHelper.SerializeToJson(analyticContainer);
              //https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference?client_type=gtag#payload_post_body
              httpClient.DefaultRequestHeaders.Add("Accept", "application/json");
              var e = await httpClient.PostAsync(GA4_Endpoint, new StringContent(data, Encoding.UTF8, "application/json"));
              return e;
            }

Why in GA4 when i click on the event there is no event parameter key ? It's not supposed to show

method

That is my realtime show.

enter image description here enter image description here enter image description here ?


Solution

  • Here is your JSON

    {
       "client_id":"server",
       "events":{
          "name":"API_call",
          "params":{
             "items":[
                {
                   "method":"GetLicenceDetails"
                }
             ]
          }
       }
    }
    

    Here is the JSON copy from the GA4 Measurement Protocol Document https://developers.google.com/analytics/devguides/collection/protocol/ga4/sending-events?client_type=gtag#recommended_parameters_for_reports

    {
    "client_id": "x",
    "events": [
      {
        "name": "offline_purchase",
        "params": {
          "engagement_time_msec": "100",
          "session_id": "123"
        }
      }
    ]
    }
    

    The quick thing I can see is you have a item array which contains the parameter you expected. So maybe the right version from your JSON is

    {
       "client_id":"server",
       "events":{
          "name":"API_call",
          "params":{
              "method":"GetLicenceDetails"
          }
       }
    }
    

    But just curious about why there is a item in your JSON. Is it copy from the JSON which using for ecommerce?