フリークエンシーでクリエイティブを選択する

共有ストレージ ワークレットを実行して URL を選択し、フェンス付きフレームでレンダリングします。

Shared Storage API は、汎用のクロスサイト ストレージ向けのプライバシー サンドボックスの提案で、多くのユースケースに対応しています。一例として周波数制御があります。これは Chrome ベータ版 104.0.5086.0 以降でテストできます。

ワークレット スクリプトを実行して、保存されているデータに基づいて指定されたリストから URL を選択し、その URL をフェンス付きのフレームにレンダリングします。フリークエンシーの上限に達した際に、新しい広告やその他のコンテンツを選択する際に使用できます。

フリークエンシー別のクリエイティブの選択をテスト

共有ストレージとフェンス付きフレームで頻度によるクリエイティブの選択をテストするには、Chrome 104.0.5086.0 以降を使用していることを確認してください。chrome://settings/adPrivacy で、すべての広告プライバシー API を有効にします。

コマンドラインで --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames フラグを使用して共有ストレージを有効にすることもできます。

コードサンプルでテストする

不透明な URL を選択して作成するには、共有ストレージ データを読み取るワークレット モジュールを登録します。ワークレット クラスは、最大 8 つの URL のリストを受け取り、選択された URL のインデックスを返します。

クライアントが sharedStorage.selectURL() を呼び出すと、ワークレットが実行されて、フェンス付きフレームにレンダリングされる不透明な URL が返されます。

たとえば、ユーザーがこれまでに見た頻度に応じて、別の広告やコンテンツを選択してレンダリングするとします。ユーザーがコンテンツを閲覧した回数をカウントし、その値を共有ストレージに保存できます。一度保存すると、共有ストレージの値はさまざまなオリジンで利用できるようになります。

次に、共有ストレージ ワークレットが共有ストレージ内の値を読み取り、ビューを追加するたびにカウンタをインクリメントします。事前定義された上限に達していない場合は、レンダリングするコンテンツが返されます(インデックス 1)。そうでない場合は、デフォルトの URL が返されます(インデックス 0)。

この例では、次のようになります。

  • creative-selection-by-frequencyjs は、コンテンツ プロデューサーまたは広告主の iframe を介して読み込まれ、共有ストレージ ワークレットを読み込み、返された不透明なソースをフェンス付きのフレームにレンダリングします。
  • creative-selection-by-frequency-worklet.js は、頻度を読み取り、コンテンツまたは広告クリエイティブに返される URL を決定する共有ストレージ ワークレットです。

creative-selection-by-frequency.js

// The first URL is the default content or ad to be rendered when the frequency limits reached.
const CONTENT_URLS = [
  { url: `https://${contentProducerUrl}/default-content.html` },
  { url: `https://${contentProducerUrl}/example-content.html` },
];

async function injectAd() {
  // Load the worklet module.
  await window.sharedStorage.worklet.addModule('creative-selection-by-frequency-worklet.js');

  // Set the initial frequency count
  window.sharedStorage.set('frequency-count', 0, {
    ignoreIfPresent: true,
  });

  // Run the URL selection operation to choose an ad based on the frequency count in shared storage.
  const fencedFrameConfig = await window.sharedStorage.selectURL('creative-selection-by-frequency', CONTENT_URLS, {
    resolveToConfig: true
  });

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

injectAd();

creative-selection-by-frequency-worklet.js

const FREQUENCY_LIMIT = 5;

class CreativeSelectionByFrequencyOperation {
  async run(urls, data) {
    // Read the current frequency limit in shared storage
    const count = parseInt(await this.sharedStorage.get('frequency-count'));

    // Check if the frequency limit has been reached.
    if (count === FREQUENCY_LIMIT) {
      console.log('Frequency limit has been reached, and the default content will be rendered.');
      return 0;
    }

    // Set the new frequency count in shared storage
    await this.sharedStorage.set('frequency-count', count + 1);
    return 1;
  }
}

// Register the operation as 'creative-selection-by-frequency'.
register('creative-selection-by-frequency', CreativeSelectionByFrequencyOperation);

Use cases

These are only some of the possible use cases for Shared Storage. We'll continue to add examples as we receive feedback and discover new use cases.

Content selection

Select and display different content on different websites in fenced frames based on information collected in Shared Storage. The output gate for these use cases is URL selection.

  • Creative rotation: Store data, such as creative ID, view counts, and user interaction, to determine which creative users' see across different sites.
  • A/B testing: You can assign a user to an experiment group, then store that group in Shared Storage to be accessed cross-site.
  • Custom user experiences: Share custom content and calls-to-action based on a user's registration status or other user states

Generate summary reports

Collect information with Shared Storage and generated a noisy, aggregated summary report. The output gate for these use cases is the Private Aggregation API.

  • Unique reach measurement: Many content producers and advertisers want to know how many unique people saw their content. Use Shared Storage to record the first time a user saw your ad, embedded video, or publication, and prevent duplicative counting of that same user on different sites. You can then use the Private Aggregation API to output a summary report for your reach.
  • Demographics measurement: Content producers often want to understand the demographics of their audience. You can use Shared Storage to record user demographic data in a context where you have it, such as your first-party site, and use aggregated reporting to report on it across many other sites, such as embedded content.
  • K+ frequency measurement: Sometimes described as "effective frequency," there is often a minimum number views before a user will recognize or recall certain content (often in the context of advertisement views). You can use Shared Storage to build reports of unique users that have seen a piece of content at least K number of times.

対応してフィードバックを共有する

共有ストレージの提案は現在検討中であり、変更される可能性があります 使用できます。この API をお試しいただき、ご意見やご感想がございましたら、ぜひお聞かせください。