ผู้ผลิตเนื้อหามักต้องการทำความเข้าใจข้อมูลประชากรของกลุ่มเป้าหมาย คุณสามารถใช้พื้นที่เก็บข้อมูลส่วนกลางเพื่อบันทึกข้อมูลประชากรของผู้ใช้ในบริบทที่คุณมี เช่น เว็บไซต์ของบุคคลที่หนึ่ง จากนั้นใช้การรายงานแบบรวมเพื่อรวมข้อมูลดังกล่าวไว้ในรายงานจากเว็บไซต์อื่นๆ เช่น เนื้อหาที่ฝัง
Shared Storage API เป็นข้อเสนอ Privacy Sandbox สำหรับพื้นที่เก็บข้อมูลข้ามเว็บไซต์อเนกประสงค์ที่รองรับ Use Case หลายรายการ Private Aggregation API เป็นเอาต์พุตที่มีอยู่ใน Shared Storage ซึ่งช่วยให้คุณรวบรวมข้อมูลจากหลายเว็บไซต์ได้
ลองวัดข้อมูลประชากรของผู้ใช้
หากต้องการทดสอบการวัดข้อมูลประชากรของผู้ใช้ด้วยพื้นที่เก็บข้อมูลที่ใช้ร่วมกันและ Private Aggregation โปรดยืนยันว่าคุณใช้ Chrome Canary และ Dev M107 ขึ้นไป เปิดใช้ Ad Privacy API ทั้งหมดในส่วน chrome://settings/adPrivacy
นอกจากนี้ คุณยังเปิดใช้พื้นที่เก็บข้อมูลที่ใช้ร่วมกันได้ด้วย Flag --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames
ในบรรทัดคำสั่ง
ทดลองใช้ตัวอย่างโค้ด
คุณอาจต้องวัดข้อมูลประชากรบางอย่างของผู้ใช้ที่ดูเนื้อหาของคุณในเว็บไซต์ต่างๆ เช่น ช่วงอายุหรือสถานที่ตั้งทางภูมิศาสตร์ ในตัวอย่างนี้ มิติข้อมูลรหัสเนื้อหา รหัสกลุ่มอายุ และรหัสภูมิศาสตร์ได้รับการเข้ารหัสเป็นคีย์การรวม (ที่เก็บข้อมูล) และระบบจะใช้จํานวนเป็นค่าที่รวบรวมได้ รายงานสรุปที่สร้างขึ้นจะให้ข้อมูล เช่น "ผู้ใช้ประมาณ 391 คนที่ได้เห็นรหัสเนื้อหา 123 มีอายุระหว่าง 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 just 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 sharedStorage.get(key)) === 'true';
const ageGroup = await sharedStorage.get('age-group');
const continent = await sharedStorage.get('continent');
// Don't 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 using the Private Aggregation API
privateAggregation.contributeToHistogram({ bucket, value });
// Set the report submission status flag
await sharedStorage.set(key, true);
}
}
// Register the operation
register('demographics-measurement', DemographicsMeasurementOperation); \
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.
Stay Informed
- Mailing List: Subscribe to our mailing list for the latest updates and announcements related to the Shared Storage API.
Need Help?
- Developer Support: Connect with other developers and get answers to your questions in the Privacy Sandbox Developer Support repository.