Czasami określa się ją jako „efektywną częstotliwość”. do rozpoznania lub rozpoznania przez użytkownika określonej zawartości (często w kontekście wyświetleń reklam) występuje często minimalna liczba wyświetleń. Udostępniana pamięć masowa może służyć do tworzenia raportów o unikalnych użytkownikach, którzy widzieli daną treść co najmniej tysiąc razy.
Shared Storage API to interfejs Privacy, Propozycja piaskownicy do zwykłych obciążeń, pamięci w wielu witrynach, która obsługuje wiele możliwych zastosowań. Private Aggregation API to dane wyjściowe dostępne w pamięci współdzielonej, które umożliwiają agregowanie danych z różnych witryn.
Wypróbuj pomiar częstotliwości K+
Aby eksperymentować z pomiarem częstotliwości K+ za pomocą pamięci współdzielonej i agregacji prywatnej, sprawdź, czy używasz Chrome w wersji M107 lub nowszej. Włącz wszystkie interfejsy Ad Privacy API w sekcji chrome://settings/adPrivacy
.
Możesz też włączyć pamięć współdzieloną, używając flagi --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames
w wierszu poleceń.
Eksperyment z przykładowym kodem
Możesz mierzyć liczbę użytkowników, którzy wyświetlili Twoje treści K lub więcej razy danemu klientowi w różnych witrynach. W tym przykładzie liczba wyświetleń jest dodawana do pamięci współdzielonej, gdzie przy każdym wczytaniu treści zwiększa się o 1. Gdy liczba wyświetleń osiągnie 3, wywoływany jest interfejs Private Aggregation API. Wymiar identyfikatora treści jest zakodowany jako klucz agregacji, a licznik – jako wartość agregująca. Zawiera on informacje takie jak „Około 391 użytkowników widziało identyfikator kampanii reklamowej 123 co najmniej 3 razy”.
W tym przykładzie:
- Narzędzie
k-frequency-measurement.js
jest ładowane za pomocą ramki i odpowiada za wczytanie Workletu pamięci współdzielonej. k-frequency-measurement-worklet.js
to Worklet pamięci współdzielonej, który odczytuje liczbę wyświetleń w pamięci współdzielonej 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();
k-frequency-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 simply 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);
// Do not 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 via 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.