了解 Android 上的 Topics API 以及实现该 API 的步骤。您也可以直接实现主题。
How the Topics API works
The Topics API can be used to observe and provide access to topics that appear to be of interest to the user, based on their activity. The Topics API can then give API callers (such as ad tech platforms) access to a user's topics of interest, but without revealing additional information about the user's activity.
Key concepts
- A topic is a human-readable topic of interest for the current user and is part of the Topics taxonomy.
- A caller is an entity, such as an app, a third-party SDK, a website, or service, that makes a request to the Topics API to observe or access a user's interests.
- A topic is observed by a caller, if the caller made a Topics API request from a web page or app associated with this topic during the past three epochs.
- An epoch is a period of topic computation, which defaults to one week.
- A taxonomy is a hierarchical list of categories, which includes, for example, such categories as
/Arts & Entertainment/Music & Audio/Soul & R&B
and/Business & Industrial/Business Services/Corporate Events
. - Topics are derived using a classifier model that maps user activity to zero or more topics.
Topics API flow core steps
The Topics API lifecycle has three main steps:
- Observe user activity, such as when they visit the web page
https://cats.example/tabby/index.html
or download the appcats
. - Derive topics from user activity, for example
/Pets & Animals/Pets/Cats
. - Access topics previously observed for the user, for example as a signal to select relevant advertising (such as a cat food promotion).
Observe topics
Callers can only access topics of interest that they've observed. A caller observes a topic when they make a Topics API request from a context associated with this topic. To illustrate this concept, consider the following simplified example.
- Suppose there are two Topics API callers: A and B.
- There are two contexts:
- Greenhouse, for example an app named Greenhouse or a website greenhouse.example, associated with the topic
Home & Garden
. - Tennis exercises, for example an app named Tennis Exercises or a website tennis.example, associated with the topic
Sports/Tennis
.
- Greenhouse, for example an app named Greenhouse or a website greenhouse.example, associated with the topic
- Both caller A and B are present in the context of Greenhouse.
- Only the caller B is present in the context of Tennis exercises.
- Assume that no topics were observed for the user before epoch 1, for the sake of simplification.
- The user visits the Greenhouse app, and callers A and B make a Topics API call to record the user visit to the page or app (see the implementation guide suggested in Next steps to find out how to call the Topics API). This record (a hostname or app data) is later used to derive topics of interest. The Topics API will later mark the topic
Home & Garden
as observed by both callers A and B. - The user visits the Tennis exercises app. Only the caller B sends a Topics API request. The Topics API will later mark the topic
Sports/Tennis
as observed by the caller B. - By the end of the epoch, the Topics API refreshes the user's top topics and determines the callers that observed these topics based on user activity.
- Later, when the caller B makes another Topics API call, it can get either
Home & Garden
orSports/Tennis
topic (or, with a 5% chance, a random topic) for this user in the response array. - Caller A can only access the topic
Home & Garden
, as it has never observed the topicSports/Tennis
. This means that a third-party will only learn about a user's topic of interest within the specific context (app or website) where it is present.

Derive topics
Topics derives topics of interest from user activity. The topics are selected from a predefined open-source taxonomy. Once per epoch, Topics refreshes the user's top five topics and the callers that observed them during the epoch. The Topics classifier model derives topics from user activity: hostname for a web page visit, app information on Android.
Caller accesses user's topics of interest
The API returns only topics that have been observed by the caller within the most recent three epochs. A maximum of three topics may be returned to a caller,one topic for each of the three recent epochs (if the caller observed topics for that epoch). The returned topics can be used by the caller to supplement any contextual information and can be combined to help find a more relevant ad for the user.
Epochs
The Topics API must ensure that the topics of interest it provides are kept up to date. The topics are inferred for a user based on their activity during a period of time known as an epoch, one week by default. Each user has their own epochs (epochs are "per user") and the initial start time is randomized.
Once each epoch, the Topics API computes the user's top five topics and determines which callers observed those topics using on-device information. The topic selected for each epoch is randomly selected from the user's top five topics for that time period. To further enhance privacy and ensure that all topics may be represented, there is a 5% chance the topic is randomly selected from all possible topics in the taxonomy of interests.
Android 主题的实际应用
Topics API on Android 旨在支持通常在多个应用中运行的第三方广告 SDK。Topics 会根据用户的应用使用情况,为调用方提供粗略的兴趣主题以用于投放广告,而无需依赖跨应用标识符。这些主题可用于补充与想要展示广告的应用相关的任何情境信息,也可组合在一起以帮助为用户选择合适的广告。
在 Topics API 中,买方和广告客户依赖于卖方。 卖方在发布商的应用中广泛展示广告,并观察用户的兴趣主题,然后与买方分享这些主题,以帮助他们选择更相关的广告。若要获取主题,卖方应用和 SDK 必须至少在一个周期内成为 Topics API 的观察者,从而建立足迹。
请参阅 Topics API 实现指南中的相关代码示例,了解如何为“针对用户兴趣投放广告”设置主题提取功能。
按业务类型的主题集成
使用 Topics API 启用IBA(针对用户兴趣投放广告)。根据您的广告技术业务类型,按照相应步骤集成 Topics API,为发布做好准备。
适用于所有广告技术平台
- 查看主题分类并提供反馈。
- 尝试使用 Topics API 示例应用,查看设备端分类器会返回哪些主题数据。
- 更新应用和 SDK 流程以开始调用 Topics API。
- 更新方案以开始在广告请求中发送主题。
- 在 Privacy Sandbox 中注册您的广告技术平台。
适用于卖方广告技术平台
- 成为观察者,建立 Topics API 足迹。Topics API 提供了一个新信号,因此您需要更新 SDK 才能开始调用 Topics API。为了以一致的方式检索主题,您的 SDK 必须每个周期至少从发布商应用调用一次该 API。系统最多要用 4 个周期来获取随广告请求一同发送的最大数量的主题(3 个主题)。
- 在广告请求中包含 Topics API 信息。针对每个广告请求,开始与买方合作伙伴共享您的 Topics API 数据。Topics API 计划对其他信号(例如情境信号)进行补充,以帮助为指定访问者找到合适的广告。
- 通过协作创建与您的买方合作伙伴共享主题的方案。Topics API 要求每个 SDK 与下游合作伙伴就如何共享 Topics API 数据达成一致。
适用于买方广告技术平台
- 与卖方合作伙伴联系,确认他们观察主题并建立足迹的计划。若要接收主题,卖方提供者必须在每个周期至少调用一次 Topics API。
- 通过协作创建从卖方合作伙伴接收主题的方案。主题是一个新的信号,卖方合作伙伴将在广告请求中共享该信号。买方消费者需要确保与上游合作伙伴就如何分享主题开展合作。
- 将主题整合到出价和优化模型中。Topics API 应对内容相关等其他信号进行补充,以便帮助为访问者找到合适的广告。
Topics API 如何为应用推断主题
在 Android 上,Topics API 会使用分类器模型根据应用信息推断应用的主题。在当前实现中,Topics 使用应用和软件包名称为应用分配兴趣主题,但日后可能会扩展为包含应用说明等其他信息。
主题分类器
兴趣主题衍生自基于公开的应用信息进行训练的分类器模型。
- 在使用分类器模型进行推理以计算给定周期的主题时,所用的那组信号会保留在设备上。这组信号可能包含已安装的应用或最近使用过的应用,之后还可能会进行扩展,以包含其他信号。
- V5 模型由 Google 使用来自 Google Play 商店等应用商店的 54 万条人工标记的公开应用信息和 1700 万条机器学习标记的公开应用信息进行训练。该模型使用应用名称和软件包名称作为输入信号,可供应用开发者免费使用,以便测试其应用会归类为哪些主题。
- 应用可能会映射到多个主题,可能未映射到任何主题,也可能未向用户的主题历史记录添加任何内容。如果某个应用映射到分类中的多个主题,为此应用选择的主题数量将按上限限定为 3 个。
如需更好地了解分类器模型的工作原理,您可以使用 Android Topics 分类器 Colab 测试不同应用数据对分类的影响
分类
主题是从预定义的开源分类中选择的。分类是公开的,可能会发生变化。您可以使用此页面顶部的反馈按钮提交建议。此分类由人工挑选,以确保其中不含敏感主题。我们会根据可在 Android 移动应用中展示的广告类别调整此分类。
Android 主题的实际应用
假设用户在设备上安装了 7 个应用:A、B、C、D、E、F 和 G。假设应用的主题分类以及这些应用中的广告技术 SDK 如下所示:
应用 | 主题分类 | 广告技术 SDK |
A | T1、T5 | ad-sdk1、ad-sdk2 |
B | T2 | ad-sdk2 |
C | T3、T6 | ad-sdk3、ad-sdk4 |
D | T1、T4 | ad-sdk1 |
E | T5 | ad-sdk4、ad-sdk5 |
F | T6 | ad-sdk2、ad-sdk3、ad-sdk4 |
G | T7 | ad-sdk2 |
第 1 周结束时:Topics API 会针对此周期生成用户的 5 个首要主题。
首要主题 | 可获悉此主题的调用方 |
T1 | ad-sdk1、ad-sdk2 |
T2 | ad-sdk2 |
T3 | ad-sdk3、ad-sdk4 |
T4 | ad-sdk1 |
T5 | ad-sdk1、ad-sdk2、ad-sdk4、ad-sdk5 |
在第 2 周,如果任何应用中的某个调用方调用此 API,返回的主题列表将仅包含符合以下条件的主题:该调用方包含在主题在相应周期内针对相关应用的“可获取此主题的调用方”列中。
- 计算每个调用方可用的主题时用到的历史期限为 3 个周期(或 3 周)。
- 仅使用与通过广告 SDK 调用 Topics API 的应用相关联的主题。这意味着,如果某个应用不包含任何调用 Topics API 的广告 SDK,与该应用相关联的主题便不会纳入广告 SDK 可访问的主题池。
- 应用还可以明确停用 Topics API。每周主题的计算不会考虑与选择停用的应用相关联的主题。本文档的内容会进行更新,以包含相关实现详情。
如果应用使用情况数据不足,导致平台无法推断出 5 个主题,平台可能会考虑随机生成剩余主题等选项。
返回的主题的加密
调用 Topics API 的已注册广告技术平台还必须提供加密密钥,以确保只有调用方可以读取返回的主题。
Privacy Sandbox 将从广告技术平台提供的端点提取这些密钥。我们建议的最佳实践是,密钥应定期更新,但间隔时间不长于每 6 个月一次。
在注册过程中,Privacy Sandbox 会要求广告技术平台确认其提供的端点是否可用。如需详细了解当前注册的和新注册的广告技术平台要求采取的操作,请参阅注册指南
Next steps
Implement Topics
Control & transparency
See also
Check out our resources to better understand the Topics API on Android.
- Check out Topics sample apps, collab and walkthrough videos.
- See how users and developers can control the API.
- Check out the support resources to ask questions, engage and share feedback.