Targeting

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

前提条件

RequestConfiguration

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

使用 RequestConfiguration 的构建器创建包含所需定位标记的 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 Google Mobile Ads SDK (beta) on a background thread.
  MobileAds.initialize(
    this@MainActivity,
    InitializationConfig
      // Sample AdMob 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 Google Mobile Ads SDK (beta) on a background thread.
      MobileAds.initialize(
          this,
          // Sample AdMob 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();

面向儿童的设置

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

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

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

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

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

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

以下示例表明您希望根据《儿童在线隐私保护法》(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(),即表明您希望按适合未达到同意年龄的欧洲经济区 (EEA) 用户的方式处理该广告请求。这也会阻止传输 Android 广告标识符 (AAID)

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

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

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

发布商隐私保护处理措施(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);