提问人:Amir Dora. 提问时间:11/7/2023 最后编辑:Amir Dora. 更新时间:11/7/2023 访问量:18
Firebase 分析响应 204,分析中未显示事件
Firebase analytics response 204, event not being seen in analytics
问:
我将分析自定义事件发送到 Google Analytics(分析),但这些事件未显示。谷歌分析的 api 总是返回,我不确定事件是否被正确发送。邮递员也是如此,即使 measurement_id 或 api_secret 是假的,它也总是返回 204。与此工具相同。204 no content
https://ga-dev-tools.google/ga4/event-builder/
如何确保事件被记录响应没有多大帮助,事件需要多长时间才能出现在控制台中。204 no content
private function sendAnalyticsEvent(string $eventName): void
{
try {
$data = $this->constructEventData($eventName);
$this->analyticsRequestService->sendEvent($data);
} catch (\Exception $e) {
$this->logger->error(sprintf('Error sending analytics event: %s', $e->getMessage()));
}
}
private function constructEventData(string $eventName): array
{
$client_id = session_id(); // Retrieve or generate client_id appropriately
return [
'client_id' => $client_id,
'non_personalized_ads' => false,
'events' => [
[
'name' => $eventName,
'params' => [
'items' => [], // Populate with relevant items
'search_term' => 'validate' // Or any other relevant parameters
]
]
]
];
}
public function sendEvent(array $eventData): void
{
try {
$response = $this->client->post("https://www.google-analytics.com/mp/collect?measurement_id={$this->measurementId}&api_secret={$this->apiSecret}", [
'headers' => [
'Content-Type' => 'application/json'
],
'json' => $eventData
]);
if ($response->getStatusCode() !== 204) {
$this->logger->error('Firebase Analytics API returned non-204 status code', [
'status_code' => $response->getStatusCode(),
'response' => $response->getBody()->getContents()
]);
}
} catch (\Exception $e) {
$this->logger->error('Failed to send data to Firebase Analytics', [
'exception' => $e->getMessage(),
'trace' => $e->getTraceAsString()
]);
}
}
Postman 示例
{
"client_id": "12345",
"events": [
{
"name": "purchase_postman",
"params": {}
}
]
}
答: 暂无答案
评论