「有効フリークエンシー」とも呼ばれますが、ユーザーが特定のコンテンツを認識または想起するまでに必要な最小視聴回数が存在することがよくあります(多くの場合、広告の視聴回数に関連します)。共有ストレージを使用すると、コンテンツを K 回以上閲覧したユニーク ユーザーのレポートを作成できます。
Shared Storage API は、汎用のクロスサイト ストレージに関するプライバシー サンドボックスの提案で、多くのユースケースに対応できます。Private Aggregation API は、クロスサイト データを集計できる Shared Storage で利用可能な出力です。
K 回以上のフリークエンシー測定を試す
Shared Storage と Private Aggregation を使用して K+ 頻度測定を試すには、Chrome M107 以降を使用していることを確認してください。chrome://settings/adPrivacy で広告プライバシー API をすべて有効にします。
コマンドラインで --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames フラグを使用して共有ストレージを有効にすることもできます。
コードサンプルを試す
たとえば、特定のクライアントでコンテンツを K 回以上閲覧したユーザーの数を、さまざまなサイトで測定したい場合があります。この例では、コンテンツが読み込まれるたびに 1 ずつ増える表示回数が共有ストレージに追加されます。インプレッション数が 3 に達すると、Private Aggregation API が呼び出されます。コンテンツ ID ディメンションは集計キーとしてエンコードされ、カウントは集計可能な値として使用されます。概要レポートには、「約 391 人のユーザーが広告キャンペーン ID 123 を 3 回以上閲覧しました」などの情報が表示されます。
この例では、次のようになります。
k-frequency-measurement.jsはフレームを使用して読み込まれ、共有ストレージ ワークレットの読み込みを担当します。k-frequency-measurement-worklet.jsは、共有ストレージ内のインプレッション数を読み取り、Private Aggregation API を使用してレポートを送信する共有ストレージ ワークレットです。
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();
kuency-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 just 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 sharedStorage.get(hasReportedContentKey)) === 'true';
const impressionCount = parseInt((await sharedStorage.get(impressionCountKey)) || 0);
// Don't report if a report has been sent already
if (hasReportedContent) {
return;
}
// Check impression count against frequency limit
if (impressionCount < kFreq) {
await 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 using the Private Aggregation API
privateAggregation.contributeToHistogram({ bucket, value });
// Set the report submission status flag
await sharedStorage.set(hasReportedContentKey, 'true');
}
}
// Register the operation
register('k-freq-measurement', KFreqMeasurementOperation); \
Engage and share feedback
Note that the Shared Storage API proposal is under active discussion and development and therefore subject to change.
We're eager to hear your thoughts on the Shared Storage API.
- Proposal: Review the detailed proposal.
- Discussion: Join the ongoing discussion to ask questions and share your insights.