为已知客户定制用户体验

使用共享存储空间 Worklet 识别已知客户。

Shared Storage API 是一个适用于通用跨站存储的 Privacy Sandbox 提案,支持许多可能的用例。例如,识别已知客户,可在 Chrome 104.0.5086.0 及更高版本中测试。

您可以将用户是否在您网站上注册过的信息存储到共享存储空间中,然后根据用户的存储状态(该用户是否为“已知”客户)呈现单独的元素。

设置已知客户

如要尝试识别共享存储空间中的已知客户,请确认您使用的是 Chrome 104.0.5086.0 或更高版本。启用 chrome://settings/adPrivacy 下的所有广告隐私权 API。

您还可以在命令行中使用 --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames 标志启用共享存储空间。

试用代码示例

您可能希望根据用户是否在其他网站上看到相应用户来呈现不同的元素。例如,付款服务机构可能希望根据用户是否已在其网站上注册来显示“注册”或“立即购买”按钮。共享存储空间可用于设置用户的状态,并根据该状态自定义用户体验。

在此示例中:

  • known-customer.js 嵌入在帧中。此脚本设置各种选项,即应在网站上显示哪个按钮:“注册”或“立即购买”。
  • known-customer-worklet.js 是确定用户是否为已知用户的共享存储空间 Worklet。如果已知用户,则返回该信息。如果用户未知,系统会返回该信息以显示“注册”按钮,并将用户标记为将来已知。

known-customer.js

// 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();

known-customer-worklet.js

class SelectURLOperation {
  async run(urls) {
    const knownCustomer = await this.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 并有反馈意见,我们非常期待收到您的反馈意见。