Shared Storage ワークレットを実行して URL を選択し、フェンス付きフレームでレンダリングします。
Shared Storage API は、汎用のクロスサイト ストレージに関するプライバシー サンドボックスの提案で、多くのユースケースに対応できます。たとえば、Chrome Beta 104.0.5086.0 以降でテストできる周波数制御があります。
ワークレット スクリプトを実行して、保存されたデータに基づいて指定されたリストから URL を選択し、フェンス付きフレームでその URL をレンダリングします。この設定は、フリークエンシー キャップに達したときに新しい広告やその他のコンテンツを選択するために使用できます。
フリークエンシーによるクリエイティブの選択をテストする
Shared Storage と Fenced Frames を使用してフリークエンシーによるクリエイティブ選択をテストするには、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 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 sharedStorage.set('frequency-count', count + 1);
return 1;
}
}
// Register the operation as 'creative-selection-by-frequency'.
register('creative-selection-by-frequency', CreativeSelectionByFrequencyOperation);
ユースケース
このセクションでは、Select URL API で利用可能なすべてのユースケースについて説明します。フィードバックや新しいテストケースの検出に応じて、例を追加していきます。
- 広告クリエイティブをローテーションする: クリエイティブ ID やユーザー インタラクションなどのデータを保存して、ユーザーに表示するクリエイティブをさまざまなサイト間で決定します。
- フリークエンシーで広告クリエイティブを選択する: 視聴回数データを使用して、ユーザーがさまざまなサイトで目にするクリエイティブを特定します。
- A/B テストを実施する: ユーザーをテストグループに割り当て、そのグループを共有ストレージに保存して、クロスサイトからアクセスできるようにします。
- 既知のユーザー向けにエクスペリエンスをカスタマイズする: ユーザーの登録ステータスやその他のユーザー状態に基づいて、カスタム コンテンツや行動を促すフレーズを共有します。
Engage and share feedback
Note that the Select URL API proposal is under active discussion and development and subject to change.
We're eager to hear your thoughts on the Select URL API.
- Proposal: Review the detailed proposal.
- Discussion: Join the ongoing discussion to ask questions and share your insights.