[已弃用] 迁移指南 (Chrome 92):Conversion Measurement API 到 Attribution Reporting API

Chrome 92 中的 Conversion Measurement API 将发生变化。

有何变化?

根据 2021 年前几个月的 API 提案变更,Chrome 中的 API 实现正在不断发展。具体更改内容如下:

  • API 名称和权限政策名称。
  • HTML 属性名称和 .well-known 网址。
  • 报告的格式。现在,报告以 JSON 格式在请求正文中发送。
  • 报告的内容:credit 已被移除,同时移除了本应获得 0 积分的报告。

Chrome 92 中保持不变的是支持的功能集:仅针对点击的事件级报告。敬请关注相关更新。此更改生效后,其他更新和功能将在未来的 Chrome 版本中发布。

这些更改何时生效?

这些变更自 Chrome 92(于 2021 年 7 月 20 日发布稳定版)起生效。 Chrome 92 Beta 版于 2021 年 6 月 3 日发布。

您该怎么做?

如果您正在运行源试用或已为此 API 实现演示,则有两种选择:

  • 方案 1(推荐):立即或在未来几周内迁移代码,最好在 2021 年 7 月中旬之前完成。这样一来,您的代码库将为未来的变化做好准备,并能继续适用于较新的 Chrome 客户端。
  • 方法 2:等待未来 Chrome 版本中发布更多更新和功能,然后一次性完成所有必要的代码更改。

迁移

示例迁移

您可以在此拉取请求(草稿)中查看小型演示应用的迁移示例。

更新权限政策代码

旧版代码 新验证码
allow='conversion-measurement' allow='attribution-reporting'

更新功能检测代码

旧版代码 新验证码
document.featurePolicy.features()
.includes('conversion-measurement')
document.featurePolicy.features()
.includes('attribution-reporting')

更新 HTML 属性

旧版代码 新验证码
conversiondestination attributiondestination
impressiondata attributionsourceeventid
impressionexpiry attributionexpiry
reportingorigin attributionreportto

更新了 window.open() 个实参

可以为由 window.open() 发起的导航注册归因来源。如果您使用 window.open() 注册归因来源,请更新这些调用。

新代码应如下所示(此重命名遵循 HTML 属性重命名):

window.open(
  'https://dest.example',
  '_blank',
  'attributionsourceeventid=1234,attributiondestination=https://dest.example,attributionreportto=https://reporter.example,attributionexpiry=604800000'
);

更新注册回调网址和参数

旧版代码 新验证码
.well-known/register-conversion?conversion-data={DATA} .well-known/attribution-reporting/trigger-attribution?trigger-data={DATA}

更新报告端点代码

旧版代码 新验证码
浏览器会发送哪些请求 .well-known/register-conversion?impression-data=&conversion-data={DATA}&attribution-credit=100 .well-known/attribution-reporting/trigger-attribution
收到的报告 以网址参数的形式发送。 以 JSON 格式在请求正文中发送。

报告数据包含在请求正文中,以 JSON 对象的形式呈现,并包含以下键:
source_event_id:之前为 impression-data,在归因来源上设置的 64 位事件 ID。
trigger_data:以前称为 conversion-data,归因触发重定向中的 3 位数据集。

⚠️ credit 已移除。

Attribution Reporting:所有资源

请参阅归因报告