उपयोगकर्ता की डेमोग्राफ़िक्स (उम्र, लिंग, आय, शिक्षा वगैरह) को मेज़र करना

कॉन्टेंट बनाने वाले लोगों को अक्सर अपनी ऑडियंस की डेमोग्राफ़िक्स के बारे में जानना होता है. Shared Storage का इस्तेमाल करके, उपयोगकर्ता के डेमोग्राफ़िक डेटा को ऐसे कॉन्टेक्स्ट में रिकॉर्ड किया जा सकता है जहां आपके पास यह डेटा मौजूद है. जैसे, आपकी पहली पार्टी की साइट. इसके बाद, कुल रिपोर्टिंग का इस्तेमाल करके, उस डेटा को अन्य साइटों की रिपोर्ट में शामिल किया जा सकता है. जैसे, एम्बेड किया गया आपका कॉन्टेंट.

Shared Storage API, Privacy Sandbox का एक प्रस्ताव है. इसका इस्तेमाल, अलग-अलग कामों के लिए और एक से ज़्यादा साइटों पर डेटा सेव करने के लिए किया जाता है. यह कई तरह के इस्तेमाल के उदाहरणों के साथ काम करता है. Private Aggregation API, Shared Storage में उपलब्ध एक आउटपुट है. इसकी मदद से, अलग-अलग साइटों से मिले डेटा को एग्रीगेट किया जा सकता है.

उपयोगकर्ता की डेमोग्राफ़िक (उम्र, लिंग, आय, शिक्षा वगैरह) से जुड़े डेटा को मेज़र करने की सुविधा आज़माएं

Shared Storage और Private Aggregation की मदद से, उपयोगकर्ता के डेमोग्राफ़िक मेज़रमेंट का एक्सपेरिमेंट करने के लिए, पक्का करें कि Chrome Canary और Dev M107 या इसके बाद के वर्शन का इस्तेमाल किया जा रहा हो. chrome://settings/adPrivacy में जाकर, विज्ञापन देखने वाले की निजता बनाए रखने से जुड़े सभी एपीआई चालू करें.

कमांड लाइन में --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames फ़्लैग का इस्तेमाल करके भी, शेयर किए गए स्टोरेज की सुविधा चालू की जा सकती है.

कोड सैंपल आज़माएँ

ऐसा हो सकता है कि आपको अलग-अलग साइटों पर आपका कॉन्टेंट देखने वाले उपयोगकर्ताओं के कुछ डेमोग्राफ़िक को मेज़र करना हो. उदाहरण के लिए, उम्र सीमा या जगह. इस उदाहरण में, कॉन्टेंट आईडी, उम्र ग्रुप आईडी, और इलाके के आईडी डाइमेंशन को एग्रीगेशन कुंजी (बकेट) में कोड किया गया है. साथ ही, गिनती का इस्तेमाल एग्रीगेट की जा सकने वाली वैल्यू के तौर पर किया गया है. जनरेट की गई खास जानकारी वाली रिपोर्ट में, इस तरह की जानकारी शामिल होगी: "कॉन्टेंट आईडी 123 वाले वीडियो को देखने वाले करीब 391 उपयोगकर्ता, यूरोप के हैं और उनकी उम्र 18 से 39 साल के बीच है."

इस उदाहरण में:

  • demographic-measurement.js को फ़्रेम का इस्तेमाल करके लोड किया जाता है. साथ ही, यह शेयर किए गए स्टोरेज वर्कलेट को लोड करने के लिए ज़िम्मेदार होता है.
  • demographic-measurement-worklet.js, Shared Storage Worklet है. यह Shared Storage में मौजूद डेमोग्राफ़िक्स डेटा को पढ़ता है और Private Aggregation API का इस्तेमाल करके रिपोर्ट भेजता है.

store-demographic-data.js

(यह कुकी, मेज़रमेंट किए जाने से पहले किसी समय चलती है, ताकि जनसांख्यिकी डेटा को 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();

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 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.