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

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

Shared Storage API یک پیشنهاد Privacy Sandbox برای اهداف عمومی، فضای ذخیره‌سازی بین سایتی است که از بسیاری از موارد استفاده ممکن پشتیبانی می‌کند. Private Aggregation API خروجی موجود در ذخیره سازی مشترک است که به شما امکان می دهد داده های بین سایتی را جمع آوری کنید.

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

برای آزمایش اندازه‌گیری جمعیت‌شناسی کاربر با فضای ذخیره‌سازی مشترک و تجمیع خصوصی، تأیید کنید که از Chrome Canary و Dev M107 یا جدیدتر استفاده می‌کنید. سپس پرچم آزمایش Privacy Sandbox Ads APIs را در chrome://flags/#privacy-sandbox-ads-apis فعال کنید.

آزمایش APIهای Privacy Sandbox Ads را برای استفاده از این APIها فعال کنید.

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

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

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

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

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