字段映射

使用表格中的映射,将 Measurement Protocol 数据收集 请求 (/mp/collect) 映射到 Data Manager API 中等效的 IngestEventsRequest 。

身份验证

Data Manager API 需要 OAuth 凭据,而不是 api_secret。按照 设置 API 访问权限中的步骤 生成包含 Data Manager API 范围的新凭据。

请求字段

/mp/collect 请求 (Measurement Protocol) IngestEventsRequest (Data Manager API) 备注
measurement_id(查询参数) destinations 对于网站事件 ,映射到 product_destination_id。如需了解详情,请参阅目标字段。
firebase_app_id(查询参数) destinations 对于应用事件 ,映射到 product_destination_id。如需了解详情,请参阅目标字段。
api_secret(查询参数) 无对应报告 如需了解如何在 Data Manager API 中对请求进行身份验证,请参阅设置 API 访问权限
consent consent 设置为 Consent 对象。
events events 设置为 Event 资源列表。如需了解详情,请参阅事件字段部分。
client_id events.client_id 对于网站事件 ,这是必需字段。
app_instance_id events.app_instance_id 对于应用事件 ,这是必需字段。
user_id events.user_id 可选。用户的唯一标识符。
timestamp_micros events.event_timestamp 在 Measurement Protocol 中,可以在请求级别或针对单个事件提供此字段。在 Data Manager API 中,没有请求级时间戳。将每个事件的 event_timestamp 设置为事件发生的时间。
  • 如果使用 JSON 格式,请设置为 RFC 3339 格式的值。
  • 如果使用协议缓冲区,请使用 Timestamp 并设置 seconds 和(可选)nanoseconds 字段。

如需了解详情,请参阅时间戳格式。
user_properties events.user_properties

设置为 UserProperties 对象。如果要发送用户的类型或值存储桶,请分别使用 UserProperties 的 customer_type 或 customer_value_bucket 字段。对于其他用户属性,请创建一个单独的 UserProperty 对象,设置其 property_name 和 value 字段,并将其添加到 additional_user_properties 列表中。

Data Manager API 不支持为单个用户属性设置时间戳。与用户属性更改相关联的时间戳是从事件的时间戳 (event_timestamp) 推断出来的。

user_data events.user_data 设置为 UserData 对象。如需了解详情,请参阅用户标识符字段。
non_personalized_ads events.consent.ad_personalization 如果 non_personalized_ads 为 true,请将 ad_personalization 设置为 CONSENT_DENIED。
user_location events.event_location 如需了解详情,请参阅用户位置字段。
ip_override events.event_device_info.ip_address
device events.event_device_info 如需了解详情,请参阅设备字段。
user_agent events.event_device_info.user_agent
validation_behavior 无对应报告 使用 Diagnostics 检索上传的状态,以及下游处理期间单个事件的错误和警告。如果 IngestEventsRequest 失败(例如,由于缺少必填字段),则不会处理任何事件,您需要解决错误并重试请求。如需了解详情,请参阅了解 API 错误。
/debug/mp/collect validate_only 将 validate_only 设置为 true 以验证事件,而无需接收任何数据,这与 Measurement Protocol 验证服务器 类似。
无对应报告 encoding 上传 UserData 时,这是必需字段。设置为用于 UserIdentifier 值的 Encoding。

目标字段

Measurement Protocol 使用 measurement_id 或 firebase_app_id 查询参数将事件直接发送到特定数据流。

Data Manager API 使用 Destination 对象指定要将数据发送到何处。 如需详细了解目标,请参阅配置目标。

下面介绍了如何将 Measurement Protocol 字段映射到 Destination 中的等效字段:

Measurement Protocol Destination (Data Manager API) 备注
measurement_id(查询参数) product_destination_id 设置为 Google Analytics 网站数据流 的衡量 ID
firebase_app_id(查询参数) product_destination_id 设置为 Google Analytics 应用数据流 的 Firebase 应用 ID
无对应报告 operating_account 将 account_id 设置为 Google Analytics 媒体资源 ID。将 account_type 设置为 GOOGLE_ANALYTICS_PROPERTY。
无对应报告 login_account 将 account_id 设置为 Google Analytics 媒体资源 ID。将 account_type 设置为 GOOGLE_ANALYTICS_PROPERTY。

事件字段

Measurement Protocol events[] Event (Data Manager API) 备注
name event_name 如果 event_name 使用 保留名称,API 会拒绝该事件并返回 INVALID_EVENT_NAME 错误。
无对应报告 event_source 如果事件是从网络浏览器生成的,请设置为 WEB;如果事件是从应用生成的,请设置为 APP。
无对应报告 destination_references 如果请求级 destinations 列表包含多个 Google Analytics Destination,则这是必需字段。添加一个条目以指定哪个目标应接收事件。
timestamp_micros event_timestamp
  • 如果使用 JSON 格式,请设置为 RFC 3339 格式的值。
  • 如果使用协议缓冲区,请使用 Timestamp 并设置 seconds 和(可选)nanoseconds 字段。

如需了解详情,请参阅时间戳格式。
params.currency currency
params.value conversion_value
params.customer_type user_properties.customer_type 在 Measurement Protocol 中,customer_type 参数设置为事件参数。在 Data Manager API 中,请在事件的 UserProperties 对象中的 customer_type 字段中进行设置。
params.transaction_id transaction_id 对于某些事件和用例,这是必需字段 。如需了解详情,请参阅将数据转换为 Event 对象。
params.items cart_data.items 如需了解详情,请参阅购物车数据的商品字段。
params.coupon cart_data.coupon_codes 使用 coupon_codes 字段提供应用于购物车的优惠券。仅为 Google Analytics 提供一张优惠券。这与 Item 级优惠券无关,后者可以使用 cart_data.items.additional_item_parameters 为单个商品设置。
params.session_id additional_event_parameters 映射到 parameter_name 设置为 session_id 的条目。
params.engagement_time_msec additional_event_parameters 映射到 parameter_name 设置为 engagement_time_msec 的条目。
其他 params additional_event_parameters

将其他参数映射为包含 parameter_name 和 value 的对象列表。

注意:请勿在此处添加 transaction_id、 currency 或 value 的条目;请改用 Event 中的顶级字段。

用户标识符字段

Measurement Protocol user_data UserIdentifier (Data Manager API) 备注
sha256_email_address[] email_address 设置为格式化和哈希处理后的电子邮件地址。您还可以加密哈希处理后的电子邮件地址。
sha256_phone_number[] phone_number 设置为格式化和哈希处理后的电话号码。您还可以加密哈希处理后的电话号码。
address[] address 设置为 AddressInfo 对象。请遵循格式设置和哈希处理准则。
address[].sha256_first_name address.given_name 设置为格式化和哈希处理后的名字。您还可以加密哈希处理后的名字。
address[].sha256_last_name address.family_name 设置为格式化和哈希处理后的姓氏。您还可以加密哈希处理后的姓氏。
address[].country address.region_code
address[].postal_code address.postal_code
address[].city address.city 设置为规范化后的城市。请勿对该字段进行哈希处理。
address[].region address.administrative_area 设置为规范化后的行政区域(州或省)。请勿对该字段进行哈希处理。
address[].sha256_street address.address_line 设置为格式化和哈希处理后的街道地址。您还可以加密哈希处理后的街道地址。

购物车数据的商品字段

Measurement Protocol items[] Item (Data Manager API) 备注
item_id item_id 必需 。
item_name additional_item_parameters 映射到 parameter_name 设置为 item_name 的条目。
quantity quantity 必需 。
price unit_price 必需 。
其他商品字段 additional_item_parameters

将其他商品参数(例如 discount、affiliation、item_brand 等)映射为包含 parameter_name 和 value 的对象列表。

注意 :请勿在此处添加 quantity、price 或 item_id 的条目;请改用 Item 中的顶级字段。

用户位置字段

Measurement Protocol user_location EventLocation (Data Manager API) 备注
city city 事件发生的城市名称。
country_id region_code 设置为 2 个字母的 CLDR 地区代码。
region_id subdivision_code 设置为 ISO 3166-2 分区代码。
continent_id continent_code 设置为 联合国 M49 格式 的大陆代码。
subcontinent_id subcontinent_code 设置为 联合国 M49 格式 的次大陆代码。

设备字段

Measurement Protocol device DeviceInfo (Data Manager API) 备注
category category
language language_code
screen_resolution screen_height 和 screen_width 在 Measurement Protocol 中,screen_resolution 以字符串形式提供 ("1280x720")。在 Data Manager API 中,请将 screen_height 和 screen_width 作为单独的整数值发送。
operating_system operating_system
operating_system_version operating_system_version
model model
brand brand
browser browser
browser_version browser_version