使用共享存储空间 Worklet 识别已知客户。
Shared Storage API 是一种 适用于通用的跨站点存储的沙盒提案,支持多种 可能的使用场景。一个例子是识别已知客户, 可在 Chrome 104.0.5086.0 及更高版本中测试。
您可以将用户是否在您网站上注册过的信息存储到共享存储空间、 然后根据用户的存储状态(是 向用户发送“已知”客户)。
设置已知客户
如要尝试识别共享存储空间中的已知客户,请确认您使用的是 Chrome 104.0.5086.0 或更高版本。启用 chrome://settings/adPrivacy
下的所有广告隐私权 API。
您还可以在命令行中使用 --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames
标志启用共享存储空间。
试用代码示例
您可能希望根据用户是否在其他网站上看到相应用户来呈现不同的元素。例如,付款服务机构可能希望显示“注册”或“立即购买”按钮。共享存储空间可用于设置用户的状态,并根据该状态自定义用户体验。
在此示例中:
known-customer.js
嵌入在帧中。此脚本设置选项,即按钮应在网站上显示,即“Register”或“立即购买”。known-customer-worklet.js
是确定用户是否为已知用户的共享存储空间 Worklet。如果已知用户,则返回该信息。如果用户未知,则返回该信息以显示“Register”按钮,并且用户会被标记为未来已知。
// The first URL for the "register" button is rendered for unknown users.
const BUTTON_URLS = [
{ url: `https://${advertiserUrl}/ads/register-button.html` },
{ url: `https://${advertiserUrl}/ads/buy-now-button.html` },
];
async function injectButton() {
// Load the worklet module
await window.sharedStorage.worklet.addModule('known-customer-worklet.js');
// Set the initial status to unknown ('0' is unknown and '1' is known)
window.sharedStorage.set('known-customer', 0, {
ignoreIfPresent: true,
});
// Run the URL selection operation to choose the button based on the user status
const fencedFrameConfig = await window.sharedStorage.selectURL('known-customer', BUTTON_URLS, {
resolveToConfig: true
});
// Render the opaque URL into a fenced frame
document.getElementById('button-slot').src = fencedFrameConfig;
}
injectButton();
class SelectURLOperation {
async run(urls) {
const knownCustomer = await sharedStorage.get('known-customer');
// '0' is unknown and '1' is known
return parseInt(knownCustomer);
}
}
register('known-customer', SelectURLOperation);
Use cases
These are only some of the possible use cases for Shared Storage. We'll continue to add examples as we receive feedback and discover new use cases.
Content selection
Select and display different content on different websites in fenced frames based on information collected in Shared Storage. The output gate for these use cases is URL selection.
- Creative rotation: Store data, such as creative ID, view counts, and user interaction, to determine which creative users' see across different sites.
- A/B testing: You can assign a user to an experiment group, then store that group in Shared Storage to be accessed cross-site.
- Custom user experiences: Share custom content and calls-to-action based on a user's registration status or other user states
Generate summary reports
Collect information with Shared Storage and generated a noisy, aggregated summary report. The output gate for these use cases is the Private Aggregation API.
- Unique reach measurement: Many content producers and advertisers want to know how many unique people saw their content. Use Shared Storage to record the first time a user saw your ad, embedded video, or publication, and prevent duplicative counting of that same user on different sites. You can then use the Private Aggregation API to output a summary report for your reach.
- Demographics measurement: Content producers often want to understand the demographics of their audience. You can use Shared Storage to record user demographic data in a context where you have it, such as your first-party site, and use aggregated reporting to report on it across many other sites, such as embedded content.
- K+ frequency measurement: Sometimes described as "effective frequency," there is often a minimum number views before a user will recognize or recall certain content (often in the context of advertisement views). You can use Shared Storage to build reports of unique users that have seen a piece of content at least K number of times.
互动和分享反馈
共享存储空间提案正在积极讨论,可能会发生变化 。如果您试用此 API 并有反馈意见,我们非常期待收到您的反馈意见。
- GitHub:阅读 提案、覆盖面白皮书、提出问题并参与讨论。
- Shared Storage API 通告:加入我们的邮寄名单,或查看以往的通告
- 开发者支持:提出问题并加入 Privacy Sandbox 开发者支持代码库。