完成驗證事件後,請驗證導入狀態。驗證伺服器會驗證事件結構是否正確,但如要確認事件是否正確傳送至資源,請按照下列步驟操作:
如果完成上述步驟後仍未看到事件,請參閱疑難排解,瞭解常見的導入錯誤。
從用戶端傳送事件
選擇用戶端:
如要讓事件有效,必須有 app_instance_id
,且該 app_instance_id
已用於從 Google Analytics for Firebase SDK 傳送事件。在用戶端擷取這個 ID,並納入對 Measurement Protocol 的呼叫中。在將事件傳送至資源中,我們使用 "app_instance_id"
做為 app_instance_id
。您需要將這個值換成 SDK 提供的實際 app_instance_id
。請參閱「您是否使用正確的 app_instance_id」,瞭解如何確認您使用的是有效值。
將事件傳送至資源
從用戶端傳送事件並擷取有效 app_instance_id
後,即可使用 Measurement Protocol 傳送事件。驗證導入作業時,請使用 Measurement Protocol 傳送您要評估的確切事件。
舉例來說,下列程式碼會傳送 refund 事件:
const firebaseAppId = "FIREBASE_APP_ID";
const apiSecret = "API_SECRET";
fetch(`https://www.google-analytics.com/mp/collect?firebase_app_id=${firebaseAppId}&api_secret=${apiSecret}`, {
method: "POST",
body: JSON.stringify({
"app_instance_id": "APP_INSTANCE_ID",
"events": [{
"name": "refund",
"params": {
"currency": "USD",
"value": "9.99",
"transaction_id": "ABC-123"
}
}]
})
});
查看即時檢視畫面
使用 Measurement Protocol 傳送事件後,請查看資源的「即時」檢視畫面。事件通常會在幾秒內顯示。
開啟 Google Analytics,然後依序前往左側導覽面板中的「報表」 >「即時」,即可查看即時檢視畫面。您應著重於底部的圖表,例如「按事件名稱劃分的事件數」和「按事件名稱劃分的重要事件」。
查看 DebugView
如果即時檢視畫面提供的詳細資料不足,無法驗證導入作業,請在某些測試事件中啟用偵錯模式,方法是在 params
集合中加入下列參數,以便在 DebugView 中監控及查看事件:
"debug_mode": true
或"debug_mode": 1
"engagement_time_msec"
設為正數
舉例來說,下列程式碼會傳送 refund,並啟用偵錯模式:
const firebase_app_id = "FIREBASE_APP_ID";
const apiSecret = "API_SECRET";
fetch(`https://www.google-analytics.com/mp/collect?firebase_app_id=${firebaseAppId}&api_secret=${apiSecret}`, {
method: "POST",
body: JSON.stringify({
"app_instance_id": "APP_INSTANCE_ID",
"events": [{
"name": "refund",
"params": {
"currency": "USD",
"value": "9.99",
"transaction_id": "ABC-123",
"engagement_time_msec": 1200,
"debug_mode": true
}
}]
})
});
啟用偵錯模式並傳送事件後,請按照使用 DebugView 監控事件的操作說明,驗證實作項目。