有时称为“有效频率”,即只有在观看次数达到最低次数时,用户才会识别或回想某些内容(通常在观看广告的情况下)。使用共享存储空间,您可以生成查看了一段内容至少 K 次的唯一身份用户的报告。
Shared Storage API 是 Privacy Sandbox 提案,用于实现通用的跨网站存储,它支持许多可能的使用场景。Private Aggregation API 是共享存储空间中提供的一种输出,可让您汇总跨网站数据。
尝试 K+ 频次衡量
若要尝试使用共享存储空间和不公开汇总功能来衡量 K+ 频次,请确认您使用的是 Chrome M107 或更高版本。然后,在 chrome://flags/#privacy-sandbox-ads-apis
处启用 Privacy Sandbox Ads API 实验标志。
您还可以在命令行中使用 --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames
标志启用共享存储空间。
使用代码示例进行实验
您可能想要衡量某个客户在不同网站上看到您内容 K 次(或 K 次以上)的用户数。在本例中,展示次数被添加到共享存储空间中,每当内容加载时,展示次数都会加 1。当展示次数达到 3 时,系统会调用 Private Aggregation API。Content ID 维度编码为汇总键,计数被用作可汇总值。摘要报告将提供诸如“大约 391 位用户已经看到广告系列 ID 123 至少 3 次”之类的信息。
在此示例中:
k-frequency-measurement.js
通过帧加载,并负责加载共享存储空间 Worklet。k-frequency-measurement-worklet.js
是一个共享存储空间 Worklet,它读取共享存储空间中的展示次数,并通过 Private Aggregation API 发送报告。
k-frequency-measurement.js
async function injectContent() {
// Load the Shared Storage worklet
await window.sharedStorage.worklet.addModule('k-freq-measurement-worklet.js');
// Run the K-frequency measurement operation
await window.sharedStorage.run('k-freq-measurement', { data: { kFreq: 3, contentId: 123 });
}
injectContent();
k-frequency-measurement-worklet.js
// Learn more about noise and scaling from the Private Aggregation fundamentals
// documentation on Chrome blog
const SCALE_FACTOR = 65536;
/**
* The bucket key must be a number, and in this case, it is simply the content
* ID itself. For more complex bucket key construction, see other use cases in
* this demo.
*/
function convertContentIdToBucket(contentId) {
return BigInt(contentId);
}
class KFreqMeasurementOperation {
async run(data) {
const { kFreq, contentId } = data;
// Read from Shared Storage
const hasReportedContentKey = 'has-reported-content';
const impressionCountKey = 'impression-count';
const hasReportedContent = (await this.sharedStorage.get(hasReportedContentKey)) === 'true';
const impressionCount = parseInt((await this.sharedStorage.get(impressionCountKey)) || 0);
// Do not report if a report has been sent already
if (hasReportedContent) {
return;
}
// Check impression count against frequency limit
if (impressionCount < kFreq) {
await this.sharedStorage.set(impressionCountKey, impressionCount + 1);
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(hasReportedContentKey, 'true');
}
}
// Register the operation
register('k-freq-measurement', KFreqMeasurementOperation); \
互动和分享反馈
共享存储空间提案正在积极讨论中,将来可能会发生变化。如果您在试用此 API 时有反馈意见,我们非常期待收到您的宝贵意见。
- GitHub:阅读提案、提出问题并参与讨论。
- Shared Storage API 公告:加入或查看我们在邮寄名单中的过往公告
- 开发者支持:在 Privacy Sandbox 开发者支持代码库中提问并加入讨论。