有時也稱為「有效展示頻率」使用者通常必須達到一定的最低觀看次數,才能辨識或記得特定內容 (通常是廣告觀看次數)。您可以利用「共用儲存空間」為看過某項內容至少 K 次的不重複使用者建立報表,
Shared Storage API 是一項「隱私權」 一般用途的沙箱提案,支援多種 可能的用途Private Aggregation API 是共用儲存空間中的輸出項目,可讓您匯總跨網站資料。
試用 K+ 頻率評估功能
如要使用共用儲存空間和私人匯總功能進行 K+ 頻率測量結果,請確認您使用的是 Chrome M107 以上版本。啟用 chrome://settings/adPrivacy
下的所有廣告隱私權 API。
您也可以在指令列中使用 --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames
旗標啟用共用儲存空間。
使用程式碼範例進行實驗
建議您評估在各種網站上看過您內容 K 次以上特定客戶的次數。在這個範例中,曝光次數會併入共用儲存空間,內容載入時就會增加 1。當曝光次數達到 3 次時,系統會呼叫 Private Aggregation API。系統會將 Content ID 維度編碼為匯總鍵,並做為可匯總值使用。摘要報表會提供「大約 391 名使用者看過廣告活動 ID 123 至少 3 次」等資訊。
在這個例子中:
k-frequency-measurement.js
是透過框架載入,並負責載入共用儲存空間工作程式。k-frequency-measurement-worklet.js
是共用儲存空間工作程式,可讀取共用儲存空間中的曝光次數,並透過 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.