本指南介绍了如何向 Google 移动广告 SDK 提供定位信息。
如需查看实际示例,请下载 Android API 演示版应用。前提条件
在继续操作之前,请设置 Google Mobile Ads SDK。
RequestConfiguration
RequestConfiguration 用于收集在全局范围内应用于每个广告请求的定位信息。如需查看可用的定位标记,请参阅 RequestConfiguration.Builder 文档。
若要更新请求配置,请从现有配置中获取构建器,执行任何所选的更新,然后按如下所示进行设置:
Kotlin
val requestConfiguration = MobileAds.getRequestConfiguration()
MobileAds.setRequestConfiguration(requestConfiguration)Java
RequestConfiguration requestConfiguration = MobileAds.getRequestConfiguration();
MobileAds.setRequestConfiguration(requestConfiguration);为了确保请求配置的更改能应用到所有广告请求中,请在初始化 Google Mobile Ads SDK 之前完成请求配置的设置。
设置年龄处理方式
为了帮助您遵守与儿童和青少年相关的适用隐私权法规,Google Mobile Ads SDK 提供了一项年龄处理方式设置。通过年龄处理方式设置,您可以指明 Google Mobile Ads SDK 是否应针对儿童或青少年应用特定的广告投放保护措施。使用此设置时,Google Mobile Ads SDK 会在广告请求中包含 tfat 参数。请咨询您的法律顾问,以便根据您的法律和监管义务确定适用于用户的年龄处理方式。
您可以通过 RequestConfiguration.Builder API 中的 setAgeRestrictedTreatment() 方法来设置年龄处理方式。
设置针对儿童的年龄处理方式
以下示例展示了如何指明广告请求应按针对儿童的年龄处理方式进行处理:
Java
RequestConfiguration requestConfiguration =
MobileAds.getRequestConfiguration().toBuilder()
// Indicate that ad requests should have child age treatment.
.setAgeRestrictedTreatment(AgeRestrictedTreatment.CHILD)
.build();
MobileAds.setRequestConfiguration(requestConfiguration);
Kotlin
val requestConfiguration = MobileAds.getRequestConfiguration().toBuilder()
// Indicate that ad requests should have child age treatment.
.setAgeRestrictedTreatment(AgeRestrictedTreatment.CHILD)
.build()
MobileAds.setRequestConfiguration(requestConfiguration)
设置适用于青少年的处理方式
以下示例表明广告请求应按适用于青少年的处理方式处理:
Java
RequestConfiguration requestConfiguration =
MobileAds.getRequestConfiguration().toBuilder()
// Indicate that ad requests should have teen age treatment.
.setAgeRestrictedTreatment(AgeRestrictedTreatment.TEEN)
.build();
MobileAds.setRequestConfiguration(requestConfiguration);
Kotlin
val requestConfiguration = MobileAds.getRequestConfiguration().toBuilder()
// Indicate that ad requests should have teen age treatment.
.setAgeRestrictedTreatment(AgeRestrictedTreatment.TEEN)
.build()
MobileAds.setRequestConfiguration(requestConfiguration)
设置不针对特定年龄的处理方式
以下示例展示了如何指明广告请求不应按特定年龄的处理方式进行处理:
Java
RequestConfiguration requestConfiguration =
MobileAds.getRequestConfiguration().toBuilder()
// Indicate that ad requests should have unspecified age treatment.
.setAgeRestrictedTreatment(AgeRestrictedTreatment.UNSPECIFIED)
.build();
MobileAds.setRequestConfiguration(requestConfiguration);
Kotlin
val requestConfiguration = MobileAds.getRequestConfiguration().toBuilder()
// Indicate that ad requests should have unspecified age treatment.
.setAgeRestrictedTreatment(AgeRestrictedTreatment.UNSPECIFIED)
.build()
MobileAds.setRequestConfiguration(requestConfiguration)
从 TFCD 和 TFUA 迁移到年龄处理方式
年龄处理方式设置取代了已弃用的 .setTagForChildDirectedTreatment() (TFCD) 和 .setTagForUnderAgeOfConsent() (TFUA) 设置。
下表列出了 TFCD 和 TFUA 设置及其对等的年龄处理方式:
TFCD
TFCD |
年龄处理方式 |
|---|---|
TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE |
AgeRestrictedTreatment.CHILD |
TAG_FOR_CHILD_DIRECTED_TREATMENT_FALSE |
AgeRestrictedTreatment.UNSPECIFIED |
TAG_FOR_CHILD_DIRECTED_TREATMENT_UNSPECIFIED |
AgeRestrictedTreatment.UNSPECIFIED |
未指定值 .setTagForChildDirectedTreatment() |
AgeRestrictedTreatment.UNSPECIFIED |
| (无对等处理方式) | AgeRestrictedTreatment.TEEN |
TFUA
TFUA |
年龄处理方式 |
|---|---|
TAG_FOR_UNDER_AGE_OF_CONSENT_TRUE |
AgeRestrictedTreatment.CHILD |
TAG_FOR_UNDER_AGE_OF_CONSENT_FALSE |
AgeRestrictedTreatment.UNSPECIFIED |
TAG_FOR_UNDER_AGE_OF_CONSENT_UNSPECIFIED |
AgeRestrictedTreatment.UNSPECIFIED |
未指定价值 .setTagForUnderAgeOfConsent() |
AgeRestrictedTreatment.UNSPECIFIED |
| (无对等处理方式) | AgeRestrictedTreatment.TEEN |
了解年龄处理方式与 TFCD 和 TFUA 的相互作用
如果您同时设置了年龄处理方式和 TFCD/TFUA,Google 会采用最保守的处理方式。
面向儿童的设置
为了遵守《儿童在线隐私保护法》(COPPA) 的规定,我们提供了一项名为“‘面向儿童的内容’标记”的设置。设置此标记即表示您确认此通知准确无误,且您有权代表应用所有者行事。您了解,滥用此设置可能会导致您的 Google 账号被终止。
作为应用开发者,您可以在发送广告请求时指明是否希望 Google 将您的内容视为面向儿童的内容。如果您指明要进行此类处理,我们便会采取相应措施,针对该广告请求停用针对用户兴趣投放广告和再营销广告。
您可以通过 setTagForChildDirectedTreatment() 应用面向儿童的设置:
使用
TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE调用setTagForChildDirectedTreatment,即表明您希望根据《儿童在线隐私保护法》的规定将您的内容视为面向儿童的内容。这会阻止传输 Android 广告标识符 (AAID)。使用
TAG_FOR_CHILD_DIRECTED_TREATMENT_FALSE调用setTagForChildDirectedTreatment,即表明您不希望根据《儿童在线隐私保护法》的规定将您的内容视为面向儿童的内容。如果您不希望在广告请求中表明您想如何根据《儿童在线隐私保护法》的规定来认定您的内容,请使用
TAG_FOR_CHILD_DIRECTED_TREATMENT_UNSPECIFIED调用setTagForChildDirectedTreatment。
以下示例表明您希望根据《儿童在线隐私保护法》的规定将您的内容视为面向儿童的内容:
Kotlin
val requestConfiguration =
MobileAds.getRequestConfiguration()
.toBuilder()
.setTagForChildDirectedTreatment(RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE)
.build()
MobileAds.setRequestConfiguration(requestConfiguration)Java
RequestConfiguration requestConfiguration =
MobileAds.getRequestConfiguration().toBuilder()
.setTagForChildDirectedTreatment(
RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE)
.build();
MobileAds.setRequestConfiguration(requestConfiguration);未达到同意年龄的用户
您可以对广告请求进行标记,确保针对未达到同意年龄的欧洲经济区 (EEA) 用户投放的是合适的广告。这项功能旨在帮助您遵守《一般数据保护条例》(GDPR)。需要说明的是,您可能还须承担 GDPR 规定的其他法律义务。具体请查看欧盟发布的指导原则,并咨询您的法律顾问。另请注意,Google 的工具旨在协助您遵守相关法规,但并不能免除任何特定发布商按照法律要求所需承担的义务。详细了解 GDPR 给发布商带来了哪些影响。
使用这项功能时,广告请求中会包含一个 TFUA(表示用户位于欧洲且未达到同意年龄的标记)参数。此参数会针对所有广告请求停用个性化广告,包括再营销广告。它还禁止向第三方广告供应商(例如广告效果衡量像素和第三方广告服务器)发送请求。
与面向儿童的设置一样,RequestConfiguration.Builder 中也提供了一个用于设置 TFUA 参数的 setTagForUnderAgeOfConsent() 方法,其中包含以下选项。
使用
TAG_FOR_UNDER_AGE_OF_CONSENT_TRUE调用setTagForUnderAgeOfConsent(),即表明您希望针对欧洲经济区未达到同意年龄的用户,对广告请求进行相应处理。这也会阻止传输 Android 广告标识符 (AAID)。使用
TAG_FOR_UNDER_AGE_OF_CONSENT_FALSE调用setTagForUnderAgeOfConsent(),即表明您不希望针对欧洲经济区未达到同意年龄的用户,对广告请求进行相应处理。使用
TAG_FOR_UNDER_AGE_OF_CONSENT_UNSPECIFIED调用setTagForUnderAgeOfConsent(),即表明您未明确是否针对欧洲经济区未达到同意年龄的用户,对广告请求进行相应处理。
以下示例表明您希望广告请求中包含 TFUA 标记:
Kotlin
val requestConfiguration =
MobileAds.getRequestConfiguration()
.toBuilder()
.setTagForUnderAgeOfConsent(RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_TRUE)
.build()
MobileAds.setRequestConfiguration(requestConfiguration)Java
RequestConfiguration requestConfiguration =
MobileAds.getRequestConfiguration().toBuilder()
.setTagForUnderAgeOfConsent(RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_TRUE)
.build();
MobileAds.setRequestConfiguration(requestConfiguration);不应将用于启用面向儿童的设置的标记和 setTagForUnderAgeOfConsent() 同时设置为 true。如果这两者同时设置为 true,则以“面向儿童的设置”为准。
广告内容过滤
为遵守 Google Play 的“不当广告”政策(包括广告中的相关优惠),应用中展示的所有广告及其相关优惠都必须适合应用的内容分级(即使广告内容本身符合 Google Play 政策)。
“广告内容分级上限”等工具可让您更好地控制向用户展示的广告内容。设置内容分级上限可帮助您遵守平台政策。
通过使用 setMaxAdContentRating 方法,应用可为其广告请求设置广告内容分级上限。配置此方法后,返回的 AdMob 广告的内容分级将不高于该上限。此广告联盟额外信息的可选值取决于数字内容标签分类,并且必须是以下字符串之一:
MAX_AD_CONTENT_RATING_GMAX_AD_CONTENT_RATING_PGMAX_AD_CONTENT_RATING_TMAX_AD_CONTENT_RATING_MA
下面的代码会配置一个 RequestConfiguration 对象,以指定返回的广告内容所对应的数字内容标签不应高于 G:
Kotlin
val requestConfiguration =
MobileAds.getRequestConfiguration()
.toBuilder()
.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_G)
.build()
MobileAds.setRequestConfiguration(requestConfiguration)Java
RequestConfiguration requestConfiguration =
MobileAds.getRequestConfiguration().toBuilder()
.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_G)
.build();
MobileAds.setRequestConfiguration(requestConfiguration);详细了解如何为每个广告请求设置内容分级上限。
Publisher Privacy Treatment(Beta 版)
Publisher Privacy Treatment (PPT) API 是一种可选工具,可让应用使用 setPublisherPrivacyPersonalizationState() 方法指明是否针对所有广告请求关闭广告个性化设置。使用这项功能时,在当前会话的剩余时间内,后续的所有广告请求中都会包含一个 PPT 参数。
默认情况下,对于向 Google 发送的广告请求,系统会返回个性化广告。以下代码会针对所有广告请求关闭广告个性化设置:
Kotlin
val requestConfiguration =
MobileAds.getRequestConfiguration()
.toBuilder()
.setPublisherPrivacyPersonalizationState(
RequestConfiguration.PublisherPrivacyPersonalizationState.DISABLED
)
.build()
MobileAds.setRequestConfiguration(requestConfiguration)Java
RequestConfiguration requestConfiguration =
MobileAds.getRequestConfiguration().toBuilder()
.setPublisherPrivacyPersonalizationState(
RequestConfiguration.PublisherPrivacyPersonalizationState.DISABLED)
.build();
MobileAds.setRequestConfiguration(requestConfiguration);广告请求
AdManagerAdRequest 对象用于收集随广告请求一起发送的定位信息。
添加广告联盟额外信息
广告联盟额外信息是指随广告请求一起发送的额外详细信息,专属于单个广告来源。
以下代码段为 Google 设置了一个额外的参数键 collapsible(值为 bottom):
Kotlin
val extras = Bundle()
extras.putString("collapsible", "bottom")
val adRequest =
AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter::class.java, extras).build()
adView.loadAd(adRequest)Java
Bundle extras = new Bundle();
extras.putString("collapsible", "bottom");
AdRequest adRequest =
new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class, extras).build();
adView.loadAd(adRequest);自定义定位
您可以传递自定义键值对,以定位 Google Ad Manager 广告系列(订单项)。以下示例会在广告请求中传递自定义键值对:
Kotlin
// Example: Pass custom targeting "age=25".
val newRequest = AdManagerAdRequest.Builder().addCustomTargeting("age", "25").build()Java
// Example: Pass custom targeting "age=25".
AdManagerAdRequest newRequest =
new AdManagerAdRequest.Builder().addCustomTargeting("age", "25").build();您可以将一个键的多个值作为字符串列表传递。例如,定位 25 岁左右的用户,而不仅仅只定位 25 岁的用户。
Kotlin
.addCustomTargeting("age", listOf("24", "25", "26"))Java
.addCustomTargeting("age", Arrays.asList("24", "25", "26"))类别排除
您可以使用 addCategoryExclusion() 方法向请求中添加广告位一级的类别排除级别:
Kotlin
// Example: Exclude "automobile" and "boat" categories.
val newRequest =
AdManagerAdRequest.Builder()
.addCategoryExclusion("automobile")
.addCategoryExclusion("boat")
.build()Java
// Example: Exclude "automobile" and "boat" categories.
AdManagerAdRequest newRequest =
new AdManagerAdRequest.Builder()
.addCategoryExclusion("automobile")
.addCategoryExclusion("boat")
.build();如需关于 Android API 演示版应用中类别排除的实现,请参阅 Ad Manager 类别排除示例。
发布商提供的标识符 (PPID)
您可以设置 PPID,用于实现跨设备的频次上限、受众群细分和定位、广告依序轮播和其他基于受众群体的广告投放控制。
以下是设置 PPID 的示例:
Kotlin
val adRequest = AdManagerAdRequest.Builder().setPublisherProvidedId("AB123456789").build()Java
AdManagerAdRequest adRequest =
new AdManagerAdRequest.Builder().setPublisherProvidedId("AB123456789").build();如需关于 Android API 演示版应用中发布商提供的标识符 (PPID) 的实现,请参阅 Ad Manager PPID 示例。
发布商提供的信号
您可以在广告请求中,将受众群体和情境数据作为发布商提供的信号 (PPS) 进行发送。借助 PPS,您可以通过标准类目,将您的受众群体特征传递给所有交易类型中的出价方,从而利用您的用户数据提升程序化变现能力,而且无需分享用户标识符。您的受众群体特征可能包括行为数据和兴趣数据(IAB 受众群体类目 1.1)以及情境数据(IAB 内容类目 2.2)。
Kotlin
val extras = Bundle()
// Set the demographic to an audience with an "Age Range" of 30-34 and an
// interest in mergers and acquisitions.
extras.putIntegerArrayList("IAB_AUDIENCE_1_1", arrayListOf(6, 284))
// Set the content to sedan, station wagon and SUV automotive values.
extras.putIntegerArrayList("IAB_CONTENT_2_2", arrayListOf(4, 5, 6))
val request =
AdManagerAdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter::class.java, extras).build()Java
Bundle extras = new Bundle();
// Set the demographic to an audience with an "Age Range" of 30-34 and an
// interest in mergers and acquisitions.
extras.putIntegerArrayList("IAB_AUDIENCE_1_1", new ArrayList<>(Arrays.asList(6, 284)));
// Set the content to sedan, station wagon and SUV automotive values.
extras.putIntegerArrayList("IAB_CONTENT_2_2", new ArrayList<>(Arrays.asList(4, 5, 6)));
AdManagerAdRequest request =
new AdManagerAdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class, extras).build();内容网址
如需针对内容定位广告和品牌保障提供内容网址,请添加以下内容:
Kotlin
val builder = AdManagerAdRequest.Builder()
builder.setContentUrl("https://www.example.com")
val request = builder.build()Java
AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
builder.setContentUrl("https://www.example.com");
AdManagerAdRequest request = builder.build();品牌保障(Beta 版)
针对各种受众群体显示动态内容的应用可以提供一个简短的网址列表:
Kotlin
val urls =
mutableListOf(
"https://www.mycontenturl1.com",
"https://www.mycontenturl2.com",
"https://www.mycontenturl3.com",
"https://www.mycontenturl4.com",
)
val requestWithContent = AdManagerAdRequest.Builder().setNeighboringContentUrls(urls).build()Java
List<String> urls =
Arrays.asList(
"https://www.mycontenturl1.com",
"https://www.mycontenturl2.com",
"https://www.mycontenturl3.com",
"https://www.mycontenturl4.com");
AdManagerAdRequest requestWithContent =
new AdManagerAdRequest.Builder().setNeighboringContentUrls(urls).build();.setNeighboringContentUrls() 与 .setContentUrl() 的区别在于,前者仅用于品牌保障。