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

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

有何变化?

遵循 API 提案的变更 在 2021 年头几个月,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:所有资源

请参阅 Attribution Reporting