قياس الخصائص الديمغرافية للمستخدم

غالبًا ما يرغب منتجو المحتوى في فهم الخصائص الديمغرافية لجمهورهم. يمكنك استخدام "مساحة التخزين المشتركة" لتسجيل البيانات الديمغرافية للمستخدمين في سياق تتوفّر لديك تلك البيانات، مثل موقع الطرف الأول، ثم استخدام التقارير المجمّعة لتضمين هذه البيانات في تقارير من مواقع إلكترونية أخرى، مثل المحتوى المضمّن.

Shared Storage API هي اقتراح ضمن "مبادرة حماية الخصوصية" مخصّص للاستخدام العام ومساحة التخزين على مواقع إلكترونية متعددة، ويتوافق مع العديد من حالات الاستخدام الممكنة واجهة برمجة التطبيقات الخاصة للتجميع الخاص هي ناتج متوفّر في "مساحة التخزين المشتركة" يسمح لك بتجميع البيانات من مواقع إلكترونية متعددة.

تجربة ميزة القياس حسب الخصائص الديمغرافية للمستخدمين

لتجربة قياس الخصائص الديمغرافية للمستخدمين من خلال مساحة التخزين المشتركة والتجميع الخاص، تأكَّد من استخدام إصدار Chrome Canary والإصدار M107 من Chrome أو إصدار أحدث. بعد ذلك، فعِّل علامة تجربة واجهات برمجة التطبيقات لإعلانات "مبادرة حماية الخصوصية" على chrome://flags/#privacy-sandbox-ads-apis.

يجب تفعيل تجربة واجهات برمجة التطبيقات للإعلانات في "مبادرة حماية الخصوصية" لاستخدام واجهات برمجة التطبيقات هذه.

يمكنك أيضًا تفعيل "مساحة التخزين المشتركة" باستخدام العلامة --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames في سطر الأوامر.

تجربة عيّنات التعليمات البرمجية

يمكنك قياس خصائص ديمغرافية معيّنة للمستخدمين الذين شاهدوا المحتوى الخاص بك في مواقع إلكترونية مختلفة، مثل الفئة العمرية أو الموقع الجغرافي. في هذا المثال، يتمّ ترميز سمات Content ID ومعرّف الفئة العمرية ومعرّف الموقع الجغرافي في مفتاح التجميع (حزمة)، ويتمّ استخدام العدد كقيمة مجمّعة. سيوفر تقرير الملخّص الذي تم إنشاؤه معلومات مثل "حوالي 391 مستخدمًا شاهدوا معرّف المحتوى 123 تتراوح أعمارهم بين 18 و39 عامًا وهم من أوروبا".

في هذا المثال:

  • يتم تحميل demographic-measurement.js من خلال إطار، ويكون مسؤولًا عن تحميل مهام التخزين المشتركة.
  • demographic-measurement-worklet.js هو الوظيفة المصغّرة لمساحة التخزين المشتركة التي تقرأ بيانات الخصائص الديمغرافية في مساحة التخزين المشتركة وترسل تقريرًا من خلال 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); \

التفاعل مع الملاحظات ومشاركتها

يخضع اقتراح مساحة التخزين المشتركة للمناقشة النشطة ويخضع للتغيير في المستقبل. إذا جربت واجهة برمجة التطبيقات هذه ولديك تعليقات، يسعدنا سماعها.