本指南說明如何為 Google Mobile Ads SDK 提供指定目標資訊。
如需實際運作的範例,請下載 Android API Demo 應用程式。修課條件
- 完成入門指南的步驟。
RequestConfiguration
RequestConfiguration
會收集套用至每項廣告請求的全域指定目標資訊。如要瞭解可用的指定目標標記,請參閱RequestConfiguration.Builder
說明文件。
如要更新要求設定,請從現有設定取得建構工具,執行任何所需更新,然後設定如下:
Kotlin
val requestConfiguration = MobileAds.getRequestConfiguration()
.toBuilder()
.build()
MobileAds.setRequestConfiguration(requestConfiguration)
Java
RequestConfiguration requestConfiguration = MobileAds.getRequestConfiguration()
.toBuilder()
.build();
MobileAds.setRequestConfiguration(requestConfiguration);
為確保所有廣告請求都套用請求設定變更,請先指定請求設定,再初始化 Google Mobile Ads SDK。
兒童導向內容設定
為符合《兒童網路隱私保護法》(COPPA) 規範,系統提供了名為「兒童導向內容標記」的設定。設定此標記,即表示您確認這項通知正確無誤,且您有權代表應用程式擁有者採取行動;同時您也瞭解如果濫用這項設定,可能導致 Google 帳戶遭到終止。
應用程式開發人員可以在傳送廣告請求時,指明是否希望 Google 將內容標為兒童導向。如果選擇將內容視為兒童導向,Google 就會採取必要措施,停用該廣告請求的 IBA 和再行銷廣告。
您可以透過下列方式套用兒童導向內容設定:
setTagForChildDirectedTreatment()
:
使用
TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE
呼叫setTagForChildDirectedTreatment
,指明要根據 COPPA 將內容視為兒童導向。如此一來,系統便不會傳送 Android 廣告 ID (AAID)。使用
TAG_FOR_CHILD_DIRECTED_TREATMENT_FALSE
呼叫setTagForChildDirectedTreatment
,指明不要根據 COPPA 將內容視為兒童導向。如果不想在廣告請求中指明應如何依據 COPPA 處理內容,請使用
TAG_FOR_CHILD_DIRECTED_TREATMENT_UNSPECIFIED
呼叫setTagForChildDirectedTreatment
。
以下範例說明如何依 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) 參數。這項參數會停用所有廣告請求的個人化廣告功能 (包括再行銷),也會停止向第三方廣告供應商提出請求,例如廣告評估像素和第三方廣告伺服器。
就像兒童導向內容設定,指定 TFUA 參數時,可以使用 RequestConfiguration.Builder
中的方法 setTagForUnderAgeOfConsent()
,並有下列選項:
使用
TAG_FOR_UNDER_AGE_OF_CONSENT_TRUE
呼叫setTagForUnderAgeOfConsent()
,即表示您希望廣告請求對歐洲經濟區 (EEA) 未滿規定年齡的使用者,採取相應措施。這樣一來,系統也不會傳送 Android 廣告 ID (AAID)。使用
TAG_FOR_UNDER_AGE_OF_CONSENT_FALSE
呼叫setTagForUnderAgeOfConsent()
,即表示您「不希望」廣告請求對歐洲經濟區 (EEA) 未滿規定年齡的使用者,採取相應措施。使用
TAG_FOR_UNDER_AGE_OF_CONSENT_UNSPECIFIED
呼叫setTagForUnderAgeOfConsent()
,表示您未指定廣告請求是否應對歐洲經濟區 (EEA) 未滿規定年齡的使用者,採取相應措施。
以下範例說明如何在廣告請求中加入 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 版)
發布商隱私權處理方式 (PPT) API 是選用工具,可讓應用程式使用 setPublisherPrivacyPersonalizationState()
方法,指定是否要停用所有廣告請求的廣告個人化設定。使用這項功能後,系統就會在工作階段的剩餘時間,將發布商隱私權處理方式 (PPT) 參數,加入所有後續的廣告請求。
根據預設,向 Google 請求的廣告會採用個人化功能。下列程式碼會停用所有廣告請求的廣告個人化功能:
Kotlin
val requestConfiguration = MobileAds.getRequestConfiguration()
.toBuilder()
.setPublisherPrivacyPersonalizationState(PublisherPrivacyPersonalizationState.DISABLED)
.build()
MobileAds.setRequestConfiguration(requestConfiguration)
Java
RequestConfiguration requestConfiguration = MobileAds.getRequestConfiguration()
.toBuilder()
.setPublisherPrivacyPersonalizationState(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()
adLoader.loadAd(adRequest)
Java
Bundle extras = new Bundle();
extras.putString("collapsible", "bottom");
AdRequest adRequest = new AdRequest.Builder()
.addNetworkExtrasBundle(AdMobAdapter.class, extras)
.build();
adLoader.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();
您可以將鍵的多個值做為字串清單傳遞。舉例來說,您可指定 20 幾歲的使用者,而不只是 25 歲的使用者。
.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();
請查看 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", 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 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
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();
.setNeighboringContentUrls()
與 .setContentUrl()
的不同之處在於,前者只用於品牌安全。