不重複觸及數評估

許多內容製作者和廣告客戶都想知道有多少不重複使用者收看自家內容。使用「共用儲存空間」記錄使用者首次看到你的廣告、內嵌影片或出版品時,避免重複計算同一使用者在不同網站上的重複內容。然後,您可以使用 Private Aggregation API 輸出摘要報表,以呈現觸及率。

Shared Storage API 是 Privacy Sandbox 提案之一,適用於一般用途的跨網站儲存空間。這個 API 支援許多可能的用途。Private Aggregation API 是「共用儲存空間」提供的輸出內容,可讓您匯總跨網站資料。

試用不重複觸及評估功能

如要試用不重複觸及率評估功能,並採用共用儲存空間和私人匯總功能,請確認您目前使用的是 Chrome M107 以上版本。接著,在 chrome://flags/#privacy-sandbox-ads-apis 中啟用 Privacy Sandbox Ads API 實驗旗標。

將 Privacy Sandbox Ads API 實驗設為啟用以使用這些 API

您也可以在指令列中使用 --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames 旗標啟用「共用儲存空間」。

使用程式碼範例進行實驗

你可能會想追蹤有多少不重複使用者在不同網站上看過你的內容。在這個範例中,內容 ID 維度已編碼為匯總鍵 (值區),並使用計數做為可匯總的值。摘要報告將包含「約有 391 位使用者看過 Content ID 123」等資訊。

在此範例中: * unique-reach-measurement.js 是透過框架載入,並負責載入共用儲存空間小程式。 * unique-reach-measurement-worklet.js 是一個共用儲存空間工作小程式,可用來檢查共用儲存空間中的旗標,並透過 Private Aggregation API 傳送報表。

reach-measurement.js

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();

reach-measurement-worklet.js

// 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,並有任何意見,歡迎與我們分享。