A volte descritta come "frequenza effettiva", spesso è necessario un numero minimo di visualizzazioni prima che un utente riconosca o ricordi determinati contenuti (spesso nel contesto delle visualizzazioni degli annunci). Puoi utilizzare Shared Storage per creare report sugli utenti unici che hanno visualizzato un contenuto almeno K volte.
L'API Shared Storage è una proposta di Privacy Sandbox per l'archiviazione cross-site per uso generico, che supporta molti possibili casi d'uso. L'API Private Aggregation è un output disponibile in Shared Storage che consente di aggregare i dati tra siti.
Provare la misurazione della frequenza K+
Per eseguire esperimenti sulla misurazione della frequenza K+ con lo spazio di archiviazione condiviso e l'aggregazione privata, verifica di utilizzare Chrome M107 o versioni successive. Abilita tutte le API Privacy per gli annunci in chrome://settings/adPrivacy
.
Puoi anche attivare lo spazio di archiviazione condiviso con il flag --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames
nella riga di comando.
Sperimenta con gli esempi di codice
Potresti voler misurare il numero di utenti che hanno visto i tuoi contenuti per K o più volte su un determinato cliente su siti diversi. In questo esempio, il conteggio delle impressioni viene aggiunto allo spazio di archiviazione condiviso, dove viene incrementato di 1 ogni volta che vengono caricati i contenuti. Quando il conteggio delle impressioni ha raggiunto il valore 3, viene chiamata l'API Private Aggregation. La dimensione ID contenuti viene codificata come chiave di aggregazione e il conteggio viene utilizzato come valore aggregabile. Il report di riepilogo fornirà informazioni quali "Circa 391 utenti hanno visto l'ID campagna pubblicitaria 123 almeno 3 volte".
In questo esempio:
k-frequency-measurement.js
viene caricato utilizzando un frame ed è responsabile del caricamento del worklet di archiviazione condiviso.k-frequency-measurement-worklet.js
è il worklet di archiviazione condivisa che legge il conteggio delle impressioni nello spazio di archiviazione condiviso e invia un report utilizzando l'API Private Aggregation.
k-frequency-measurement.js
async function injectContent() {
// Load the Shared Storage worklet
await window.sharedStorage.worklet.addModule('k-freq-measurement-worklet.js');
// Run the K-frequency measurement operation
await window.sharedStorage.run('k-freq-measurement', { data: { kFreq: 3, contentId: 123 });
}
injectContent();
kuency-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 just the content
* ID itself. For more complex bucket key construction, see other use cases in
* this demo.
*/
function convertContentIdToBucket(contentId) {
return BigInt(contentId);
}
class KFreqMeasurementOperation {
async run(data) {
const { kFreq, contentId } = data;
// Read from Shared Storage
const hasReportedContentKey = 'has-reported-content';
const impressionCountKey = 'impression-count';
const hasReportedContent = (await sharedStorage.get(hasReportedContentKey)) === 'true';
const impressionCount = parseInt((await sharedStorage.get(impressionCountKey)) || 0);
// Don't report if a report has been sent already
if (hasReportedContent) {
return;
}
// Check impression count against frequency limit
if (impressionCount < kFreq) {
await sharedStorage.set(impressionCountKey, impressionCount + 1);
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(hasReportedContentKey, 'true');
}
}
// Register the operation
register('k-freq-measurement', KFreqMeasurementOperation); \
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.