有时也称为“有效频次”,是指用户在识别或回忆起特定内容(通常是指广告观看)之前需要观看的最低次数。您可以使用共享存储空间来生成报告,其中包含至少 K 次看到某内容的不重复用户。
Shared Storage API 是一项 Privacy Sandbox 提案,旨在提供通用的跨网站存储空间,支持许多可能的用例。Private Aggregation API 是 Shared Storage 中提供的一种输出,可用于汇总跨网站数据。
尝试 K+ 频次衡量
如需使用共享存储空间和 Private Aggregation 实验 K+ 频次衡量,请确认您使用的是 Chrome M107 或更高版本。启用 chrome://settings/adPrivacy 下的所有广告隐私权 API。
您还可以在命令行中使用 --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames 标志启用共享存储空间。
试用代码示例
您可能希望衡量在不同网站上,特定客户看到您的内容 K 次或更多次的用户数量。在此示例中,展示次数会添加到共享存储空间,并且每次加载内容时都会递增 1。当展示次数达到 3 时,系统会调用 Private Aggregation API。内容 ID 维度编码为汇总键,而观看次数用作可汇总的值。摘要报告将提供如下信息:“大约有 391 位用户至少 3 次看到了广告系列 ID 为 123 的广告系列。”
在此示例中:
k-frequency-measurement.js使用框架加载,负责加载共享存储区 worklet。k-frequency-measurement-worklet.js是一个共享存储区工作程序,用于读取共享存储区中的展示次数,并使用 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 的看法。