कॉन्टेंट प्रोड्यूसर अक्सर अपने दर्शकों की डेमोग्राफ़िक्स (उम्र, लिंग, आय, शिक्षा वगैरह) के बारे में जानना चाहते हैं. आपके पास जिस कॉन्टेक्स्ट में उपयोगकर्ता का डेमोग्राफ़िक डेटा मौजूद है, उसे रिकॉर्ड करने के लिए, शेयर किए गए स्टोरेज का इस्तेमाल किया जा सकता है. जैसे, आपकी पहले-पक्ष की साइट. इसके बाद, इकट्ठा की गई रिपोर्ट का इस्तेमाल करके, उस डेटा को अन्य साइटों की रिपोर्ट में शामिल किया जा सकता है. जैसे, एम्बेड किया गया कॉन्टेंट.
Shared Storage API, प्राइवसी सैंडबॉक्स से जुड़ा एक प्रस्ताव है. इसे अलग-अलग कामों के लिए, अलग-अलग कामों के लिए इस्तेमाल किया जाता है. इससे कई तरीकों से मदद मिल सकती है. प्राइवेट एग्रीगेशन एपीआई, शेयर किए गए स्टोरेज में उपलब्ध एक आउटपुट होता है. इसकी मदद से, क्रॉस-साइट डेटा इकट्ठा किया जा सकता है.
उपयोगकर्ताओं की डेमोग्राफ़िक (उम्र, लिंग, आय, शिक्षा वगैरह) का मेज़रमेंट आज़माएं
शेयर किए गए स्टोरेज और निजी एग्रीगेशन की मदद से, उपयोगकर्ता के डेमोग्राफ़िक्स (उम्र, लिंग, आय, शिक्षा वगैरह) मेज़रमेंट के साथ प्रयोग करने के लिए, पुष्टि करें कि Chrome कैनरी और Dev M107 या इसके बाद के वर्शन का इस्तेमाल किया जा रहा है. इसके बाद, chrome://flags/#privacy-sandbox-ads-apis
पर Privacy Sandbox Ads API प्रयोग फ़्लैग को चालू करें.
कमांड लाइन में --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames
फ़्लैग का इस्तेमाल करके, शेयर किए गए स्टोरेज की सुविधा को भी चालू किया जा सकता है.
कोड सैंपल के साथ प्रयोग करें
हो सकता है कि आप अलग-अलग साइटों पर आपका कॉन्टेंट देखने वाले उपयोगकर्ताओं की कुछ डेमोग्राफ़िक्स (उम्र, लिंग, आय, शिक्षा वगैरह) का आकलन करना चाहें. जैसे, उम्र सीमा या भौगोलिक जगह. इस उदाहरण में, Content ID, उम्र समूह का आईडी, और भौगोलिक आईडी के डाइमेंशन को एग्रीगेशन कुंजी (बकेट) में एन्कोड किया गया है. साथ ही, गिनती का इस्तेमाल एग्रीगेट वैल्यू के तौर पर किया गया है. जनरेट की गई खास जानकारी वाली रिपोर्ट में कुछ इस तरह की जानकारी होगी: "कॉन्टेंट आईडी 123 को देखने वाले करीब 391 उपयोगकर्ताओं की उम्र 18 से 39 साल के बीच है और वे यूरोप से हैं."
इस उदाहरण में:
demographic-measurement.js
को एक फ़्रेम से लोड किया जाता है. इस पर, शेयर किए गए स्टोरेज के वर्कलेट को लोड करने की ज़िम्मेदारी होती है.demographic-measurement-worklet.js
, शेयर किए गए स्टोरेज के लिए वर्कलेट है. यह शेयर किए गए स्टोरेज में मौजूद डेमोग्राफ़िक्स (उम्र, लिंग, आय, शिक्षा वगैरह) डेटा को पढ़ता है और Private एग्रीगेशन एपीआई के ज़रिए रिपोर्ट भेजता है.
(यह डेटा, शेयर किए गए स्टोरेज में डेमोग्राफ़िक्स के डेटा को सेट करने के लिए, मेज़रमेंट से पहले किसी समय पर काम करता है)
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 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); \
लोगों से जुड़ें और सुझाव, शिकायत या राय शेयर करें
शेयर किए गए स्टोरेज के प्रपोज़ल पर अभी चर्चा चल रही है. आने वाले समय में, इसमें बदलाव हो सकता है. अगर आप इस एपीआई को आज़माते हैं और आपके पास कोई सुझाव, राय या शिकायत है, तो हमें खुशी होगी.
- GitHub: प्रस्ताव पढ़ें, सवाल उठाएं, और चर्चा में हिस्सा लें.
- Shared Storage API से जुड़ी सूचनाएं: हमारी मेलिंग सूची में शामिल हों या पिछली सूचनाएं देखें
- डेवलपर सहायता: प्राइवसी सैंडबॉक्स डेवलपर सहायता रेपो पर सवाल पूछें और होने वाली चर्चाओं में शामिल हों.