Customize user experience for known customers

Use a Shared Storage worklet to identify known customers.

The Shared Storage API is a Privacy Sandbox proposal for general purpose, cross-site storage, which supports many possible use cases. One example is identifying known customers, which is available to test in Chrome 104.0.5086.0 and later.

You can store whether the user has registered on your site into Shared Storage, then render a separate element based on whether the user's stored status (is the user a "known" customer).

Set known customers

To experiment with identifying known customers in Shared Storage, confirm you're using Chrome 104.0.5086.0 or later. Enable all the Ad privacy APIs under chrome://settings/adPrivacy.

You can also enable Shared Storage with the --enable-features=PrivacySandboxAdsAPIsOverride,OverridePrivacySandboxSettingsLocalTesting,SharedStorageAPI,FencedFrames flag in the command line.

Experiment with code samples

You may want to render a different element based on whether the user was seen on a different site. For example, a payment provider may want to render a "Register" or "Buy now" button based on whether the user has registered at the payment provider's site. Shared storage can be used to set the user's status and customize their user experience based on that status.

In this example:

  • known-customer.js is embedded in a frame. This script sets the options for which button should be displayed on a site, "Register" or "Buy now."
  • known-customer-worklet.js is the shared storage worklet that determines if the user is known. If the user is known, the information is returned. If the user is unknown, that information is returned to display the "Register" button and the user is marked as known for the future.

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 sharedStorage.get('known-customer');

    // '0' is unknown and '1' is known
    return parseInt(knownCustomer);
  }
}

register('known-customer', SelectURLOperation);

使用场景

以上只是共享存储空间的一部分用例。我们将 我们会继续添加样本, 获取反馈 并发现新的应用场景

内容选择

在以下位置选择和显示不同网站上的不同内容: 围栏框架 共享存储空间这些用例的输出门控是网址选择。

  • 广告素材轮播: 存储广告素材 ID、观看次数和用户互动等数据,以确定哪个广告素材在不同网站上的呈现效果
  • A/B 测试: 您可以将用户分配到实验组,然后将该组存储在共享存储空间中,以便跨网站访问。
  • 自定义用户体验: 根据用户的注册状态或其他用户状态共享自定义内容和号召性用语

生成摘要报告

通过共享存储空间收集信息,并生成杂乱的汇总摘要报告。这些用例的输出门控是 Private Aggregation API

  • 唯一身份用户覆盖面衡量: 许多内容制作者和广告客户都想知道 人查看了他们的内容。使用共享存储空间记录用户首次访问 用户看过您的广告、嵌入式视频或发布内容,并防止重复 统计不同网站上的同一用户然后,您可以使用 Private Aggregation API 输出覆盖面的摘要报告。
  • 受众特征衡量: 内容制作者通常希望了解其网站的受众特征 受众群体。您可以使用共享存储空间来记录 背景信息(例如您的第一方网站),并使用汇总的数据 以便在其他许多网站(例如嵌入式内容)中生成此报告。
  • K+ 频次衡量: 有时也称为“有效频次”通常会有一个 用户会认出或回想某些内容(通常在 广告观看情境)。您可以使用共享存储空间生成报告 的唯一身份用户中,特定内容至少浏览了 K 次。

Engage and share feedback

The Shared Storage proposal is under active discussion and subject to change in the future. If you try this API and have feedback, we'd love to hear it.