Measurement Protocol 用例
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
借助 Google Analytics Measurement Protocol,除了使用代码植入或 Firebase SDK 收集的数据之外,您还可以将离线数据发送到您的网站或应用数据流。
本指南介绍了常见的 Google Analytics Measurement Protocol 应用场景及其要求。
要求摘要
下表简要提供了每种应用场景的要求供您快速参考。请牢记以下最佳实践:
事件和用户属性的 timestamp_micros
默认为请求发生的时间。当发送过去发生的事件或用户属性变更时,请按照发送事件指南和用户属性指南中所述替换该时间戳。
为了确保实时报告和互动指标的准确性,请添加 engagement_time_msec
事件参数,并将其设置为自前一个事件以来经过的毫秒数。
使用场景 |
会话 ID |
请求时间要求 |
timestamp_micros 要求 |
将 User-ID 分配给事件 |
必需 |
<= 会话开始的工作日结束时间 |
>= 会话开始时间且 <= 会话结束时间 |
会话归因 |
必需 |
<= 会话开始时间 + 24 小时 |
>= 会话开始时间且 <= 会话结束时间 |
将事件导出到广告平台 |
不需要 |
<= 最后一个会话所在工作日 + 63 天 |
>= 请求时间减去两个工作日,且 <= 请求时间 |
发送事件或用户属性以创建受众群体 |
不需要
|
网站:<= 最新在线事件发生时间 + 30 天
应用:<= 最新在线事件发生时间 + 42 天 |
>= 请求时间减去两个工作日,且 <= 请求时间
|
将 User-ID 分配给事件
使用 Measurement Protocol 为线上或线下事件提供 User-ID。
以下是一些将 User-ID 添加到事件中的应用场景示例:
您的线上衡量缺少查找线上事件的用户 ID 所需的信息,但您有一个能够将线上会话与用户 ID 相关联的事件处理流水线。
在此方案中,您将使用 Measurement Protocol 提供包含 User-ID 的线上事件。
您通过 Measurement Protocol 发送的事件没有 User-ID,但您希望这些事件在用户在会话期间在线登录后与 User-ID 相关联。
在此方案中,您使用线上事件来提供带有 User-ID 的 Measurement Protocol 事件。
以下是将 User-ID 添加到事件的要求:
- 在事件的参数列表中添加
session_id
。
- 在同一工作日发送 Measurement Protocol 事件。
- 如果您要替换
timestamp_micros
,请将其设置为在线会话的开始时间和结束时间之间的时间戳。
- 如果您的目标是为线上活动提供 User-ID,请在请求中设置
user_id
。
- 如果您的目标是让每个 Measurement Protocol 事件都具有相应在线会话中的 User-ID,则无需设置
user_id
。
会话归因
符合特定要求的 Measurement Protocol 事件在报告中显示的会话属性(例如地理位置信息、来源、媒介和广告系列)与同一会话中的在线事件相同。
以下是会话归因的要求:
Google Analytics 会将您使用 Measurement Protocol 发送的事件纳入导出到关联的广告产品(例如 Google Ads 或 Campaign Manager 360)的数据中。
以下是一些常见的使用场景:
- 您的商家有线下活动,您希望将其纳入广告归因和报告中。
- 您在某个系统中还有其他事件,但这些事件无法通过代码植入或 Firebase SDK 来获取,不过您仍想将这些事件纳入关联的产品中。
以下是将事件导出到广告平台的要求:
即使关键事件的归因时间范围超过 63 天,也请务必在最新在线事件发生后 63 天内(以工作日结束时间为准)发送请求。
例如,如果 client_id
或 app_instance_id
的最新在线事件发生在 3 月 1 日,请在 5 月 3 日营业日结束之前发送 Measurement Protocol 事件。
如果您替换 timestamp_micros
,请将其设置为过去三个工作日内的某个时间戳。
发送事件或用户属性以创建受众群体
如果您遵循一些要求,则使用 Measurement Protocol 发送的事件和用户属性会纳入受众群体条件的评估范围。
以下是发送事件或用户属性以创建受众群体的要求:
在同一 client_id
的最新在线事件发生后 30 天内(最晚在当天营业结束前),将请求发送到 Web 数据流。
例如,如果 client_id
的最新在线事件发生在 3 月 1 日,请在 3 月 31 日营业日结束之前发送 Measurement Protocol 事件。
在同一 app_instance_id
的最新在线活动发生后的 42 天内(不得晚于该工作日结束时),将请求发送到应用数据流。
例如,如果 app_instance_id
的最新在线事件发生在 3 月 1 日,请在 4 月 12 日营业日结束之前发送 Measurement Protocol 事件。
如果您要替换 timestamp_micros
,请将其设置为过去 3 个工作日内的时间戳。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-29。
[null,null,["最后更新时间 (UTC):2025-07-29。"],[[["\u003cp\u003eThe Google Analytics Measurement Protocol allows you to send offline data, supplementing your existing online data collection.\u003c/p\u003e\n"],["\u003cp\u003eThis protocol enables you to assign User IDs to events, attribute sessions, export events for advertising, and leverage data for audience creation within Google Analytics.\u003c/p\u003e\n"],["\u003cp\u003eSpecific requirements, including session IDs and timestamps, must be met for each use case to ensure data accuracy and integration with online data.\u003c/p\u003e\n"],["\u003cp\u003eRefer to the provided tables and guidelines for detailed requirements and best practices for each use case, such as session attribution and audience creation.\u003c/p\u003e\n"],["\u003cp\u003eAdhering to these guidelines ensures accurate reporting, attribution, and audience creation based on both online and offline data within your Google Analytics property.\u003c/p\u003e\n"]]],["The Google Analytics Measurement Protocol allows sending offline data to web or app streams. Key actions include: assigning User-IDs to events (requiring a `session_id`, same-day processing, and specific `timestamp_micros`), attributing sessions (requiring `session_id` and submission within 24 hours of session start), exporting events to advertising platforms (no `session_id` required, must be sent within 63 days of the last online event), and using data for audience creation (no `session_id`, web data must be sent within 30 days and app data within 42 days of the last event).\n"],null,["# Measurement protocol use cases\n\nThe Google Analytics Measurement Protocol lets you send offline data to your Web or App stream, in\naddition to the data you're already collecting with tagging or the Firebase SDK.\n\nThis guide describes common Google Analytics Measurement Protocol use cases and their requirements.\n| **Key Term:** In this guide, \"business day\" is the business day of an event or session in the [time zone of your property](//support.google.com/adsense/answer/9830725).\n\nSummary of requirements\n-----------------------\n\nThis table provides a quick reference of the requirements for each use\ncase. Keep the following best practices in mind:\n\n1. The `timestamp_micros` of events and user properties defaults to the request\n time. When sending an event or user property change that occurred in the\n past, override the timestamp as described in the [sending events](/analytics/devguides/collection/protocol/ga4/sending-events) guide and\n the [user properties](/analytics/devguides/collection/protocol/ga4/user-properties) guide.\n\n2. For accurate Realtime reports and engagement metrics, include the\n `engagement_time_msec` event parameter set to the milliseconds elapsed since\n the preceding event.\n\n| Use case | Session ID | Request time requirement | `timestamp_micros` requirement |\n|------------------------------------------------------|--------------|-----------------------------------------------------------------------------------------|---------------------------------------------------------------|\n| Assign User-ID to events | Required | \\\u003c= end of the session start's business day | \\\u003e= session start and \\\u003c= session end |\n| Session attribution | Required | \\\u003c= session start + 24 hours | \\\u003e= session start and \\\u003c= session end |\n| Export events to advertising platforms | Not required | \\\u003c= last session business day + 63 days | \\\u003e= request time minus two business days and \\\u003c= request time |\n| Send events or user properties for audience creation | Not required | Web: \\\u003c= latest online event time + 30 days App: \\\u003c= latest online event time + 42 days | \\\u003e= request time minus two business days and \\\u003c= request time |\n\nAssign User-ID to events\n------------------------\n\nUse the Measurement Protocol to provide online or offline events with a\n[User-ID](//support.google.com/analytics/answer/9213390).\n\nHere are some example use cases for adding a User-ID to an event:\n\n1. Your online measurement lacks the information needed to look up the\n User-ID for online events, but you have an event-processing pipeline that\n is able to make the association between an online session and a User-ID.\n\n In this scenario, you are using the Measurement Protocol to provide\n *online* events with a User-ID.\n2. You don't have the User-ID for events you are sending with the\n Measurement Protocol, but you want those events to be associated with a\n User-ID if the user logged in online over the course of the session.\n\n In this scenario, you are using online events to provide\n *Measurement Protocol* events with a User-ID.\n\nHere are the requirements to add a User-ID to an event:\n\n- Include the `session_id` in the event's parameter list.\n- Send the Measurement Protocol events on the *same business day* as the online session.\n- If you override `timestamp_micros`, set it to a timestamp between the start and end time of the online session.\n- If your goal is to provide User-ID for online events, set the `user_id` in the request.\n- If your goal is for each Measurement Protocol event to have the User-ID from its corresponding online session, you don't need to set `user_id`.\n\nSession attribution\n-------------------\n\nMeasurement Protocol events that meet specific requirements appear in reports\nwith the same session attributes (such as geographic information, source,\nmedium, and campaign) as online events from the same session.\n\nHere are the requirements for session attribution:\n\n- Include the `session_id` in the event's parameter list.\n- Send the request no later than 24 hours after the start of the online\n session.\n\n For example, if the session started at 11:15 AM on Monday in your property's\n time zone, send the request before 11:15 AM on Tuesday.\n- If you override `timestamp_micros`, set it to a timestamp between the\n start and end time of the online session.\n\nExport events to advertising platforms\n--------------------------------------\n\nGoogle Analytics includes the events you send using Measurement Protocol\nin exports to linked advertising products such as Google Ads or Campaign Manager\n360.\n| **Tip:** This use case doesn't require `session_id`.\n\nA few common scenarios where this is useful include:\n\n- Your business has offline events that you want included in advertising attribution and reporting.\n- You have additional events in a system that is not available to tagging or the Firebase SDK, but you still want to include those events in linked products.\n\nHere are the requirements to export events to advertising platforms:\n\n- Send the request no later than the end of the business day 63 days after\n the latest online event, even if the key event's attribution window is more\n than 63 days.\n\n For example, if the latest online event for the `client_id` or\n `app_instance_id` occurred on March 1, send the Measurement Protocol\n event no later than the end of the business day on May 3.\n- If you override `timestamp_micros`, set it to a timestamp within the last\n three business days.\n\nSend events or user properties for audience creation\n----------------------------------------------------\n\nEvents and user properties sent using Measurement Protocol are included in\nthe evaluation of [audience conditions](//support.google.com/analytics/answer/9267572) if you adhere to a few requirements.\n| **Tip:** This use case doesn't require `session_id`.\n\nHere are the requirements to send events or user properties for audience\ncreation:\n\n- Send the request to a Web stream no later than the end of the business day\n 30 days after the latest online event for the same `client_id`.\n\n For example, if the latest online event for the `client_id` occurred on\n March 1, send the Measurement Protocol event no later than the end of the\n business day on March 31.\n- Send the request to an App stream no later than the end of the business day\n 42 days after the latest online event for the same `app_instance_id`.\n\n For example, if the latest online event for the `app_instance_id` occurred\n on March 1, send the Measurement Protocol event no later than the end of\n the business day on April 12.\n- If you override `timestamp_micros`, set it to a timestamp within the last 3\n business days."]]