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

कॉन्टेंट प्रोड्यूसर अक्सर अपने दर्शकों की डेमोग्राफ़िक्स (उम्र, लिंग, आय, शिक्षा वगैरह) को समझना चाहते हैं. शेयर किए गए स्टोरेज का इस्तेमाल करके, उपयोगकर्ता की डेमोग्राफ़िक (उम्र, लिंग, आय, शिक्षा वगैरह) डेटा को उस जगह के हिसाब से रिकॉर्ड किया जा सकता है जहां आपके पास उपलब्ध है. जैसे, आपके पहले पक्ष की साइट. इसके बाद, उस डेटा को अन्य साइटों की रिपोर्ट में शामिल करने के लिए, एग्रीगेट की गई रिपोर्टिंग का इस्तेमाल किया जा सकता है. जैसे, एम्बेड किया गया कॉन्टेंट.

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

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

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

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

कोड सैंपल के साथ प्रयोग करें

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

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

  • demographic-measurement.js को एक फ़्रेम से लोड किया जाता है. इसकी ज़िम्मेदारी, शेयर किए गए स्टोरेज के वर्कलेट को भी लोड करनी होती है.
  • demographic-measurement-worklet.js, शेयर किया गया स्टोरेज वर्कलेट है, जो शेयर किए गए स्टोरेज में मौजूद डेमोग्राफ़िक्स (उम्र, लिंग, आय, शिक्षा वगैरह) के डेटा को पढ़ता है और Private एग्रीगेशन 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 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); \

लोगों से जुड़ें और सुझाव, शिकायत या राय शेयर करें

शेयर किए गए स्टोरेज के प्रपोज़ल पर अभी चर्चा चल रही है. आने वाले समय में, इसमें बदलाव हो सकता है. अगर आप इस एपीआई को आज़माते हैं और आपके पास कोई सुझाव, राय या शिकायत है, तो हमें खुशी होगी.