有时也称为“有效频次”,通常需要达到最低观看次数,用户才能识别或回想某些内容(通常是在广告观看的背景下)。您可以使用共享存储空间生成报告,了解至少观看了某项内容 K 次的唯一身份用户。
Shared Storage API 是一项 Privacy Sandbox 提案,适用于通用的跨网站存储,支持许多可能的用例。Private Aggregation API 是 Shared Storage 中提供的一个输出,可让您汇总跨网站数据。
试用“覆盖 1,000 人次以上”频次衡量功能
如需使用共享存储空间和不公开汇总功能试用 K+ 频次衡量功能,请确认您使用的是 Chrome M107 或更高版本。启用 chrome://settings/adPrivacy
下的所有广告隐私权 API。
您还可以在命令行中使用 --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames
标志启用共享存储空间。
试验代码示例
您可能希望衡量在不同网站上,有多少用户在给定客户的广告中看到了您的内容至少 K 次。在此示例中,系统会将展示次数添加到共享存储空间,每次加载内容时,展示次数都会递增 1。当展示次数达到 3 次时,系统会调用 Private Aggregation API。内容 ID 维度编码为汇总键,计数用作可汇总的值。摘要报告将提供“大约有 391 位用户至少看过广告系列 ID 为 123 的广告 3 次”等信息。
在此示例中:
k-frequency-measurement.js
使用帧加载,负责加载共享存储工作容器。k-frequency-measurement-worklet.js
是 Shared Storage Worklet,用于读取 Shared Storage 中的展示次数,并使用 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();
kuency-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 just 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 sharedStorage.get(hasReportedContentKey)) === 'true';
const impressionCount = parseInt((await sharedStorage.get(impressionCountKey)) || 0);
// Don't report if a report has been sent already
if (hasReportedContent) {
return;
}
// Check impression count against frequency limit
if (impressionCount < kFreq) {
await 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 using the Private Aggregation API
privateAggregation.contributeToHistogram({ bucket, value });
// Set the report submission status flag
await sharedStorage.set(hasReportedContentKey, 'true');
}
}
// Register the operation
register('k-freq-measurement', KFreqMeasurementOperation); \
互动和分享反馈
请注意,Shared Storage API 提案正在积极讨论和开发中,因此可能会发生变化。
我们非常期待听到您对 Shared Storage API 的看法。
掌握最新动态
- 邮寄名单:订阅我们的邮寄名单,及时了解与 Shared Storage API 相关的最新动态和公告。
需要帮助?
- 开发者支持:在 Privacy Sandbox 开发者支持代码库中与其他开发者联系,并获取问题解答。