Muchos productores de contenido y anunciantes quieren saber cuántas personas únicas vieron su contenido. Usa Shared Storage para registrar la primera vez que un usuario vio tu anuncio, video incorporado o publicación, y evita el registro duplicado de ese mismo usuario en diferentes sitios. Luego, puedes usar la API de Private Aggregation para generar un informe de resumen de tu alcance.
La API de Shared Storage es una propuesta de Privacy Sandbox para el almacenamiento multisitio de uso general, que admite muchos casos de uso posibles. La API de Private Aggregation es un resultado disponible en Shared Storage que te permite agregar datos de varios sitios. Para obtener más información sobre los métodos para implementar estas mediciones, consulta nuestro informe de alcance.
Prueba la medición de alcance único
Para experimentar con la medición del alcance único con Shared Storage y Private Aggregation, confirma que estás usando Chrome M107 o una versión posterior. Habilita todas las APIs de privacidad en los anuncios en chrome://settings/adPrivacy
.
También puedes habilitar el almacenamiento compartido con la marca --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames
en la línea de comandos.
Experimenta con muestras de código
Te recomendamos que realices un seguimiento de cuántos usuarios únicos vieron tu contenido en diferentes sitios. En este ejemplo, la dimensión de ID de contenido se codifica en la clave de agregación (bucket) y el recuento se usa como el valor agregable. El informe de resumen contendrá información como "Aproximadamente 391 usuarios vieron el ID de contenido 123".
En este ejemplo:
unique-reach-measurement.js
se carga con un marco y es responsable de cargar la worklet de almacenamiento compartido.unique-reach-measurement-worklet.js
es la worklet de almacenamiento compartido que verifica la marca en el almacenamiento compartido y envía un informe con la API de 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.