評估 K+ 頻率觸及

有時也稱為「有效展示頻率」,是指使用者認得或記得特定內容 (通常是廣告觀看次數) 之前,至少需要幾次幾次才認識或再次印象。您可以利用「共用儲存空間」為看過某項內容至少 K 次的不重複使用者建立報表,

Shared Storage API 是適用於一般用途的跨網站儲存空間 Privacy Sandbox 提案,可支援許多可能的用途。Private Aggregation API 是共用儲存空間中的輸出項目,可讓您匯總跨網站資料。

試用 K+ 頻率評估功能

如要使用共用儲存空間和私人匯總功能進行 K+ 頻率測量結果,請確認您使用的是 Chrome M107 以上版本。啟用 chrome://settings/adPrivacy 下的所有廣告隱私權 API。

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

使用程式碼範例進行實驗

建議您評估在各種網站上看過您內容 K 次以上特定客戶的次數。在這個範例中,曝光次數會併入共用儲存空間,內容載入時就會增加 1。當曝光次數達到 3 次時,系統會呼叫 Private Aggregation API。系統會將 Content ID 維度編碼為匯總鍵,並做為可匯總值使用。摘要報表會提供「大約 391 名使用者看過廣告活動 ID 123 至少 3 次」等資訊。

在這個例子中:

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

k-frequency-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 simply 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 this.sharedStorage.get(hasReportedContentKey)) === 'true';
    const impressionCount = parseInt((await this.sharedStorage.get(impressionCountKey)) || 0);

    // Do not report if a report has been sent already
    if (hasReportedContent) {
      return;
    }

    // Check impression count against frequency limit
    if (impressionCount < kFreq) {
      await this.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 via the Private Aggregation API
    privateAggregation.sendHistogramReport({ bucket, value });

    // Set the report submission status flag
    await this.sharedStorage.set(hasReportedContentKey, 'true');
  }
}

// Register the operation

register('k-freq-measurement', KFreqMeasurementOperation); \

交流及分享意見回饋

共用儲存空間提案仍在進行中的討論,日後可能會有變動。如果您試用這個 API,並有任何意見,歡迎與我們分享。