Często określa się ją jako „efektywną częstotliwość”. Zwykle istnieje minimalna liczba wyświetleń, po której użytkownik rozpoznaje lub zapamiętuje określone treści (często w kontekście wyświetleń reklam). Za pomocą interfejsu Shared Storage możesz tworzyć raporty o unikalnych użytkownikach, którzy wyświetlili daną treść co najmniej K razy.
Shared Storage API to propozycja w ramach Piaskownicy prywatności dotycząca ogólnego przeznaczenia pamięci między witrynami, która obsługuje wiele możliwych przypadków użycia. Private Aggregation API to dane wyjściowe dostępne w Shared Storage, które umożliwiają agregowanie danych z różnych witryn.
Pomiar częstotliwości K+
Aby eksperymentować z pomiarem częstotliwości K+ za pomocą pamięci współdzielonej i prywatnej agregacji, upewnij się, że używasz Chrome w wersji M107 lub nowszej. Włącz wszystkie interfejsy API ochrony prywatności w reklamach w sekcji chrome://settings/adPrivacy.
Pamięć współdzieloną możesz też włączyć za pomocą flagi --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames w wierszu poleceń.
Eksperymentowanie z przykładowymi fragmentami kodu
Możesz chcieć zmierzyć liczbę użytkowników, którzy widzieli Twoje treści co najmniej K razy w przypadku danego klienta w różnych witrynach. W tym przykładzie liczba wyświetleń jest dodawana do pamięci współdzielonej, w której zwiększa się o 1 za każdym razem, gdy treść jest wczytywana. Gdy liczba wyświetleń osiągnie 3, wywoływany jest interfejs Private Aggregation API. Wymiar identyfikatora treści jest kodowany jako klucz agregacji, a liczba jest używana jako wartość podlegająca agregacji. Raport podsumowujący będzie zawierać informacje takie jak „Około 391 użytkowników zobaczyło kampanię reklamową o identyfikatorze 123 co najmniej 3 razy”.
W tym przykładzie:
k-frequency-measurement.jsjest wczytywany za pomocą ramki i odpowiada za wczytywanie workletu pamięci współdzielonej.k-frequency-measurement-worklet.jsto element roboczy Shared Storage, który odczytuje liczbę wyświetleń w Shared Storage i wysyła raport za pomocą interfejsu Private Aggregation API.
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.