許多內容製作者和廣告主都想知道有多少不重複使用者看過自己的內容。使用 Shared Storage 記錄使用者首次看到廣告、內嵌影片或出版物的時間,並避免在不同網站上重複計算同一位使用者。然後使用 Private Aggregation API 輸出觸及率的摘要報表。
Shared Storage API 是 Privacy Sandbox 提案,提供一般用途的跨網站儲存空間,支援多種可能用途。Private Aggregation API 是 Shared Storage 中提供的輸出內容,可讓您匯總跨網站資料。 如要進一步瞭解如何實作這些評估指標,請參閱觸及數白皮書。
試用不重複觸及評估功能
如要使用共用儲存空間和私密匯總功能實驗不重複到達率評估,請確認您使用的是 Chrome M107 以上版本。啟用 chrome://settings/adPrivacy 下的所有廣告隱私權 API。
您也可以在指令列中使用 --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames 旗標啟用共用儲存空間。
試用程式碼範例
您可能想追蹤不同網站上看到您內容的不重複使用者人數。在本範例中,內容 ID 維度會編碼為匯總鍵 (buckets),而計數則會做為可匯總的值。摘要報表會包含「約有 391 位使用者看過內容 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 sharedStorage.get(key)) === 'true';
// Don't 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 using the Private Aggregation API
privateAggregation.contributeToHistogram({ bucket, value });
// Set the report submission status flag
await sharedStorage.set(key, true);
}
}
// Register the operation
register('reach-measurement', ReachMeasurementOperation);
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.