简体   繁体   English

使用 Measurement Protocol (GA4) 设置 debug_mode

[英]Setting debug_mode with Measurement Protocol (GA4)

Can't find a way to set the debug_mode parameter using Measurement Protocol 4 .找不到使用Measurement Protocol 4设置debug_mode参数的方法。 Tried to put it everywhere (and naming it all i can think of) but without luck:) Documentation is still very light and doesn't mention the debug_mode.试图把它放在任何地方(并命名我能想到的所有东西)但没有运气:) 文档仍然很轻,没有提到 debug_mode。 With web/js and GA4 it works fine!使用 web/js 和 GA4 可以正常工作!

To add to the answers of @DalmTo and @bang - I wasn't seeing events I was sending over the Measurement Protocol show up in our GA4 Debug View.补充@DalmTo 和@bang 的答案——我没有看到我通过Measurement Protocol 发送的事件出现在我们的GA4 调试视图中。 The root cause in my case was that the Measurement Protocol expects a funky format for the user_properties , but the following steps should help others debug other problems as well.在我的案例中,根本原因是Measurement Protocol 期望user_properties的格式很时髦,但以下步骤也应该有助于其他人调试其他问题。

Steps I took to resolve:我采取的解决步骤:

  1. Add the debug_mode: true field to individual event params as described in @bang's answerdebug_mode: true字段添加到单个事件参数中,如@bang 的答案中所述
  2. Use the /debug/mp endpoint as described in @DalmTo's answer - this pointed me towards the errors in my user_properties format使用@DalmTo 的回答中描述/debug/mp端点 - 这将我指向我的user_properties格式的错误

Regarding the user_properties field, I was sending something along these lines:关于user_properties字段,我发送了以下内容:

{
  "client_id": "XXX.XXX",
  "user_id": "YYY",
  "user_properties": {
    "property_a": "value_a",
    "property_b": "value_b"
  },
  "events": ...
}

Turns out GA4 / Measurement Protocol expect something like this:结果 GA4 / Measurement Protocol 期望这样的事情:

{
  "client_id": "XXX.XXX",
  "user_id": "YYY",
  "user_properties": {
    "property_a": { "value": "value_a" },
    "property_b": { "value": "value_b" }
  },
  "events": ...
}

At the time of writing, the only way to figure this out is to carefully check out the example here .在撰写本文时,解决此问题的唯一方法是仔细查看此处的示例。

The measurment protocol for ga4 has two endpoints just like the measurment protocol for the old Google anlaytics ga4 的测量协议有两个端点,就像旧的谷歌分析的测量协议一样

  • Measurement Protocol /mp/collect测量协议 /mp/collect
  • Measurement Protocol Validation Server /debug/mp/collect测量协议验证服务器 /debug/mp/collect

So if you send a event to it will be sent to Google anlaytics ga4因此,如果您向其发送事件,它将被发送到 Google anlaytics ga4

POST /mp/collect HTTP/1.1
HOST: www.google-analytics.com

<payload_data>

So if you send a event to it will be sent to debug endpoint for Google anlaytics ga4因此,如果您向其发送事件,它将被发送到 Google anlaytics ga4 的调试端点

POST /debug/mp/collect HTTP/1.1
HOST: www.google-analytics.com

<payload_data>

Weird.诡异的。 Suddenly the debug mode started to work with code I'm 100% sure didn't work before.突然间,调试模式开始使用代码,我 100% 确定之前没有工作。

Adding the parameter debug_mode = true to the measurement protocol 4 request will make it show up in analytics DebugView.将参数 debug_mode = true 添加到测量协议 4 请求将使其显示在分析 DebugView 中。

Sample json payload that works:有效的示例 json 有效载荷:

{
  client_id: 'XXXXXXXXXX.YYYYYYYYYY',
  events:
  [{
    name: 'page_view',
    params:
    {
      page_location: '....',
      page_path: '....',
      page_title: '....',
      debug_mode: true
    }
  }]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM