게재빈도별 광고 소재 선택

공유 저장소 워크렛을 실행하여 URL을 선택하고 분리 프레임에 렌더링합니다.

Shared Storage API는 개인 정보 보호 다양한 용도를 지원하는 크로스 사이트 스토리지를 위한 범용 샌드박스 제안 사용 사례일 수 있습니다. 한 가지 예로 게재빈도 제어가 있는데, 이는 테스트할 수 있습니다.

Worklet 스크립트를 실행하여 저장된 구분한 다음 해당 URL을 분리 프레임에 렌더링해야 합니다. 이를 사용하여 새 광고나 다른 콘텐츠를 게재할 수 없습니다.

실행 빈도에 따른 광고 소재 선택 테스트

공유 저장소 및 분리 프레임으로 빈도별 광고 소재 선택을 테스트하려면 Chrome 104.0.5086.0 이상 사용 chrome://settings/adPrivacy에서 모든 광고 개인 정보 보호 API를 사용 설정합니다.

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

코드 샘플 실험

불투명 URL을 선택하고 만들려면 공유 항목을 읽을 워크렛 모듈을 등록하세요. 사용할 수 있습니다 worklet 클래스는 최대 8개의 URL 목록을 받은 다음 는 선택한 URL의 색인을 반환합니다.

클라이언트가 sharedStorage.selectURL()를 호출할 때 Worklet은 를 실행하고 분리 프레임으로 렌더링할 불투명 URL을 반환합니다.

사용자가 이전에 광고를 본 횟수의 빈도에 따라 렌더링할 다른 광고나 콘텐츠를 선택한다고 가정해 보겠습니다. 사용자가 콘텐츠를 본 횟수를 계산하고 그 가치를 공유 저장공간에 저장할 수 있습니다. 공유 스토리지의 값을 저장하면 여러 출처에서 사용할 수 있습니다.

그런 다음, 공유 저장소 Worklet은 공유 저장소의 값을 읽고 추가 뷰가 있을 때마다 카운터를 증가시킵니다. 개수가 사전 정의된 한도에 도달하지 않은 경우 렌더링할 콘텐츠 (색인 1)가 반환됩니다. 그렇지 않은 경우 기본 URL (색인 0)이 반환됩니다.

이 예에서는 다음과 같이 정의됩니다.

  • creative-selection-by-frequencyjs는 콘텐츠 제작자 또는 광고주의 iframe을 통해 로드되며 는 공유 저장소 Worklet을 로드하고 반환된 불투명한 분리 프레임으로 전송합니다.
  • creative-selection-by-frequency-worklet.js는 게재빈도를 사용하여 콘텐츠 또는 광고 소재에 대해 반환되는 URL을 결정합니다.

creative-selection-by-frequency.js

// The first URL is the default content or ad to be rendered when the frequency limits reached.
const CONTENT_URLS = [
  { url: `https://${contentProducerUrl}/default-content.html` },
  { url: `https://${contentProducerUrl}/example-content.html` },
];

async function injectAd() {
  // Load the worklet module.
  await window.sharedStorage.worklet.addModule('creative-selection-by-frequency-worklet.js');

  // Set the initial frequency count
  window.sharedStorage.set('frequency-count', 0, {
    ignoreIfPresent: true,
  });

  // Run the URL selection operation to choose an ad based on the frequency count in shared storage.
  const fencedFrameConfig = await window.sharedStorage.selectURL('creative-selection-by-frequency', CONTENT_URLS, {
    resolveToConfig: true
  });

  // Render the opaque URL into a fenced frame
  document.getElementById('content-slot').config = fencedFrameConfig;
}

injectAd();

creative-selection-by-frequency-worklet.js

const FREQUENCY_LIMIT = 5;

class CreativeSelectionByFrequencyOperation {
  async run(urls, data) {
    // Read the current frequency limit in shared storage
    const count = parseInt(await sharedStorage.get('frequency-count'));

    // Check if the frequency limit has been reached.
    if (count === FREQUENCY_LIMIT) {
      console.log('Frequency limit has been reached, and the default content will be rendered.');
      return 0;
    }

    // Set the new frequency count in shared storage
    await sharedStorage.set('frequency-count', count + 1);
    return 1;
  }
}

// Register the operation as 'creative-selection-by-frequency'.
register('creative-selection-by-frequency', CreativeSelectionByFrequencyOperation);

Use cases

All available use cases for Select URL API can be found in this section. We'll continue to add examples as we receive feedback and discover new test cases.

Engage and share feedback

Note that the Select URL API proposal is under active discussion and development and subject to change.

We're eager to hear your thoughts on the Select URL API.

Stay Informed

  • Mailing List: Subscribe to our mailing list for the latest updates and announcements related to the Select URL and Shared Storage APIs.

Need Help?