許多內容製作者和廣告客戶都想知道有多少不重複使用者看過他們的內容。使用「共用儲存空間」記錄使用者第一次看到您的廣告、內嵌影片或發布內容,即可避免在相同網站上重複計算同一位使用者。接著,您可以使用 Private Aggregation API 輸出觸及率的摘要報表。
Shared Storage API 是適用於一般用途的跨網站儲存空間 Privacy Sandbox 提案,可支援許多可能的用途。Private Aggregation API 是共用儲存空間中的輸出項目,可讓您匯總跨網站資料。
試用不重複觸及率評估功能
如要嘗試使用共用儲存空間和私人匯總功能進行不重複觸及率評估,請確認您使用的是 Chrome M107 以上版本。啟用 chrome://settings/adPrivacy
下的所有廣告隱私權 API。
您也可以在指令列中使用 --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames
旗標啟用共用儲存空間。
使用程式碼範例進行實驗
建議您追蹤有多少不重複使用者在不同網站上看過您的內容。在這個範例中,Content ID ���度是������成匯總鍵 (值區),而計數會做為可匯總值使用。摘要報告會附上各種資訊,例如「約有 391 位使用者看過 Content ID 123」。
在此範例中:* unique-reach-measurement.js
是透過框架載入,並負責載入共用儲存空間工作程式。* unique-reach-measurement-worklet.js
是共用儲存空間工作程式,可檢查共用儲存空間中的旗標,並透過 Private Aggregation API 傳送報告。
async function measureUniqueReach() {
// Load the Shared Storage worklet
await window.sharedStorage.worklet.addModule('reach-measurement-worklet.js');
// Run the reach measurement operation
await window.sharedStorage.run('reach-measurement', { data: { contentId: '1234' } });
}
measureUniqueReach();
// Learn more about noise and scaling from the Private Aggregation fundamentals
// documentation on Chrome blog
const SCALE_FACTOR = 65536;
function convertContentIdToBucket(contentId) {
return BigInt(contentId);
}
class ReachMeasurementOperation {
async run(data) {
const { contentId } = data;
// Read from Shared Storage
const key = 'has-reported-content';
const hasReportedContent = (await this.sharedStorage.get(key)) === 'true';
// Do not report if a report has been sent already
if (hasReportedContent) {
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 this.sharedStorage.set(key, true);
}
}
// Register the operation
register('reach-measurement', ReachMeasurementOperation);
交流及分享意見回饋
共用儲存空間提案仍在進行中的討論,日後可能會有變動。如果您���用這個 API,並有任何意見,歡迎與我們分享。
- GitHub:閱讀提案、提出疑問並參與討論。
- Shared Storage API 公告:透過郵寄清單加入或查看過去的公告
- 開發人員支援:在 Privacy Sandbox 開發人員支援存放區中提問及參與討論。