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

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

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

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

لإجراء تجربة على قياس الخصائص الديمغرافية للمستخدمين باستخدام Shared Storage وPrivate Aggregation، تأكَّد من استخدام الإصدار M107 من Chrome Canary وDev أو الإصدارات الأحدث. فعِّل جميع واجهات برمجة التطبيقات "للخصوصية في عرض الإعلانات" ضمن chrome://settings/adPrivacy.

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

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

قد تحتاج إلى قياس خصائص ديمغرافية معيّنة للمستخدمين الذين شاهدوا المحتوى الخاص بك على مواقع إلكترونية مختلفة، مثل الفئة العمرية أو الموقع الجغرافي. في هذا المثال، يتم ترميز سمات معرّف المحتوى ومعرّف الفئة العمرية ومعرّف الموقع الجغرافي في مفتاح التجميع (الحزمة)، ويتم استخدام العدد كقيمة قابلة للتجميع. سيقدّم التقرير التلخيصي الذي يتم إنشاؤه معلومات، مثل "تتراوح أعمار 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 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.

الاطّلاع على آخر الأخبار

  • القائمة البريدية: يمكنك الاشتراك في قائمتنا البريدية لتلقّي آخر الأخبار والإشعارات المتعلّقة بواجهة برمجة التطبيقات Shared Storage API.

هل أنت بحاجة إلى مساعدة؟