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

कॉन्टेंट बनाने वाले लोग अक्सर अपने दर्शकों की डेमोग्राफ़िक्स के बारे में जानना चाहते हैं. उपयोगकर्ता के डेमोग्राफ़िक्स का डेटा रिकॉर्ड करने के लिए, 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 का वर्कलेट है. यह 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); \

दर्शकों से जुड़ना और सुझाव, राय या शिकायत शेयर करना

ध्यान दें कि Shared Storage API के प्रस्ताव पर फ़िलहाल चर्चा की जा रही है और इसे डेवलप किया जा रहा है. इसलिए, इसमें बदलाव हो सकते हैं.

हम शेयर किए गए स्टोरेज के एपीआई के बारे में आपके विचार जानना चाहते हैं.

अप-टू-डेट रहना

  • मेल सूची: Shared Storage API से जुड़े नए अपडेट और सूचनाओं के लिए, हमारी मेल सूची की सदस्यता लें.

क्या आपको मदद चाहिए?