有時稱為「有效展示頻率」,使用者必須看到一定次數的廣告,才會認出或回想特定內容 (通常是在廣告觀看的情況下)。您可以使用 Shared Storage 建立報表,針對至少看過某項內容 K 次的不重複使用者進行分析。
Shared Storage API 是一種 Privacy Sandbox 提案,可用於一般用途的跨網站儲存空間,支援多種可能的用途。Private Aggregation API 是 Shared Storage 中的輸出內容,可讓您匯總跨網站資料。
嘗試使用 K+ 展示頻率評估
如要嘗試使用 K+ 頻率評估功能搭配共用儲存空間和私人匯總,請確認您使用的是 Chrome M107 以上版本。啟用 chrome://settings/adPrivacy
下方的所有廣告隱私權 API。
您也可以在指令列中使用 --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames
旗標啟用共用儲存空間。
嘗試使用程式碼範例
您可能想評估在不同網站上,有多少使用者看過特定客戶的內容 K 次以上。在這個範例中,曝光次數會加入至共用儲存空間,每次載入內容時就會增加 1 次。當曝光次數達到 3 次時,系統會呼叫 Private Aggregation API。系統會將內容 ID 維度編碼為匯總鍵,並將計數用作可匯總的值。摘要報表會提供「約 391 位使用者至少看過 3 次廣告活動 ID 123」等資訊。
在這個例子中:
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();
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); \
互動並分享意見回饋
請注意,Shared Storage API 提案仍在積極討論和開發中,因此可能會有變動。
我們很期待聽到您對 Shared Storage API 的想法。
掌握最新消息
- 電子報:訂閱我們的電子報,即可取得與 Shared Storage API 相關的最新消息和公告。
需要協助嗎?
- 開發人員支援:在 Privacy Sandbox 開發人員支援存放區中與其他開發人員互動,並取得問題解答。