许多内容制作者和广告客户都想知道有多少唯一身份用户看过他们的内容。使用共享存储空间来记录用户首次看到您的广告、嵌入的视频或出版物,以防止将同一用户重复计入不同的网站。然后,您可以使用 Private Aggregation API 输出有关覆盖面的摘要报告。
Shared Storage API 是 Privacy Sandbox 提案,用于实现通用的跨网站存储,它支持许多可能的使用场景。Private Aggregation API 是共享存储空间中提供的一种输出,可让您汇总跨网站数据。
试用唯一身份用户覆盖面衡量功能
若要尝试使用共享存储空间和不公开汇总功能衡量唯一身份用户覆盖面,请确认您使用的是 Chrome M107 或更高版本。然后,在 chrome://flags/#privacy-sandbox-ads-apis
处启用 Privacy Sandbox Ads API 实验标志。
您还可以在命令行中使用 --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames
标志启用共享存储空间。
使用代码示例进行实验
您可能希望跟踪在不同的网站上查看了您的内容的唯一身份用户数。在此示例中,Content ID 维度编码到汇总键(存储分区)中,计数被用作可汇总值。摘要报告将包含“大约 391 位用户看过 Content ID 123”等信息。
在此示例中:
* unique-reach-measurement.js
通过帧加载,并负责加载共享存储空间 Worklet。
* unique-reach-measurement-worklet.js
是一个共享存储空间 Worklet,用于检查共享存储空间中的标记,并通过 Private Aggregation API 发送报告。
async function measureUniqueReach() {
// Load the Shared Storage worklet
await window.sharedStorage.worklet.addModule('reach-measurement-worklet.js');
// Run the reach measurement operation
await window.sharedStorage.run('reach-measurement', { data: { contentId: '1234' } });
}
measureUniqueReach();
// Learn more about noise and scaling from the Private Aggregation fundamentals
// documentation on Chrome blog
const SCALE_FACTOR = 65536;
function convertContentIdToBucket(contentId) {
return BigInt(contentId);
}
class ReachMeasurementOperation {
async run(data) {
const { contentId } = data;
// Read from Shared Storage
const key = 'has-reported-content';
const hasReportedContent = (await this.sharedStorage.get(key)) === 'true';
// Do not report if a report has been sent already
if (hasReportedContent) {
return;
}
// Generate the aggregation key and the aggregatable value
const bucket = convertContentIdToBucket(contentId);
const value = 1 * SCALE_FACTOR;
// Send an aggregatable report via the Private Aggregation API
privateAggregation.sendHistogramReport({ bucket, value });
// Set the report submission status flag
await this.sharedStorage.set(key, true);
}
}
// Register the operation
register('reach-measurement', ReachMeasurementOperation);
互动和分享反馈
共享存储空间提案正在积极讨论中,将来可能会发生变化。如果您在试用此 API 时有反馈意见,我们非常期待收到您的宝贵意见。
- GitHub:阅读提案、提出问题并参与讨论。
- Shared Storage API 公告:加入或查看我们在邮寄名单中的过往公告
- 开发者支持:在 Privacy Sandbox 开发者支持代码库中提问并加入讨论。