指定目標

本指南說明如何向 Google Mobile Ads SDK 提供目標對象資訊。

如需實際範例,請下載 Android API 試用版應用程式。

下載 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 將您的內容視為兒童導向。如果希望 Google 將內容視為兒童導向,我們就會採取相關行動,對廣告請求停用「按照興趣顯示廣告」(IBA) 功能和再行銷廣告。

您可以使用 setTagForChildDirectedTreatment() 套用兒童導向內容設定:

  • 呼叫 setTagForChildDirectedTreatment 並傳遞 TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE,指明要根據 COPPA 將內容視為兒童導向,這樣系統就不會傳送 Android 廣告 ID (AAID)

  • 呼叫 setTagForChildDirectedTreatment 並傳遞 TAG_FOR_CHILD_DIRECTED_TREATMENT_FALSE,指明不要根據 COPPA 將內容視為兒童導向。

  • 如不想在廣告請求中指明是否依 COPPA 規定處理內容,請呼叫 setTagForChildDirectedTreatment 並傳遞 TAG_FOR_CHILD_DIRECTED_TREATMENT_UNSPECIFIED

以下示範如何指明依照 COPPA 將內容標為兒童導向。

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);

針對未滿規定年齡的歐洲經濟區使用者,您可以在廣告請求中加上相關處理標記。這項功能是為協助發布商遵守《一般資料保護規則》(GDPR)。請注意,根據 GDPR 規定,您可能還有其他法律義務。建議參考歐盟官方指引,並諮詢您的法律顧問。請注意,Google 提供適用工具是為協助發布商遵守規定,而非方便發布商規避法定義務。 進一步瞭解 GDPR 對發布商的影響

使用這項功能時,廣告請求會包含歐洲使用者適用的未滿規定年齡標記 (TFUA) 參數。這項參數會停用所有廣告請求的個人化廣告功能 (包括再行銷),並停止向第三方廣告供應商 (例如廣告評估像素和第三方廣告伺服器) 提出其他請求。

就像兒童導向內容設定,您可以用 RequestConfiguration.Builder 中的方法 setTagForUnderAgeOfConsent() 設定 TFUA 參數,可用的選項包括:

  • 呼叫 setTagForUnderAgeOfConsent() 並傳遞 TAG_FOR_UNDER_AGE_OF_CONSENT_TRUE,指明要對涉及歐洲經濟區內未滿規定年齡使用者的廣告請求,套用適當模式,且這也可防止系統傳送 Android 廣告 ID (AAID)

  • 呼叫 setTagForUnderAgeOfConsent() 並傳遞 TAG_FOR_UNDER_AGE_OF_CONSENT_FALSE,指明「不要」對涉及歐洲經濟區內未滿規定年齡使用者的廣告請求,套用相關模式。

  • 如未指明是否對涉及歐洲經濟區內未滿規定年齡使用者的廣告請求,套用相關模式,請呼叫 setTagForUnderAgeOfConsent() 並傳遞 TAG_FOR_UNDER_AGE_OF_CONSENT_UNSPECIFIED

以下範例說明如何在廣告請求中加入 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,否則將優先採用兒童導向內容設定。

廣告內容篩選

為遵守 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 =
  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);

進一步瞭解如何設定個別廣告請求的內容分級上限

發布商隱私權處理方式 (Beta 版)

如有需要可選用 Publisher Privacy Treatment (PPT) API,這樣應用程式便可使用 setPublisherPrivacyPersonalizationState() 方法,指明是否要停用所有廣告請求的廣告個人化設定。如果採用這項功能,則工作階段後續所有的廣告請求,都會加入 Publisher Privacy Treatment (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 物件會收集指定目標資訊,並與廣告請求一併傳送。

新增聯播網額外資訊

聯播網額外資訊是隨廣告請求傳送的附加詳細資料,只適用於特定廣告來源。

以下程式碼片段是將額外資訊參數鍵 collapsible 設為 bottom 值,並傳送給 Google:

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"))

請參閱 Ad Manager 自訂指定目標範例,瞭解如何在 Android API 試用版應用程式導入自訂指定目標。

類別排除

如要在請求中新增版位層級的排除類別,可以使用 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();

請參閱 Ad Manager 類別排除範例,瞭解如何在 Android API 試用版應用程式中導入類別排除。

發布商提供的 ID

您可以設定發布商提供的 ID (PPID),跨裝置管理廣告放送方式,例如指定展示頻率上限、區隔目標對象及指定目標、安排廣告依序輪播,以及採取其他依目標對象調整的控制措施。

以下示範如何設定 PPID:

Kotlin

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

Java

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

請參閱 Ad Manager PPID 範例,瞭解如何在 Android API 試用版應用程式中,導入發布商提供的 ID (PPID)。

發布商提供的信號

您可以在廣告請求中,以發布商提供的信號 (PPS) 形式傳送目標對象和比對內容資料。只要使用 PPS,就能透過標準分類,在所有交易類型中向出價方傳達目標對象特徵,如此便能運用使用者資料提升程式輔助營利成效,而不必提供使用者 ID。目標對象特徵可包括行為與興趣資料 (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() 的差異在於前者僅適用於品牌安全。