自定义事件 GA4 – 事件参数键丢失

huangapple go评论72阅读模式
英文:

Custom event GA4 - Event parameter key is missing

问题

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

我正在使用C#中的httpPost请求从服务器推送事件。

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

我不确定缺少什么,但在推送事件时我没有看到'event'参数键。

The event count appears to be correct.

事件计数似乎是正确的。

Here is my JSON.

这是我的JSON。

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

这是我的JSON。

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

这是我用于推送数据的C#代码。它运行良好,GA4_Endpoint格式正确。

// 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;
}

在GA4中,为什么当我点击事件时没有事件参数键?它不应该显示

method

这是我的实时显示。

英文:

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.

自定义事件 GA4 – 事件参数键丢失
自定义事件 GA4 – 事件参数键丢失
自定义事件 GA4 – 事件参数键丢失
?

答案1

得分: 1

这是你的JSON

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

这是来自GA4测量协议文档的JSON副本
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"
    }
  }
]
}

我能快速看到的问题是你的JSON中有一个包含你期望参数的item数组。也许你的JSON正确版本如下:

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

但我只是好奇为什么你的JSON中有一个item。这是从用于电子商务的JSON复制过来的吗?

英文:

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?

huangapple
  • 本文由 发表于 2023年6月30日 04:51:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76584540.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定