اندازه گیری جمعیت شناسی کاربران

تولیدکنندگان محتوا اغلب می‌خواهند اطلاعات جمعیتی مخاطبان خود را درک کنند. شما می‌توانید از فضای ذخیره‌سازی مشترک برای ثبت داده‌های جمعیتی کاربران در بستری که در اختیار دارید، مانند سایت شخص اول خود، استفاده کنید و سپس از گزارش‌های تجمیعی برای گنجاندن آن داده‌ها در گزارش‌های سایت‌های دیگر، مانند محتوای جاسازی‌شده خود، استفاده کنید.

API ذخیره‌سازی مشترک (Shared Storage API ) یک پیشنهاد Privacy Sandbox برای ذخیره‌سازی چندمنظوره و بین‌سایتی است که از بسیاری از موارد استفاده ممکن پشتیبانی می‌کند. API تجمیع خصوصی (Private Aggregation API) یک خروجی موجود در ذخیره‌سازی مشترک است که به شما امکان می‌دهد داده‌های بین‌سایتی را تجمیع کنید.

سنجش جمعیت‌شناختی کاربر را امتحان کنید

برای آزمایش سنجش جمعیت‌شناختی کاربران با Shared Storage و Private Aggregation، تأیید کنید که از Chrome Canary و Dev M107 یا بالاتر استفاده می‌کنید. تمام APIهای حریم خصوصی تبلیغات را در chrome://settings/adPrivacy فعال کنید.

همچنین می‌توانید Shared Storage را با استفاده از پرچم --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames در خط فرمان فعال کنید.

با نمونه کدها آزمایش کنید

ممکن است بخواهید ویژگی‌های جمعیتی خاصی از کاربرانی که محتوای شما را در سایت‌های مختلف دیده‌اند، مانند محدوده سنی یا موقعیت جغرافیایی، را اندازه‌گیری کنید. در این مثال، شناسه محتوا، شناسه گروه سنی و ابعاد شناسه جغرافیایی در کلید تجمیع (bucket) کدگذاری شده‌اند و تعداد آنها به عنوان مقدار قابل تجمیع استفاده می‌شود. گزارش خلاصه تولید شده اطلاعاتی مانند "تقریباً 391 کاربر که محتوای شناسه 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 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); \

مشارکت کنید و بازخورد خود را به اشتراک بگذارید

توجه داشته باشید که پیشنهاد API ذخیره‌سازی مشترک (Shared Storage API) در دست بحث و توسعه فعال است و بنابراین ممکن است تغییر کند.

مشتاقانه منتظر شنیدن نظرات شما در مورد API ذخیره‌سازی مشترک هستیم.