受限广告让应用 可以在用户不同意共享个人数据的情况下投放广告。 受限广告模式会停止出于广告选择目的而收集、共享和使用个人数据。如果用户选择不共享个人数据,此功能可让广告继续投放。
本指南介绍了如何在应用中使用受限广告设置,以及如何使应用行为与 Google Ad Manager 广告资源网的全局设置保持一致。
配置客户端受限广告设置
PAL 1.109.0 版引入了 forceLimitedAds 属性,并移除了 allowStorage 属性。此属性位于
ConsentSettings
类中。
从 1.109.0 版开始,PAL 会从设备读取透明度和用户意见征求框架 (TCF) 数据,以确定用户是否同意访问本地存储数据。以前,您的应用负责确定存储意见征求。您的应用仍必须在广告代码网址中传递 gdpr= 和 gdpr_consent= 参数。
如果基于 TCF 的自动确定不足以满足需求,请直接在应用中设置
forceLimitedAds 属性。如需了解详情,请参阅
发布商集成 IAB Europe TCF。
将 forceLimitedAds 属性设置为 true 值可防止 PAL 在发送到服务器的 nonce 中存储或发送用户标识符。
将 forceLimitedAds 属性设置为 true 值与在 IMA(互动式媒体广告)SDK 中向广告请求网址添加 ltd=1 参数的效果相同。如需详细了解受限广告,请参阅
ltd(受限广告)。
当您将 forceLimitedAds 属性设置为 true 值时,PAL 会在 nonce 中添加 ltd=1 参数。
为了在应用中保留当前运作机制,您可能需要更新实现方式;即使您之前没有设置过 allowStorage 属性,也需要更新。allowStorage 属性默认设置为 false 值,这会 启用 受限广告。forceLimitedAds 属性默认设置为 false
值,这 不会启用 受限广告。
与 Google Ad Manager 全局设置保持一致
如果您更新了 Ad Manager 设置程序化受限广告 或 允许将第一方 Cookie 用于在 网站中展示的 广告, 请使用这些新 API 使其与 Ad Manager 中的设置保持一致。如果您不使用这些 API,PAL 可能会在广告请求中使用的 nonce 中添加标识符。不过,Ad Manager 可能会根据 Ad Manager 中的设置舍弃这些信号。
这些 API 如下所示:
disableLimitedAdsStorage- 停用仅用于检测无效流量的 Cookie,并禁止将本地存储用于受限广告。如果您在 Ad Manager 中更新了程序化受限广告 设置(位于管理 > 全局设置 下),请使用此 API 禁止 PAL 将本地存储用于受限广告。请注意,此设置不适用于非受限广告。disableFirstPartyIdentifiers- 停用用于广告选择的第一方标识符。如果您在 Ad Manager 中更新了允许将第一方 Cookie 用于在网站中展示的广告 设置(位于管理 > 全局 设置下),请使用此 API 禁止 PAL 使用此类标识符。请注意,此设置不适用于将 Cookie 和本地存储用于检测无效流量。
在应用中处理用户同意
以下示例介绍了如何在 PAL 实现中处理用户隐私和数据使用情况:
const consentSettings = new goog.pal.ConsentSettings();
consentSettings.allowStorage = true;
// During the PAL Phase 1 release, best practice is to always set the
// `allowStorage` property to a `true` value to allow PAL to automatically
// determine whether limited ads applies based on the TCF data.
// To enable limited ads regardless of the TCF determination, set the
// `forceLimitedAds` property to a `true` value.
const adManagerSettings = new goog.pal.GoogleAdManagerSettings();
// Add this line if the "Programmatic limited ads" toggle is turned off in
// Ad Manager.
adManagerSettings.disableLimitedAdsStorage = true;
// Add this line if the "First party cookies for ads on web" toggle
// is turned off in Ad Manager.
adManagerSettings.disableFirstPartyIdentifiers = true;
const nonceLoader = new goog.pal.NonceLoader(consentSettings, adManagerSettings);