字段映射

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

请求字段

/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 格式的值。
  • 如果使用 Protocol Buffers,请使用 Timestamp 并设置 seconds 和(可选)nanoseconds 字段。

如需了解详情,请参阅时间戳格式
user_properties events.user_properties 设置为 UserProperties 对象。Data Manager API 不支持为各个用户属性设置时间戳。与用户属性更改相关联的时间戳是从事件的时间戳 (event_timestamp) 推断出来的。
user_data events.user_data 设置为 UserData 对象。如需了解详情,请参阅用户标识符字段
non_personalized_ads events.consent.ad_personalization 如果 non_personalized_adstrue,请将 ad_personalization 设置为 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_idfirebase_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 浏览器生成的,请设置为 WEB;如果事件是从应用生成的,请设置为 APP
无对应字段 destination_references 如果请求级层 destinations 列表包含多个 Google Analytics Destination,则此字段为必填字段。添加条目以指定哪个目标应接收事件。
timestamp_micros event_timestamp
  • 如果使用 JSON 格式,请设置为 RFC 3339 格式的值。
  • 如果使用 Protocol Buffers,请使用 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_namevalue 的对象列表。

注意:请勿在此处添加 transaction_idcurrencyvalue 的条目;请改用 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 无对应字段 Data Manager API 的当前版本不支持此字段。
address[].region 无对应字段 Data Manager API 的当前版本不支持此字段。
address[].sha256_street 无对应字段 Data Manager API 的当前版本不支持此字段。

购物车数据的商品字段

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

将其他商品参数(例如 discountaffiliationitem_brand 等)映射为包含 parameter_namevalue 的对象列表。

注意 :请勿在此处添加 quantitypriceitem_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_heightscreen_width 在 Measurement Protocol 中,screen_resolution 以字符串形式提供 ("1280x720")。在 Data Manager API 中,请将 screen_heightscreen_width 作为单独的整数值发送。
operating_system operating_system
operating_system_version operating_system_version
model model
brand brand
browser browser
browser_version browser_version