İçerik üreticiler genellikle kitlelerinin demografisini anlamak ister. Kullanıcıların demografik verilerini (ör. birinci taraf siteniz) bulunduğu bir bağlamda kaydetmek için Paylaşılan Depolama Alanı'nı kullanabilir, ardından toplu raporlamayı kullanarak bu verileri diğer sitelerdeki (ör. yerleştirilmiş içeriğiniz) raporlara dahil edebilirsiniz.
Shared Storage API; genel amaçlı, siteler arası depolamaya yönelik bir Özel Korumalı Alan teklifidir. Birçok olası kullanım alanını destekler. Private Aggregation API, Shared Storage'da bulunan ve siteler arası verileri toplamanıza olanak tanıyan bir çıkıştır.
Kullanıcı demografik ölçümünü deneyin
Paylaşılan depolama alanı ve özel toplama ile kullanıcı demografik ölçümüyle ilgili denemeler yapmak için Chrome Canary ve Dev M107 ya da sonraki bir sürümü kullandığınızdan emin olun. chrome://settings/adPrivacy
altındaki tüm reklam gizliliği API'lerini etkinleştirin.
Paylaşılan Depolama Alanı'nı, komut satırındaki --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames
işaretini kullanarak da etkinleştirebilirsiniz.
Kod örnekleriyle denemeler yapma
Yaş grubu veya coğrafi konum gibi, farklı sitelerde içeriğinizi gören kullanıcıların belirli demografik özelliklerini ölçmek isteyebilirsiniz. Bu örnekte Content ID, yaş grubu kimliği ve coğrafi konum kimliği boyutları toplama anahtarına (paket) kodlanmış olup sayı, toplanabilir değer olarak kullanılmaktadır. Oluşturulan özet raporda, "Content ID 123'ü görmüş yaklaşık 391 kullanıcı, 18-39 yaşları arasında ve Avrupa'dadır" gibi bilgiler içerir.
Bu örnekte:
demographic-measurement.js
bir çerçeve aracılığıyla yüklenir ve paylaşılan depolama işletini yüklemekten sorumludur.demographic-measurement-worklet.js
, paylaşılan depolama alanındaki demografi verilerini okuyan ve Private Aggregation API aracılığıyla rapor gönderen paylaşılan depolama iş uygulamasıdır.
(Demografi verilerini Paylaşılan Depolama alanında ayarlamak için, ölçüm yapılmadan belirli bir zamanda çalıştırılır)
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.contributeToHistogram({ bucket, value });
// Set the report submission status flag
await this.sharedStorage.set(key, true);
}
}
// Register the operation
register('demographics-measurement', DemographicsMeasurementOperation); \
Engage and share feedback
The Shared Storage proposal is under active discussion and subject to change in the future. If you try this API and have feedback, we'd love to hear it.
- GitHub: Read the proposal, reach whitepaper, raise questions and participate in discussion.
- Shared Storage API announcements: Join or view past announcements on our mailing list
- Developer support: Ask questions and join discussions on the Privacy Sandbox Developer Support repo.