コンテンツ制作者の多くは、視聴者のユーザー属性を把握したいと考えています。共有ストレージを使用すると、所有しているコンテキスト(自社サイトなど)でユーザー属性データを記録し、集計レポートを使用して他のサイトのレポート(埋め込みコンテンツなど)にそのデータを含めることができます。
Shared Storage API は、汎用のクロスサイト ストレージに関するプライバシー サンドボックスの提案であり、多くのユースケースに対応しています。Private Aggregation API は、クロスサイト データを集計できる共有ストレージの出力です。
ユーザー属性の測定を試す
共有ストレージとプライベート アグリゲーションを使用してユーザー属性の測定を試すには、Chrome Canary と Dev M107 以降を使用していることを確認してください。次に、chrome://flags/#privacy-sandbox-ads-apis
でプライバシー サンドボックスの広告 API のテストフラグを有効にします。
コマンドラインで --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames
フラグを使用して共有ストレージを有効にすることもできます。
コードサンプルでテストする
さまざまなサイトでコンテンツを見たユーザーの属性(年齢層や地域など)を測定したい場合、この例では、コンテンツ ID、年齢層 ID、地域 ID のディメンションが集計キー(バケット)にエンコードされ、カウントが集計可能値として使用されます。生成される概要レポートには、「コンテンツ ID 123 を見た約 391 人のユーザーが、ヨーロッパ在住の 18 ~ 39 歳である」といった情報が表示されます。
この例では、次のようになります。
demographic-measurement.js
はフレームを介して読み込まれ、共有ストレージ ワークレットを読み込みます。demographic-measurement-worklet.js
は、共有ストレージ内のユーザー属性データを読み取り、Private Aggregation API を介してレポートを送信する共有ストレージ ワークレットです。
(ユーザー属性データを共有ストレージに設定するための測定が行われる前の任意の時点で実行)
function getDemogrationsData() {
// Collect age group and continent data
return {
ageGroup,
continent
}
}
async function storeDemographics() {
const { ageGroup, continent } = getDemographicsData();
await window.sharedStorage.set('age-group', ageGroup);
await window.sharedStorage.set('continent', continent);
}
storeDemographics();
async function measureDemographics() {
// Load the Shared Storage worklet
await window.sharedStorage.worklet.addModule('demographics-measurement-worklet.js');
// Run the demographics measurement operation
await window.sharedStorage.run('demographics-measurement', { data: { contentId: '123' } });
}
measureDemographics();
demographic-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 ad campaign
* ID itself. For more complex bucket key construction, see other use cases in
* this demo.
*/
const AGGREGATION_KEY_MAP = {
ageGroupId: {
'18-39': '1',
'40-64': '2',
'65+': '3',
},
continentId: {
africa: '1',
antarctica: '2',
asia: '3',
australia: '4',
europe: '5',
'north-america': '6',
'south-america': '7',
},
};
/**
* The aggregation key will be in the format of:
* contentId | ageGroupId | continentId
*
* For example, a user from Australia between the age of 40-64, who has
* seen the Content ID 321 will be represented by the key:
* 321 | 2 | 4 or 32124
*/
function generateAggregationKey(contentId, ageGroup, continent) {
const ageGroupId = AGGREGATION_KEY_MAP.ageGroupId[ageGroup];
const continentId = AGGREGATION_KEY_MAP.continentId[continent];
const aggregationKey = BigInt(`${contentId}${ageGroupId}${continentId}`);
return aggregationKey;
}
class DemographicsMeasurementOperation {
async run(data) {
const { contentId } = data;
// Read from Shared Storage
const key = 'has-reported-content';
const hasReportedContent = (await this.sharedStorage.get(key)) === 'true';
const ageGroup = await this.sharedStorage.get('age-group');
const continent = await this.sharedStorage.get('continent');
// Do not report if a report has been sent already
if (hasReportedContent) {
return;
}
// Generate the aggregation key and the aggregatable value
const bucket = generateAggregationKey(contentId, ageGroup, continent);
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(key, true);
}
}
// Register the operation
register('demographics-measurement', DemographicsMeasurementOperation); \
フィードバックを共有
共有ストレージの提案は現在検討中であり、将来変更される可能性があります。この API をお試しいただき、フィードバックがございましたら、ぜひお寄せください。
- GitHub: 提案を確認し、質問を投稿し、ディスカッションに参加する。
- Shared Storage API に関するお知らせ: メーリング リストに参加したり、過去のお知らせを確認したりできます。
- デベロッパー サポート: プライバシー サンドボックス デベロッパー サポート リポジトリで質問したり、ディスカッションに参加したりできます。