定位

本指南介绍如何向广告请求提供定位信息。如需查看工作示例,请下载 Android API Demo 应用。

下载 API 演示版

前提条件

RequestConfiguration

RequestConfiguration 对象会收集通过 MobileAds 静态方法在全局范围内应用的定位信息。

如需更新请求配置,请从现有配置中获取构建器,执行所需的更新,然后按如下所示进行设置:

Java

RequestConfiguration requestConfiguration = MobileAds.getRequestConfiguration()
    .toBuilder()
    .build();
MobileAds.setRequestConfiguration(requestConfiguration);

Kotlin

var requestConfiguration = MobileAds.getRequestConfiguration()
  .toBuilder()
  .build()
MobileAds.setRequestConfiguration(requestConfiguration)

面向儿童的设置

为了遵守《儿童在线隐私保护法》(COPPA) 的规定,我们提供了一项名为“面向儿童的内容的标记”的设置。设置此标记,即表示您确认此通知准确无误,且您有权代表应用的所有者行事。您了解,滥用此设置可能会导致您的 Google 账号被终止。

作为应用开发者,您可以在发出广告请求时指明是否希望 Google 将您的内容视为面向儿童的内容。如果您指明希望 Google 将您的内容视为面向儿童的内容,我们会采取相应措施,以针对该广告请求停用针对用户兴趣投放广告和再营销广告。

通过 RequestConfiguration.Builder.setTagForChildDirectedTreatment(int),该设置可用于所有版本的 Google Play 服务 SDK:

  • 使用 TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE 调用 setTagForChildDirectedTreatment,即表明您希望根据《儿童在线隐私保护法》(COPPA) 的规定将您的内容视为面向儿童的内容。这样可以阻止传输 Android 广告标识符 (AAID)

  • 使用 TAG_FOR_CHILD_DIRECTED_TREATMENT_FALSE 调用 setTagForChildDirectedTreatment,即表明您不希望根据《儿童在线隐私保护法》(COPPA) 的规定将您的内容视为面向儿童的内容。

  • 如果您不希望在广告请求中表明您想如何根据《儿童在线隐私保护法》(COPPA) 的规定来认定您的内容,请使用 TAG_FOR_CHILD_DIRECTED_TREATMENT_UNSPECIFIED 调用 setTagForChildDirectedTreatment

以下示例表明您希望根据《儿童在线隐私保护法》(COPPA) 的规定将您的内容视为面向儿童的内容:

Java

RequestConfiguration requestConfiguration = MobileAds.getRequestConfiguration()
    .toBuilder()
    .setTagForChildDirectedTreatment(RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE)
    .build();
MobileAds.setRequestConfiguration(requestConfiguration);

Kotlin

var 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(),即表明您希望按适合未达到法定承诺年龄的欧洲经济区 (EEA) 用户的方式处理该广告请求。这也会阻止传输 Android 广告标识符 (AAID)

  • 使用 TAG_FOR_UNDER_AGE_OF_CONSENT_FALSE 调用 setTagForUnderAgeOfConsent(),即表明您不希望按适合未达到法定承诺年龄的欧洲经济区 (EEA) 用户的方式处理该广告请求。

  • 使用 TAG_FOR_UNDER_AGE_OF_CONSENT_UNSPECIFIED 调用 setTagForUnderAgeOfConsent(),即表明您未明确是否按适合未达到法定承诺年龄的欧洲经济区 (EEA) 用户的方式处理该广告请求。

以下示例表明您希望广告请求中包含 TFUA 标记:

Java

RequestConfiguration requestConfiguration = MobileAds.getRequestConfiguration()
    .toBuilder()
    .setTagForUnderAgeOfConsent(RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_TRUE)
    .build();
MobileAds.setRequestConfiguration(requestConfiguration);

Kotlin

var 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_G
  • MAX_AD_CONTENT_RATING_PG
  • MAX_AD_CONTENT_RATING_T
  • MAX_AD_CONTENT_RATING_MA

以下代码会配置 RequestConfiguration 对象,以指定返回的广告内容所对应的数字内容标签不应高于 G

Java

RequestConfiguration requestConfiguration = MobileAds.getRequestConfiguration()
    .toBuilder()
    .setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_G)
    .build();
MobileAds.setRequestConfiguration(requestConfiguration);

Kotlin

var requestConfiguration = MobileAds.getRequestConfiguration()
  .toBuilder()
  .setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_G)
  .build()
MobileAds.setRequestConfiguration(requestConfiguration)

不妨查看以下内容了解详情:

发布商隐私保护处理(Beta 版)

Publisher Privacy Treatment (PPT) API 是一款可选工具,可让应用使用 setPublisherPrivacyPersonalizationState() 方法指示是否针对所有广告请求关闭广告个性化功能。 使用此功能时,发布商隐私保护处理 (PPT) 参数将包含在相应会话剩余部分接下来的所有广告请求中。

默认情况下,系统会向 Google 发出的广告请求投放个性化广告。以下代码会为所有广告请求关闭广告个性化功能:

Java

RequestConfiguration requestConfiguration = MobileAds.getRequestConfiguration()
    .toBuilder()
    .setPublisherPrivacyPersonalizationState(PublisherPrivacyPersonalizationState.DISABLED)
    .build();
MobileAds.setRequestConfiguration(requestConfiguration);

Kotlin

var requestConfiguration = MobileAds.getRequestConfiguration()
  .toBuilder()
  .setPublisherPrivacyPersonalizationState(PublisherPrivacyPersonalizationState.DISABLED)
  .build()
MobileAds.setRequestConfiguration(requestConfiguration)

广告请求

AdManagerAdRequest 对象可收集随广告请求一起发送的定位信息。

自定义定位

您可以通过 AdManagerAdRequest.Builder.addCustomTargeting() 传递自定义键值对,以定位 Google Ad Manager 广告系列(订单项):

Java

// Example: Pass custom targeting "age=25".
AdManagerAdRequest newRequest = new AdManagerAdRequest.Builder()
    .addCustomTargeting("age", "25")
    .build();

Kotlin

// Example: Pass custom targeting "age=25".
var newRequest = AdManagerAdRequest.Builder()
  .addCustomTargeting("age", "25")
  .build()

您可以将一个键的多个值作为字符串列表传递。例如,要定位二十多岁中间年龄段而不只是 25 岁的个人。

.addCustomTargeting("age", Arrays.asList("24", "25", "26"))

有关 Android API Demo 应用中自定义定位的实现方式,请参考 Ad Manager 自定义定位示例

类别排除

您可以使用 AdManagerAdRequest.Builder 提供的 addCategoryExclusion() 方法向请求添加广告位级类别排除级别:

Java

// Example: Exclude "automobile" and "boat" categories.
AdManagerAdRequest newRequest = new AdManagerAdRequest.Builder()
    .addCategoryExclusion("automobile")
    .addCategoryExclusion("boat")
    .build();

Kotlin

// Example: Exclude "automobile" and "boat" categories.
var newRequest = AdManagerAdRequest.Builder()
  .addCategoryExclusion("automobile")
  .addCategoryExclusion("boat")
  .build()

有关 Android API Demo 应用中类别排除的实现方式,请参阅 Ad Manager 类别排除示例

发布商提供的标识符 (PPID)

您可以设置发布商提供的标识符 (PPID),以用于跨设备实现频次上限、受众群细分和定位、依序广告轮播以及基于受众群体的其他广告投放控制。

以下是设置 PPID 的示例:

Java

AdManagerAdRequest adRequest = new AdManagerAdRequest.Builder()
    .setPublisherProvidedId("AB123456789")
    .build();

Kotlin

var adRequest = AdManagerAdRequest.Builder()
  .setPublisherProvidedId("AB123456789")
  .build()

有关 Android API Demo 应用中发布商提供的标识符 (PPID) 的实现方式,请参阅 Ad Manager PPID 示例

发布商提供的信号

您可以在广告请求中将受众群体和情境数据作为发布商提供的信号 (PPS) 发送。借助 PPS,您可以利用标准分类向所有交易类型的出价方传达受众群体特征,从而使用用户数据来提升程序化变现效果,而无需共享用户标识符。您的受众群体特征可能包括行为数据和基于兴趣的数据(IAB 受众群体类目 1.1)和情境数据(IAB 内容类目 2.2)。

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", arrayListOf(6,284));
// Set the content to sedan, station wagon and SUV automotive values.
extras.putIntegerArrayList("IAB_CONTENT_2_2", arrayListOf(4,5,6));

AdManagerAdRequest request = new AdManagerAdRequest.Builder()
  .addNetworkExtrasBundle(AdMobAdapter.class, extras)
  .build()

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 = AdRequest.Builder()
  .addNetworkExtrasBundle(AdMobAdapter::class.java, extras)
  .build()

内容网址

如需为内容定位广告和品牌保障提供内容网址,您可以在构建 AdManagerAdRequest 时调用 setContentUrl()

Java

AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
builder.setContentUrl("https://www.example.com");
AdManagerAdRequest request = builder.build();

Kotlin

val builder = AdManagerAdRequest.Builder()
builder.setContentUrl("https://www.example.com")
val request = builder.build()

品牌保障(Beta 版)

针对各种受众群体显示动态内容的应用可以在构建 AdManagerAdRequest 时使用 setNeighboringContentUrls() 方法提供一个简短的网址列表:

Java

ArrayList<String> urls = new ArrayList<String>();
urls.add("https://www.mycontenturl1.com");
urls.add("https://www.mycontenturl2.com");
urls.add("https://www.mycontenturl3.com");
urls.add("https://www.mycontenturl4.com");
AdManagerAdRequest requestWithContent = new AdManagerAdRequest.Builder()
    .setNeighboringContentUrls(urls)
    .build();

Kotlin

var urls = mutableListOf("https://www.mycontenturl1.com", "https://www.mycontenturl2.com",
                         "https://www.mycontenturl3.com", "https://www.mycontenturl4.com")
var requestWithContent = AdManagerAdRequest.Builder()
  .setNeighboringContentUrls(urls)
  .build()

.setNeighboringContentUrls().setContentUrl() 的区别在于,前者仅用于品牌保障。