许多内容制作者和广告客户都希望了解有多少唯一身份用户看到了他们的内容。使用共享存储空间可记录用户首次看到您的广告、嵌入式视频或发布内容的时间,并防止在不同网站上重复统计同一用户。然后,您可以使用 Private Aggregation API 输出覆盖面摘要报告。
Shared Storage API 是一项 Privacy Sandbox 提案,适用于通用的跨网站存储,支持许多可能的用例。Private Aggregation API 是 Shared Storage 中提供的一个输出,可让您汇总跨网站数据。如需详细了解实现这些衡量的方法,请参阅我们的覆盖面白皮书。
试用唯一身份用户覆盖面衡量功能
如需通过 Shared Storage 和 Private Aggregation 衡量唯一覆盖面,请确认您使用的是 Chrome M107 或更高版本。启用 chrome://settings/adPrivacy 下的所有广告隐私权 API。
您还可以在命令行中使用 --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames 标志启用共享存储空间。
试验代码示例
您可能需要跟踪在不同网站上看到过您内容的唯一身份用户数。在此示例中,内容 ID 维度会编码到汇总键(分桶)中,而计数则用作可汇总的值。摘要报告将包含“大约有 391 位用户观看了内容 ID 123”等信息。
在此示例中:
unique-reach-measurement.js使用帧加载,并负责加载共享存储工作容器。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 sharedStorage.get(key)) === 'true';
    // Don't 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 using the Private Aggregation API
    privateAggregation.contributeToHistogram({ bucket, value });
    // Set the report submission status flag
    await sharedStorage.set(key, true);
  }
}
// Register the operation
register('reach-measurement', ReachMeasurementOperation);
互动并分享反馈
请注意,Shared Storage API 提案正在积极讨论和制作中,因此可能会发生变化。
我们非常期待您对 Shared Storage API 的看法。