מדידת מידע דמוגרפי של משתמשים

מפיקי תוכן רוצים בדרך כלל להבין את המאפיינים הדמוגרפיים של הקהל שלהם. אתם יכולים להשתמש בנפח אחסון משותף כדי לתעד נתונים דמוגרפיים של משתמשים בהקשר שבו הם נמצאים, למשל באתר שלכם מאינטראקציה ישירה (First-Party), ולאחר מכן להשתמש בדיווח מצטבר כדי לכלול את הנתונים האלה בדוחות מאתרים אחרים, כמו התוכן המוטמע שלכם.

Shared Storage API הוא הצעה של ארגז חול לפרטיות לשימוש כללי, אחסון באתרים שונים, שתומך בהרבה תרחישים אפשריים של שימוש. Private Aggregation API הוא פלט שזמין באחסון משותף שמאפשר לכם לצבור נתונים מאתרים שונים.

כדאי לנסות את המדידה הדמוגרפית של המשתמשים

כדי להתנסות במדידה דמוגרפית של משתמשים עם 'אחסון משותף' ו'צבירה פרטית', צריך לוודא שאתם משתמשים ב-Chrome Canary ובגרסת Dev M107 ואילך. לאחר מכן מפעילים את הסימון של ניסוי בממשקי ה-API של ארגז החול לפרטיות בכתובת chrome://flags/#privacy-sandbox-ads-apis.

צריך להפעיל את הניסוי של ממשקי ה-API של מודעות ארגז החול לפרטיות כך שאפשר יהיה להשתמש בממשקי ה-API האלה.

ניתן להפעיל אחסון משותף גם באמצעות הדגל --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames בשורת הפקודה.

ניסוי עם דוגמאות קוד

ייתכן שתרצו למדוד נתונים דמוגרפיים מסוימים של המשתמשים שראו את התוכן שלכם באתרים שונים, למשל טווח גילאים או מיקום גיאוגרפי. בדוגמה זו, המאפיינים של Content ID, מזהה קבוצת גיל ומזהה גיאוגרפי מקודדים במפתח הצבירה (קטגוריה), והספירה משמשת כערך נצבר. דוח הסיכום שנוצר יספק מידע כגון "בערך 391 משתמשים שראו את מזהה ה-Content ID 123 הם בין הגילאים 18-39 והם מאירופה".

בדוגמה הזו:

  • demographic-measurement.js נטען דרך פריים, והוא אחראי לטעינת ה-worklet של האחסון המשותף.
  • demographic-measurement-worklet.js הוא worklet של האחסון המשותף שקורא את הנתונים הדמוגרפיים באחסון משותף ושולח דוח דרך Private Aggregation API.

store-demographic-data.js

(המדד פועל בשלב מסוים לפני שהמדידה מתבצעת כדי להגדיר את הנתונים הדמוגרפיים באחסון משותף)

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();

demographic-measurement.js

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 הזה ויש לך משוב, נשמח לשמוע אותו.