迁移指南 (Chrome 92):Conversion Measurement API 到 Attribution Reporting API

Conversion Measurement API 在 Chrome 92 中发生变化。

Published on Updated on

Translated to: English, Español, Português, 한국어, Pусский, 日本語, Français, Deutsch

如果您在迁移过程中遇到问题或需要支持,请加入邮寄名单并提出您的问题。

有哪些变化?

随着 API 提案在 2021 年前几个月的变化,Chrome 中的 API 实现也在不断发展。下面是具体的变化:

  • API 名称和功能策略名称。
  • HTML 特性名称和 .well-known 网址。
  • 报告的格式。报告现在在请求正文中作为 JSON 发送。
  • 报告的内容:credit 以及本应为 0 信用的报告已被移除。

Chrome 92 中保持不变的是一组支持的功能:仅用于点击的事件级报告。期待这方面的更新。在此变化之后,其他更新和功能将在未来的 Chrome 版本中发布。

要接收有关此 API 的源站试用和即将推出的功能的动态,请订阅邮寄名单

这些更改何时生效?

这些更改从 2021 年 7 月 20 日达到稳定版的 Chrome 92 开始生效。Chrome 92 测试版于 2021 年 6 月 3 日发布。

您应该做什么?

未来版本中的 API 会有更多更改。它们将使用 Chrome 92 中采用的新命名方式。

如果您正在运行源站试用或为此 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 特性

旧代码新代码
conversiondestinationattributiondestination
impressiondataattributionsourceeventid
impressionexpiryattributionexpiry
reportingoriginattributionreportto

更新 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
Incoming reportsSent as URL parameters.Sent as JSON in the request body.

The report data is included in the request body as a JSON object with the following keys:
source_event_id:以前的 impression-data,在归因来源上设置的 64 位事件 ID。
trigger_data:以前的 conversion-data,特性触发器重定向中设置的 3 位数据。

⚠️ credit 已被移除。

Updated on 改进文章

This site uses cookies to deliver and enhance the quality of its services and to analyze traffic. If you agree, cookies are also used to serve advertising and to personalize the content and advertisements that you see. Learn more about our use of cookies.