사용자 인구통계 측정

콘텐츠 제작자는 시청자의 인구통계를 알고 싶어 하는 경우가 많습니다. 공유 스토리지를 사용하면 퍼스트 파티 사이트와 같이 데이터가 있는 상황에서 사용자 인구통계 데이터를 기록한 다음, 집계된 보고서를 사용하여 삽입된 콘텐츠와 같은 다른 사이트의 보고서에 해당 데이터를 포함할 수 있습니다.

Shared Storage API는 다양한 사용 사례를 지원하는 범용 크로스 사이트 저장소를 위한 개인 정보 보호 샌드박스 제안서입니다. Private Aggregation API는 공유 저장소에서 사용할 수 있는 출력으로, 이를 통해 크로스 사이트 데이터를 집계할 수 있습니다.

사용자 인구통계 측정 사용해 보기

공유 스토리지 및 비공개 집계를 사용하여 사용자 인구통계 측정을 실험하려면 Chrome Canary 및 Dev M107 이상을 사용하고 있는지 확인하세요. chrome://settings/adPrivacy에서 모든 광고 개인 정보 보호 API를 사용 설정합니다.

명령줄에서 --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames 플래그를 사용하여 공유 저장소를 사용 설정할 수도 있습니다.

코드 샘플 실험

연령대나 지리적 위치와 같은 여러 사이트에서 콘텐츠를 본 사용자의 특정 인구통계를 측정할 수 있습니다. 이 예에서는 콘텐츠 ID, 연령대 ID, 지역 ID 측정기준이 집계 키 (버킷)에 인코딩되며 개수는 집계 가능한 값으로 사용됩니다. 생성된 요약 보고서에는 'Content ID 123을 본 약 391명의 사용자가 유럽에 거주하는 만 18~39세의 사용자'와 같은 정보가 제공됩니다.

이 예는 다음과 같습니다.

  • demographic-measurement.js는 프레임을 통해 로드되며 공유 저장소 Worklet의 로드를 담당합니다.
  • demographic-measurement-worklet.js는 공유 스토리지에서 인구통계 데이터를 읽고 Private Aggregation API를 통해 보고서를 전송하는 공유 스토리지 Worklet입니다.

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를 사용해 보고 의견을 보내 주세요.