Targeting

本指南介绍了如何向 Google 移动广告 SDK 提供定位信息。

前提条件

在继续之前,请设置GMA Next-Gen SDK

RequestConfiguration

RequestConfiguration 用于收集在全局范围内应用于每个广告请求的定位信息。如需查看 可用的定位标记,请参阅 RequestConfiguration.Builder 文档。

使用构建器创建包含所需定位标记的 RequestConfiguration 对象,然后调用 MobileAds.setRequestConfiguration()设置配置。

Kotlin

val requestConfiguration = RequestConfiguration
  .Builder()
  // Set your targeting tags.
  .setTagForChildDirectedTreatment(RequestConfiguration.TagForChildDirectedTreatment.TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE)
  .build()

MobileAds.setRequestConfiguration(requestConfiguration)

Java

RequestConfiguration requestConfiguration = new RequestConfiguration
  .Builder()
  // Set your targeting tags.
  .setTagForChildDirectedTreatment(TagForChildDirectedTreatment.TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE)
  .build();

MobileAds.setRequestConfiguration(requestConfiguration);

如需应用第一个广告请求中的定位标记,请在 SDK 初始化期间提供请求配置:

Kotlin

val requestConfiguration = RequestConfiguration
  .Builder()
  // Set your targeting tags.
  .setTagForChildDirectedTreatment(RequestConfiguration.TagForChildDirectedTreatment.TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE)
  .build()

CoroutineScope(Dispatchers.IO).launch {
  // Initialize GMA Next-Gen SDK on a background thread.
  MobileAds.initialize(
    this@MainActivity,
    InitializationConfig
      // Sample Ad Manager app ID: ca-app-pub-3940256099942544~3347511713
      .Builder("SAMPLE_APP_ID")
      .setRequestConfiguration(requestConfiguration)
      .build()
  ) {
    // Adapter initialization is complete.
  }
  // Other methods on MobileAds can now be called.
}

Java

RequestConfiguration requestConfiguration = new RequestConfiguration
    .Builder()
    // Set your targeting tags.
    .setTagForChildDirectedTreatment(TagForChildDirectedTreatment.TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE)
    .build();

new Thread(
    () -> {
      // Initialize GMA Next-Gen SDK on a background thread.
      MobileAds.initialize(
          this,
          // Sample Ad Manager app ID: ca-app-pub-3940256099942544~3347511713
          new InitializationConfig
              .Builder("SAMPLE_APP_ID")
              .setRequestConfiguration(requestConfiguration)
              .build(),
          initializationStatus -> {
            // Adapter initialization is complete.
          });
      // Other methods on MobileAds can now be called.
    })
    .start();

设置年龄处理方式

为了帮助您遵守与儿童和青少年相关的适用隐私权法规,GMA Next-Gen SDK 提供了一项年龄处理方式设置。通过 年龄处理方式设置,您可以指明 GMA Next-Gen SDK 是否应采用 面向儿童、青少年或年龄不明用户的特定广告投放保护措施。

您可通过 RequestConfiguration.Builder API 中的 setAgeRestrictedTreatment() 方法来设置年龄处理方式。

以下示例展示了如何指明广告请求应按针对儿童的年龄处理方式进行处理:

Kotlin

val requestConfiguration =
  RequestConfiguration.Builder()
    // Indicate that ad requests should have child age treatment.
    .setAgeRestrictedTreatment(AgeRestrictedTreatment.CHILD)
    .build()
MobileAds.setRequestConfiguration(requestConfiguration)

Java

RequestConfiguration requestConfiguration =
    new RequestConfiguration.Builder()
        // Indicate that ad requests should have child age treatment.
        .setAgeRestrictedTreatment(AgeRestrictedTreatment.CHILD)
        .build();
MobileAds.setRequestConfiguration(requestConfiguration);

如需指明面向青少年或年龄不明用户的年龄处理方式,请将 CHILD 设置替换为以下内容:

  • TEEN
  • UNSPECIFIED

使用此设置时,GMA Next-Gen SDK 会在广告请求中包含 tfat 参数。请咨询您的法律顾问,依据自身的法律及监管义务,为用户确定适用的年龄处理方式。如需了解详情,请参阅 为广告请求添加年龄处理方式标记

从 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 会采用最保守的处理方式。

通过中介转发年龄处理方式

如果您设置了年龄处理方式,中介适配器会将年龄处理方式信号转发给中介的第三方 SDK。GMA Next-Gen SDK

下表列出了支持将有年龄限制的处理方式信号转发给中介的第三方 SDK 的中介适配器版本:

中介适配器名称 支持的最低版本
AppLovin 13.6.3.0
BidMachine 3.7.1.1
Bigo 5.9.0.1
Chartboost 9.12.1.1
DTExchange (Fyber) 8.4.5.1
i-mobile 2.3.2.4
InMobi 11.3.0.1
IronSource 9.4.3.0
Liftoff Monetize (Vungle) 7.7.4.2
LY (Line) 3.1.1.1
maio 2.0.9.0
Meta (Facebook) 6.21.0.4
Mintegral 17.1.61.1
Moloco 4.10.0.0
MyTarget 5.47.1.1
Pangle 8.1.0.3.1
PubMatic 5.1.2.2
Verve 3.9.0.0

面向儿童的设置

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

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

您可以通过 setTagForChildDirectedTreatment()应用面向儿童的设置:

  • 使用 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

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

Kotlin

val requestConfiguration = RequestConfiguration
  .Builder()
  .setTagForChildDirectedTreatment(RequestConfiguration.TagForChildDirectedTreatment.TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE)
  .build()

MobileAds.setRequestConfiguration(requestConfiguration)

Java

RequestConfiguration requestConfiguration = new RequestConfiguration
  .Builder()
  .setTagForChildDirectedTreatment(TagForChildDirectedTreatment.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(),即表明您未明确是否按适合未达到法定承诺年龄的欧洲经济区 (EEA) 用户的方式处理该广告请求。

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

Kotlin

val requestConfiguration = RequestConfiguration
  .Builder()
  .setTagForUnderAgeOfConsent(RequestConfiguration.TagForUnderAgeOfConsent.TAG_FOR_UNDER_AGE_OF_CONSENT_TRUE)
  .build()

MobileAds.setRequestConfiguration(requestConfiguration)

Java

RequestConfiguration requestConfiguration = new RequestConfiguration
  .Builder()
  .setTagForUnderAgeOfConsent(TagForUnderAgeOfConsent.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

Kotlin

val requestConfiguration = RequestConfiguration
  .Builder()
  .setMaxAdContentRating(RequestConfiguration.MaxAdContentRating.MAX_AD_CONTENT_RATING_G)
  .build()

MobileAds.setRequestConfiguration(requestConfiguration)

Java

RequestConfiguration requestConfiguration = new RequestConfiguration
  .Builder()
  .setMaxAdContentRating(MaxAdContentRating.MAX_AD_CONTENT_RATING_G)
  .build();

MobileAds.setRequestConfiguration(requestConfiguration);

详细了解如何为每个广告 请求设置内容分级上限。

Publisher Privacy Treatment(Beta 版)

Publisher Privacy Treatment(PPT) API 是一种可选工具,可让应用指明是否针对所有广告请求关闭广告个性化设置。setPublisherPrivacyPersonalizationState()使用这项功能时,在当前会话的剩余时间内,后续的所有广告请求中都会包含一个 PPT 参数。

默认情况下,对于向 Google 发送的广告请求,系统会返回个性化广告。以下代码会针对所有广告请求关闭广告个性化设置:

Kotlin

val requestConfiguration = RequestConfiguration
  .Builder()
  .setPublisherPrivacyPersonalizationState(RequestConfiguration.PublisherPrivacyPersonalizationState.DISABLED)
  .build()

MobileAds.setRequestConfiguration(requestConfiguration)

Java

RequestConfiguration requestConfiguration = new RequestConfiguration
  .Builder()
  .setPublisherPrivacyPersonalizationState(RequestConfiguration.PublisherPrivacyPersonalizationState.DISABLED)
  .build();

MobileAds.setRequestConfiguration(requestConfiguration);

广告请求

AdRequest 对象用于收集随广告请求一起发送的定位信息。

添加广告联盟额外信息

广告联盟额外信息是指随广告请求一起发送的额外详细信息,专属于单个广告来源。

以下代码段为 Google 设置了一个额外的参数键 collapsible(值为 bottom):

Kotlin

val extras = Bundle()
extras.putString("collapsible", "bottom")
val adRequest =
  NativeAdRequest.Builder("AD_UNIT_ID", listOf(NativeAd.NativeAdType.NATIVE))
    .setGoogleExtrasBundle(extras)
    .build()
NativeAdLoader.load(adRequest, adCallback)

Java

Bundle extras = new Bundle();
extras.putString("collapsible", "bottom");
NativeAdRequest adRequest =
  new NativeAdRequest.Builder("AD_UNIT_ID", Arrays.asList(NativeAd.NativeAdType.NATIVE))
    .setGoogleExtrasBundle(extras)
    .build();
NativeAdLoader.load(adRequest, adCallback);

自定义定位

您可以传递自定义键值对,以定位 Google Ad Manager 广告系列(订单项)。以下示例会在广告请求中传递自定义键值对:

Kotlin

// Example: Pass custom targeting "age=25".
val newRequest = AdRequest.Builder("AD_UNIT_ID")
  .putCustomTargeting("age", "25")
  .build()

Java

// Example: Pass custom targeting "age=25".
AdRequest newRequest = new AdRequest.Builder("AD_UNIT_ID")
  .putCustomTargeting("age", "25")
  .build();

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

Kotlin

.putCustomTargeting("age", listOf("24", "25", "26"))

Java

.putCustomTargeting("age", Arrays.asList("24", "25", "26"));

类别排除

您可以使用 addCategoryExclusion() 方法向请求中添加广告位一级的类别排除级别:

Kotlin

// Example: Exclude "automobile" and "boat" categories.
val newRequest = AdRequest.Builder("AD_UNIT_ID")
  .addCategoryExclusion("automobile")
  .addCategoryExclusion("boat")
  .build()

Java

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

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

发布商提供的标识符

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

下面是一个设置 PPID 的示例:

Kotlin

val adRequest = AdRequest.Builder("AD_UNIT_ID")
  .setPublisherProvidedId("AB123456789")
  .build()

Java

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

有关 Android API Demo 应用中发布商提供的标识符 (PPID) 的实现方式,请参阅 Google 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 = AdRequest.Builder("AD_UNIT_ID")
  .setGoogleExtrasBundle(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", arrayListOf(6,284));
// Set the content to sedan, station wagon and SUV automotive values.
extras.putIntegerArrayList("IAB_CONTENT_2_2", arrayListOf(4,5,6));

AdRequest request = new AdRequest.Builder("AD_UNIT_ID")
  .setGoogleExtrasBundle(extras)
  .build();

内容网址

如需针对内容定位广告和品牌保障提供内容网址,请添加以下内容:

Kotlin

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

Java

AdRequest.Builder builder = new AdRequest.Builder("AD_UNIT_ID")
builder.setContentUrl("https://www.example.com");
AdRequest 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 = AdRequest.Builder("AD_UNIT_ID")
  .setNeighboringContentUrls(urls)
  .build()

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");
AdRequest requestWithContent = new AdRequest.Builder("AD_UNIT_ID")
    .setNeighboringContentUrls(urls)
    .build();

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