我正在尝试使用Measurement Protocol API 将购买发送到 GA4。
这是我的要求:
https://www.google-analytics.com/mp/collect?measurement_id=G-xxxxxxxxxx&api_secret=xxxxxxxxxxxxxxxxxxxxxx
array(4) {
["client_id"]=>
string(20) "123456789.1691234567"
["non_personalized_ads"]=>
bool(true)
["events"]=>
array(1) {
[0]=>
array(2) {
["name"]=>
string(8) "purchase"
["params"]=>
array(12) {
["currency"]=>
string(3) "EUR"
["transaction_id"]=>
string(16) "123456"
["shipping"]=>
float(6.9)
["tax"]=>
float(4.81)
["value"]=>
float(30.14)
["items"]=>
array(1) {
[0]=>
array(6) {
["item_id"]=>
string(11) "654321"
["item_name"]=>
string(36) "Test-Item"
["item_brand"]=>
string(9) "Test-Brand"
["price"]=>
float(23.24)
["quantity"]=>
float(1)
}
}
["engagement_time_msec"]=>
int(1)
["session_id"]=>
string(10) "1697002512"
}
}
}
["timestamp_micros"]=>
int(1697002689740112)
}
我从 _ga-cookie 中提取 client_id 并从 _ ga _[MeasurementId]-cookie 中提取 session_id,如下所示:
_ga=GA1.1.123456789.1691234567 => 客户端 ID = 123456789.1691234567 _ga_xxxxxxxxxx=GS1.1.1697002512.2.1.1697001234.45.0.0 => session_id = 1697002512
这两个 cookie 最初都是使用 GA4 中的 gtag.js 设置的,用户之前与页面进行过交互。
转化显示在 GA4 中,但无论用户来自哪里,几乎所有的营业额都分配给“未设置”的来源/媒介。因此,Google Ads 中根本不会弹出任何转化。
知道可能出了什么问题吗?我将请求发送到 /debug/mp/collect,但没有问题或此处显示的验证消息。我现在有点迷失在哪里继续调试这个东西了。
您在 Google Analytics 中遇到的“未设置”源/媒介问题可以通过在测量请求中包含会话 ID (SID) 来解决。会话 ID 对于准确跟踪 GA4 中的源/媒介和着陆页数据至关重要。 你的新请求应该是这样的:
curl 'https://www.google-analytics.com/mp/collect?&measurement_id=G-NHG43Z5FVJ&api_secret= ' \
-H 'authority: www.google-analytics.com' \
-H 'accept: */*' \
-H 'accept-language: en-US,en;q=0.9' \
-H 'content-type: text/plain;charset=UTF-8' \
-H 'origin: https://ga-dev-tools.google' \
-H 'referer: https://ga-dev-tools.google/' \
-H 'sec-ch-ua: "Google Chrome";v="117", "Not;A=Brand";v="8", "Chromium";v="117"' \
-H 'sec-ch-ua-mobile: ?1' \
-H 'sec-ch-ua-platform: "Android"' \
-H 'sec-fetch-dest: empty' \
-H 'sec-fetch-mode: cors' \
-H 'sec-fetch-site: cross-site' \
-H 'user-agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Mobile Safari/537.36' \
--data-raw '{"client_id":"","user_id":"1235467","timestamp_micros":"1696098319000000","non_personalized_ads":false,"events":[{"name":"purchase","params":{"items":[],"currency":"USD","transaction_id":"rte2319","value":1.1,"ga_session_id":1696098149}}],"validationBehavior":"ENFORCE_RECOMMENDATIONS"}' \
--compressed