运行共享存储空间 Worklet,以选择网址并将其呈现在围栏框架中。
Shared Storage API 是一种 适用于通用的跨站点存储的沙盒提案,支持多种 可能的使用场景。例如,频次控制 在 Chrome 测试版 104.0.5086.0 及更高版本中进行测试。
运行 Worklet 脚本,根据存储的 然后在围栏框架中呈现该网址。它可用于选择 新广告或其他内容的广告。
按频次测试广告素材选择
若要使用共享存储空间和围栏框架按频次测试广告素材选择,请确认您
使用 Chrome 104.0.5086.0 或更高版本。启用 chrome://settings/adPrivacy
下的所有广告隐私权 API。
您还可以在命令行中使用 --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames
标志启用共享存储空间。
试用代码示例
如需选择并创建一个不透明网址,请注册一个 Worklet 模块,以读取共享的 Worklet 模块 存储数据Worklet 类会收到最多包含 8 个网址的列表,然后 返回所选网址的索引。
当客户端调用 sharedStorage.selectURL()
时,worklet
执行并返回要渲染到围栏框架中的不透明网址。
假设您想根据用户之前看到广告的次数来选择其他广告或内容进行呈现。您可以统计用户看到某内容的次数,并将该值存储到共享存储空间。存储后,您就可以在不同源中使用共享存储空间中的值。
然后,共享存储空间 Worklet 会读取共享存储空间中的值,并且每增加一个视图就会递增计数器。如果计数尚未达到预定义的上限,则系统会返回要呈现的内容(索引 1
)。否则,系统会返回默认网址(索引 0
)。
在此示例中:
creative-selection-by-frequencyjs
通过内容制作者或广告客户的 iframe 加载,负责 用于加载共享存储 Worklet,并将返回的 封装到一个围栏帧中。creative-selection-by-frequency-worklet.js
是读取 频次计数,以确定为内容或广告素材返回哪个网址。
creative-selection-by-frequency.js
// The first URL is the default content or ad to be rendered when the frequency limits reached.
const CONTENT_URLS = [
{ url: `https://${contentProducerUrl}/default-content.html` },
{ url: `https://${contentProducerUrl}/example-content.html` },
];
async function injectAd() {
// Load the worklet module.
await window.sharedStorage.worklet.addModule('creative-selection-by-frequency-worklet.js');
// Set the initial frequency count
window.sharedStorage.set('frequency-count', 0, {
ignoreIfPresent: true,
});
// Run the URL selection operation to choose an ad based on the frequency count in shared storage.
const fencedFrameConfig = await window.sharedStorage.selectURL('creative-selection-by-frequency', CONTENT_URLS, {
resolveToConfig: true
});
// Render the opaque URL into a fenced frame
document.getElementById('content-slot').config = fencedFrameConfig;
}
injectAd();
creative-selection-by-frequency-worklet.js
const FREQUENCY_LIMIT = 5;
class CreativeSelectionByFrequencyOperation {
async run(urls, data) {
// Read the current frequency limit in shared storage
const count = parseInt(await sharedStorage.get('frequency-count'));
// Check if the frequency limit has been reached.
if (count === FREQUENCY_LIMIT) {
console.log('Frequency limit has been reached, and the default content will be rendered.');
return 0;
}
// Set the new frequency count in shared storage
await sharedStorage.set('frequency-count', count + 1);
return 1;
}
}
// Register the operation as 'creative-selection-by-frequency'.
register('creative-selection-by-frequency', CreativeSelectionByFrequencyOperation);
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 generate 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.
互动和分享反馈
请注意,Shared Storage API 提案正在积极讨论和开发中,因此可能会发生变化。
我们非常期待听到您对 Shared Storage API 的看法。
掌握最新动态
- 邮寄名单:订阅我们的邮寄名单,及时了解与 Shared Storage API 相关的最新动态和公告。
需要帮助?
- 开发者支持:在 Privacy Sandbox 开发者支持代码库中与其他开发者联系,并获取问题解答。