有時觀看次數會高於「有效展示頻率」,通常在使用者發現或想回特定內容時,至少會達到最低觀看次數門檻 (通常是透過廣告觀看)。您可以使用「共用儲存空間」建立報表,記錄有多少不重複使用者看過至少 K 的內容。
Shared Storage API 是 Privacy Sandbox 提案之一,適用於一般用途的跨網站儲存空間。這個 API 支援許多可能的用途。Private Aggregation API 是「共用儲存空間」提供的輸出內容,可讓您匯總跨網站資料。
試用 K+ 頻率評估
如要實驗 K+ 頻率測量、共用儲存空間及私人匯總功能,請確認您使用的是 Chrome M107 以上版本。接著,在 chrome://flags/#privacy-sandbox-ads-apis
中啟用 Privacy Sandbox Ads 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 this.sharedStorage.get(hasReportedContentKey)) === 'true';
const impressionCount = parseInt((await this.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 this.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.sendHistogramReport({ bucket, value });
// Set the report submission status flag
await this.sharedStorage.set(hasReportedContentKey, 'true');
}
}
// Register the operation
register('k-freq-measurement', KFreqMeasurementOperation); \
交流及分享意見回饋
共用儲存空間提案仍在進行中的討論,日後可能會有變動。如果您試用這個 API,並有任何意見,歡迎與我們分享。
- GitHub:閱讀提案、提出疑問並參與討論。
- Shared Storage API 公告:透過郵寄清單加入或查看過去的公告
- 開發人員支援:在 Privacy Sandbox 開發人員支援存放區中提問及參與討論。