Conduzir testes A/B

usar uma worklet de armazenamento compartilhado para executar testes A/B.

A API Shared Storage é uma proposta do Sandbox de privacidade para armazenamento entre sites de uso geral e compatível com muitos casos de uso possíveis. Um exemplo desse tipo é o teste A/B, disponível para testes no Chrome 104.0.5086.0 e versões mais recentes.

Você pode atribuir um usuário a um grupo experimental e, em seguida, armazenar esse grupo no armazenamento compartilhado para ser acessado em um ambiente entre sites.

Faça o teste A/B

Para fazer testes A/B com o armazenamento compartilhado, confirme se você está usando o Chrome 104.0.5086.0 ou uma versão mais recente. Em seguida, ative a flag de experimento das APIs de anúncios do Sandbox de privacidade em chrome://flags/#privacy-sandbox-ads-apis.

Ative o experimento das APIs de anúncios do Sandbox de privacidade para usar essas APIs

Também é possível ativar o armazenamento compartilhado com a sinalização --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames na linha de comando.

Testar exemplos de código

Para ver se um experimento tem o efeito desejado, faça um teste A/B em vários sites. Como anunciante ou produtor de conteúdo, você pode renderizar conteúdos ou anúncios diferentes com base no grupo a que o usuário está atribuído. A atribuição do grupo é salva no armazenamento compartilhado, mas não pode ser exfiltrada.

Neste exemplo:

  • ab-testing.js precisa ser incorporado em um frame, que mapeia o conteúdo de um controle e de dois experimentos. O script chama a worklet de armazenamento compartilhado do experimento.
  • ab-testing-worklet.js é a worklet de armazenamento compartilhado que retorna a qual grupo o usuário foi atribuído, determinando qual anúncio é exibido.

ab-testing.js (link em inglês)

// Randomly assigns a user to a group 0 or 1
function getExperimentGroup() {
  return Math.round(Math.random());
}

async function injectContent() {
  // Register the Shared Storage worklet
  await window.sharedStorage.worklet.addModule('ab-testing-worklet.js');

  // Assign user to a random group (0 or 1) and store it in Shared Storage
  window.sharedStorage.set('ab-testing-group', getExperimentGroup(), {
    ignoreIfPresent: true,
  });

  // Run the URL selection operation
  const fencedFrameConfig = await window.sharedStorage.selectURL(
    'ab-testing',
    [
      { url: `https://your-server.example/content/default-content.html` },
      { url: `https://your-server.example/content/experiment-content-a.html` }
    ],
    {
      resolveToConfig: true
    }
  );

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

injectContent();

ab-testing-worklet.js (link em inglês)

class SelectURLOperation {
  async run(urls, data) {
    // Read the user's experiment group from Shared Storage
    const experimentGroup = await this.sharedStorage.get('ab-testing-group');

    // Return the corresponding URL (first or second item in the array)
    return urls.indexOf(experimentGroup);
  }
}

register('ab-testing', SelectURLOperation);

Use cases

These are only some of the possible use cases for Shared Storage. We'll continue to add examples as we receive feedback and discover new use cases.

Content selection

Select and display different content on different websites in fenced frames based on information collected in Shared Storage. The output gate for these use cases is URL selection.

  • Creative rotation: Store data, such as creative ID, view counts, and user interaction, to determine which creative users' see across different sites.
  • A/B testing: You can assign a user to an experiment group, then store that group in Shared Storage to be accessed cross-site.
  • Custom user experiences: Share custom content and calls-to-action based on a user's registration status or other user states

Generate summary reports

Collect information with Shared Storage and generated a noisy, aggregated summary report. The output gate for these use cases is the Private Aggregation API.

  • Unique reach measurement: Many content producers and advertisers want to know how many unique people saw their content. Use Shared Storage to record the first time a user saw your ad, embedded video, or publication, and prevent duplicative counting of that same user on different sites. You can then use the Private Aggregation API to output a summary report for your reach.
  • Demographics measurement: Content producers often want to understand the demographics of their audience. You can use Shared Storage to record user demographic data in a context where you have it, such as your first-party site, and use aggregated reporting to report on it across many other sites, such as embedded content.
  • K+ frequency measurement: Sometimes described as "effective frequency," there is often a minimum number views before a user will recognize or recall certain content (often in the context of advertisement views). You can use Shared Storage to build reports of unique users that have seen a piece of content at least K number of times.

Interaja e compartilhe feedback

A proposta de armazenamento compartilhado está em discussão e sujeita a mudanças no futuro. Se você testar essa API e quiser enviar seu feedback, adoraríamos ouvir.