輪播廣告素材

使用共用儲存空間來判斷使用者在多個網站上看到的廣告素材。

Shared Storage API 是 Privacy Sandbox 提案之一,適用於一般用途的跨網站儲存空間。這個 API 支援許多可能的用途。舉例來說,在 Chrome 104.0.5086.0 以上版本中可以測試廣告素材輪播。

您可以利用廣告素材輪播來儲存資料 (例如廣告素材 ID、觀看次數和使用者互動),以決定使用者在不同網站中看到哪些廣告素材。

執行共用儲存空間工作小程式,根據儲存的資料從提供的清單中選取網址,然後在 Fenced 頁框中顯示該廣告素材。可用來選取新的廣告或其他內容。

試用廣告素材輪播

如要透過共用儲存空間體驗廣告素材輪播功能,請確認您目前使用的是 Chrome 104.0.5086.0 以上版本。接著,在 chrome://flags/#privacy-sandbox-ads-apis 中啟用 Privacy Sandbox Ads API 實驗旗標。

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

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

使用程式碼範例進行實驗

廣告客戶或內容製作人可能會想為廣告活動套用不同的策略,並透過輪播內容或廣告素材來提高成效。共用儲存空間可用於在不同網站上執行不同的旋轉策略,例如依序旋轉和平均分配。

在這個例子中:

  • creative-rotation.js 已嵌入在頁框中。這段指令碼會設定最重要的廣告 ( 粗細),並呼叫 Worklet 來決定要顯示哪些內容。
  • creative-rotation-worklet.js 是共用儲存工作小程式,可決定內容的加權分佈情形和傳回結果。

creative-rotation.js

// Ad config with the URL of the content, a probability weight for rotation, and the clickthrough rate.
const DEMO_CONTENT_CONFIG = [
  {
    url: 'https://your-server.example/contents/content-1.html',
    weight: 0.7,
  },
  {
    url: 'https://your-server.example/contents/content-2.html',
    weight: 0.2,
  },
  {
    url: 'https://your-server.example/contents/content-3.html',
    weight: 0.1,
  },
];

// Set the mode to sequential and set the starting index to 0.
async function seedStorage() {
  await window.sharedStorage.set('content-rotation-mode', 'sequential', {
    ignoreIfPresent: true,
  });

  await window.sharedStorage.set('content-rotation-index', 0, {
    ignoreIfPresent: true,
  });
}

async function injectAd() {
  // Load the worklet module
  await window.sharedStorage.worklet.addModule('content-rotation-worklet.js');

  // Initially set the storage to sequential mode for the demo
  seedStorage();

  // Run the URL selection operation to determine the next content rendered.
  const urls = DEMO_CONTENT_CONFIG.map(({ url }) => ({ url }));
  const fencedFrameConfig = await window.sharedStorage.selectURL('content-rotation', urls, { 
    data: DEMO_CONTENT_CONFIG,
    resolveToConfig: true
  });

  // Render the opaque URL into a fenced frame
  document.getElementById('content-slot').config = fencedFrameConfig;
}

injectAd();

creative-rotation-worklet.js

class SelectURLOperation {
  async run(urls, data) {
    // Read the rotation mode from Shared Storage
    const rotationMode = await this.sharedStorage.get('content-rotation-mode');

    // Generate a random number to be used for rotation
    const randomNumber = Math.random();

    let index;

    switch (rotationMode) {
      /**
       * Sequential rotation
       * - Rotates the contents in order
       * - Example: A -> B -> C -> A ...
       */
      case 'sequential':
        const currentIndex = await this.sharedStorage.get('creative-rotation-index');
        index = parseInt(currentIndex, 10);
        const nextIndex = (index + 1) % urls.length;

        await this.sharedStorage.set('content-rotation-index', nextIndex);
        break;

      /**
       * Weighted rotation
       * - Rotates the contentswith weighted probability
       * - Example: A=70% / B=20% / C=10%
       */
      case 'weighted-distribution':
        
        // Sum the weights cumulatively, and find the first URL where the
        // sum exceeds the random number. The array is sorted in
        // descending order first.
        let weightSum = 0;
        const { url } = data
          .sort((a, b) => b.weight - a.weight)
          .find(({ weight }) => {
            weightSum += weight;
            return weightSum > randomNumber;
          });

        index = urls.indexOf(url);
        break;

      default:
        index = 0;
    }
    return index;
  }
}

register('content-rotation', SelectURLOperation);

應用情境

以上只是其中一部分的共用儲存空間用途。在收到意見回饋及發掘新的用途的同時,我們會繼續新增範例。

內容篩選

根據在共用儲存空間中收集到的資訊,在圍欄頁框中選取及顯示不同網站上的不同內容。這些用途的輸出門檻是選取網址。

  • 廣告素材輪播:儲存資料 (例如廣告素材 ID、觀看次數和使用者互動),以判斷使用者會在各網站上看到哪些廣告素材。
  • A/B 測試:您可以將使用者指派給實驗群組,然後將該群組儲存在共用儲存空間中,方便跨網站存取。
  • 自訂使用者體驗:根據使用者的註冊狀態或其他使用者狀態,分享自訂內容和行動號召

產生摘要報表

使用「共用儲存空間」收集資訊,並產生雜訊的匯總報表。這些用途的輸出閘門是 Private Aggregation API

  • 不重複觸及率評估:許多內容製作者和廣告客戶會想瞭解有多少不重複觀眾看過他們的內容。使用 Shared Storage 可記錄使用者首次看見您的廣告、內嵌影片或出版品,並防止同一位使用者在不同網站上重複計算。接著,您可以使用 Private Aggregation API 輸出觸及率的摘要報表。
  • 客層評估:內容製作者通常會想瞭解觀眾的客層。您可以使用共用儲存空間,在您擁有的位置 (例如第一方網站) 記錄使用者客層資料,並使用匯總報表製作其他許多網站的報表,例如嵌入內容。
  • K+ 頻率評估:有時又稱為「有效頻率」,通常在使用者辨識或想起某些內容前,通常會需要觀看最低次數 (通常以廣告檢視畫面來說)。您可以使用共用儲存空間,針對曾看過內容片段超過 K 次的不重複使用者人數建立報表。

交流及分享意見回饋

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