Đo lường thông tin nhân khẩu học của người dùng

Nhà sản xuất nội dung thường muốn nắm được thông tin nhân khẩu học của khán giả. Bạn có thể sử dụng Shared Storage để ghi lại dữ liệu nhân khẩu học của người dùng trong một bối cảnh mà bạn có dữ liệu đó, chẳng hạn như trang web của bên thứ nhất, sau đó sử dụng báo cáo tổng hợp để đưa dữ liệu đó vào báo cáo từ các trang web khác, chẳng hạn như nội dung được nhúng.

Shared Storage API là một đề xuất của Hộp cát về quyền riêng tư cho bộ nhớ đa dụng, trên nhiều trang web, hỗ trợ nhiều trường hợp sử dụng có thể xảy ra. Private Aggregation API là một đầu ra có trong Shared Storage, cho phép bạn tổng hợp dữ liệu trên nhiều trang web.

Thử đo lường nhân khẩu học của người dùng

Để thử nghiệm đo lường thông tin nhân khẩu học của người dùng bằng Shared Storage và Private Aggregation, hãy xác nhận rằng bạn đang sử dụng Chrome Canary và Dev M107 trở lên. Bật tất cả các API Quyền riêng tư trong quảng cáo trong chrome://settings/adPrivacy.

Bạn cũng có thể bật Bộ nhớ dùng chung bằng cờ --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames trong dòng lệnh.

Thử nghiệm với mã mẫu

Bạn có thể muốn đo lường một số thông tin nhân khẩu học nhất định của những người dùng đã xem nội dung của bạn trên nhiều trang web, chẳng hạn như độ tuổi hoặc vị trí địa lý. Trong ví dụ này, các phương diện mã nhận dạng nội dung, mã nhận dạng nhóm tuổi và mã nhận dạng địa lý được mã hoá thành khoá tổng hợp (nhóm), còn số lượt truy cập được dùng làm giá trị có thể tổng hợp. Báo cáo tóm tắt được tạo sẽ cung cấp thông tin như "Khoảng 391 người dùng đã xem nội dung có mã nhận dạng 123 có độ tuổi từ 18 đến 39 và đến từ Châu Âu".

Trong ví dụ này:

  • demographic-measurement.js được tải bằng một khung và chịu trách nhiệm tải worklet bộ nhớ dùng chung.
  • demographic-measurement-worklet.js là worklet bộ nhớ dùng chung, đọc dữ liệu nhân khẩu học trong bộ nhớ dùng chung và gửi báo cáo bằng Private Aggregation API.

store-demographic-data.js

(Chạy vào một thời điểm nào đó trước khi hoạt động đo lường được thực hiện để thiết lập dữ liệu nhân khẩu học vào Shared Storage)

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); \

Tương tác và chia sẻ ý kiến phản hồi

Xin lưu ý rằng đề xuất về Shared Storage API đang được thảo luận và phát triển tích cực, vì vậy, đề xuất này có thể thay đổi.

Chúng tôi rất mong được biết ý kiến của bạn về Shared Storage API.