Muitos produtores de conteúdo e anunciantes querem saber quantas pessoas únicas acessaram o conteúdo deles. Use o Shared Storage para registrar a primeira vez que um usuário visualizou seu anúncio, vídeo incorporado ou publicação e evitar a contagem duplicada desse mesmo usuário em sites diferentes. Em seguida, use a API Private Aggregation para gerar um relatório de resumo do seu alcance.
A API Shared Storage é uma proposta do Sandbox de privacidade para armazenamento entre sites de finalidade geral, que oferece suporte a muitos casos de uso. A API Private Aggregation é uma saída disponível na Shared Storage que permite agregar dados entre sites. Para saber mais sobre os métodos de implementação dessas medições, consulte nosso artigo sobre alcance.
Testar a medição do alcance único
Para testar a medição de alcance único com o Shared Storage e a Private Aggregation, confirme se você está usando o Chrome M107 ou mais recente. Ative todas as APIs de privacidade de anúncios em chrome://settings/adPrivacy
.
Também é possível ativar o armazenamento compartilhado com a flag --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames
na linha de comando.
Testar exemplos de código
Você pode acompanhar quantos usuários únicos acessaram seu conteúdo em diferentes sites. Neste exemplo, a dimensão do ID de conteúdo é codificada na chave de agregação (bucket) e a contagem é usada como o valor agregável. O relatório resumido vai conter informações como "Aproximadamente 391 usuários visualizaram o ID de conteúdo 123".
Neste exemplo:
- O
unique-reach-measurement.js
é carregado usando um frame e é responsável por carregar o worklet de armazenamento compartilhado. unique-reach-measurement-worklet.js
é o worklet de armazenamento compartilhado que verifica a flag no armazenamento compartilhado e envia um relatório usando a API Private Aggregation.
async function measureUniqueReach() {
// Load the Shared Storage worklet
await window.sharedStorage.worklet.addModule('reach-measurement-worklet.js');
// Run the reach measurement operation
await window.sharedStorage.run('reach-measurement', { data: { contentId: '1234' } });
}
measureUniqueReach();
// Learn more about noise and scaling from the Private Aggregation fundamentals
// documentation on Chrome blog
const SCALE_FACTOR = 65536;
function convertContentIdToBucket(contentId) {
return BigInt(contentId);
}
class ReachMeasurementOperation {
async run(data) {
const { contentId } = data;
// Read from Shared Storage
const key = 'has-reported-content';
const hasReportedContent = (await sharedStorage.get(key)) === 'true';
// Don't report if a report has been sent already
if (hasReportedContent) {
return;
}
// Generate the aggregation key and the aggregatable value
const bucket = convertContentIdToBucket(contentId);
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('reach-measurement', ReachMeasurementOperation);
Engage and share feedback
Note that the Shared Storage API proposal is under active discussion and development and therefore subject to change.
We're eager to hear your thoughts on the Shared Storage API.
- Proposal: Review the detailed proposal.
- Discussion: Join the ongoing discussion to ask questions and share your insights.
Stay Informed
- Mailing List: Subscribe to our mailing list for the latest updates and announcements related to the Shared Storage API.
Need Help?
- Developer Support: Connect with other developers and get answers to your questions in the Privacy Sandbox Developer Support repository.