不重複觸及數評估

許多內容製作者和廣告主都想知道有多少不重複使用者觀看他們的內容。使用 Shared Storage 記錄使用者第一次看到廣告、嵌入的影片或發布內容,並避免在不同網站上重複計算同一使用者的次數。接著,您可以使用 Private Aggregation API 輸出觸及數摘要報表。

Shared Storage API 是一種 Privacy Sandbox 提案,可用於一般用途的跨網站儲存空間,支援多種可能的用途。Private Aggregation API 是 Shared Storage 中的輸出內容,可讓您匯總跨網站資料。如要進一步瞭解實作這些評估指標的方法,請參閱觸及數白皮書

試用不重複觸及評估

如要嘗試使用共用儲存空間和私密匯總功能進行不重複觸及數評估,請確認您使用的是 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 是共用儲存空間工作項,可檢查共用儲存空間中的標記,並使用 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 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 的想法。

掌握最新消息

  • 電子報:訂閱我們的電子報,即可取得與 Shared Storage API 相關的最新消息和公告。

需要協助嗎?