לרוב, יוצרים של תוכן רוצים להבין את המאפיינים הדמוגרפיים של הקהל שלהם. אתם יכולים להשתמש ב-Shared Storage כדי לתעד נתונים דמוגרפיים של משתמשים בהקשר שבו יש לכם אותם, כמו האתר שלכם מאינטראקציה ישירה (First-Party), ואז להשתמש בדוחות מצטברים כדי לכלול את הנתונים האלה בדוחות מאתרים אחרים, כמו התוכן המוטמע שלכם.
Shared Storage API הוא הצעה של ארגז החול לפרטיות לאחסון כללי באתרים שונים, שתומך במגוון תרחישי שימוש אפשריים. Private Aggregation API הוא פלט שזמין ב-Shared Storage ומאפשר לצבור נתונים מאתרים שונים.
ניסיון במדידה של מאפיינים דמוגרפיים של משתמשים
כדי להתנסות במדידת מאפיינים דמוגרפיים של משתמשים באמצעות אחסון משותף וצבירה פרטית, צריך לוודא שאתם משתמשים ב-Chrome Canary וב-Dev M107 ואילך. מפעילים את כל ממשקי ה-API לשמירה על פרטיות בפרסום בקטע chrome://settings/adPrivacy
.
אפשר גם להפעיל את האחסון המשותף באמצעות הדגל --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames
בשורת הפקודה.
התנסות בדוגמאות קוד
יכול להיות שתרצו למדוד מאפיינים דמוגרפיים מסוימים של המשתמשים שראו את התוכן שלכם באתרים שונים, למשל טווח גילאים או מיקום גיאוגרפי. בדוגמה הזו, המאפיינים 'מזהה תוכן', 'מזהה קבוצת גיל' ו'מזהה גיאוגרפי' מקודדים במפתח הצבירה (הקטגוריה), והספירה משמשת כערך שניתן לצבור. בדוח הסיכום שייווצר יופיע מידע כמו "כ-391 משתמשים שצפו בתוכן שמספרו 123 הם בגילאים 18 עד 39 ומאירופה".
בדוגמה הזו:
demographic-measurement.js
נטען באמצעות מסגרת, והוא אחראי על טעינת ה-worklet של האחסון השיתופי.demographic-measurement-worklet.js
הוא ה-worklet של האחסון המשותף שקורא את הנתונים הדמוגרפיים באחסון המשותף ושולח דוח באמצעות Private Aggregation API.
(הוא פועל בשלב כלשהו לפני ביצוע המדידה כדי להגדיר את נתוני הדמוגרפיה ב-Shared Storage)
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); \
יצירת מעורבות ושיתוף משוב
חשוב לזכור שההצעה ל-Shared Storage API נמצאת כרגע בשלבי פיתוח ודיון, ולכן היא כפופה לשינויים.
נשמח לשמוע את דעתכם על Shared Storage API.
- הצעה: בודקים את ההצעה המפורטת.
- דיון: תוכלו להצטרף לדיון המתמשך כדי לשאול שאלות ולשתף את התובנות שלכם.
אפשר להתעדכן
- רשימת תפוצה: כדאי להירשם לרשימת התפוצה שלנו כדי לקבל את העדכונים וההודעות האחרונים שקשורים ל-Shared Storage API.
רוצה לקבל עזרה?
- תמיכה למפתחים: במאגר התמיכה למפתחים של ארגז החול לפרטיות תוכלו ליצור קשר עם מפתחים אחרים ולקבל תשובות לשאלות שלכם.