有時也稱為「有效展示頻率」,使用者通常要觀看特定內容 (通常是廣告) 至少幾次,才會認得或記得該內容。您可以使用 Shared Storage,建立至少看過 K 次內容的不重複使用者報表。
Shared Storage API 是 Privacy Sandbox 提案,提供一般用途的跨網站儲存空間,支援多種可能用途。Private Aggregation API 是 Shared Storage 中提供的輸出內容,可讓您匯總跨網站資料。
嘗試評估 K+ 展示頻率
如要使用 Shared Storage 和 Private Aggregation 實驗 K+ 頻率評估功能,請確認您使用的是 Chrome M107 以上版本。啟用 chrome://settings/adPrivacy 下的所有廣告隱私權 API。
您也可以在指令列中使用 --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames 旗標啟用共用儲存空間。
試用程式碼範例
您可能想評估在不同網站上,看過特定客戶內容 K 次以上的使用者人數。在本例中,曝光次數會新增至共用儲存空間,且每當載入內容時,曝光次數就會增加 1。曝光次數達到 3 次時,系統會呼叫 Private Aggregation API。內容 ID 維度會編碼為匯總鍵,而計數則會做為可匯總的值。摘要報表會提供「約有 391 位使用者至少看過廣告活動 ID 123 3 次」等資訊。
在這個例子中:
k-frequency-measurement.js是透過影格載入,負責載入共用儲存空間 worklet。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();
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.