本指南介绍如何向广告请求提供定位信息。
若要查看广告定位的实际运作情况,请下载 Swift 或 Objective-C 语言的 iOS API Demo 应用。
前提条件
在继续操作之前,请设置 Google Mobile Ads SDK。
GADRequestConfiguration
GADRequestConfiguration 对象会收集通过 GADMobileAds 共享实例在全局范围内应用的定位信息。您可以使用以下代码访问该对象:
Swift
let requestConfiguration = MobileAds.shared.requestConfiguration
Objective-C
GADRequestConfiguration requestConfiguration = GADMobileAds.sharedInstance.requestConfiguration;
为确保所有广告请求都应用请求配置更改,请在初始化 Google Mobile Ads SDK 之前设置请求配置。
设置年龄处理方式
为帮助您遵守面向儿童和青少年的适用隐私权法规,Google Mobile Ads SDK 提供了一项年龄处理方式设置。通过年龄处理方式设置,您可以指明 Google Mobile Ads SDK 是否应启用面向儿童或青少年的特定广告投放保护措施。使用此设置时,Google Mobile Ads SDK 会在广告请求中包含 tfat 参数。请咨询您的法律顾问,依据自身法律及监管义务,为用户确定适用的年龄处理方式。 如需了解详情,请参阅将应用发出的广告请求标记为按照年龄限制加以处理。
您可以通过 GADRequestConfiguration 中的 ageRestrictedTreatment 属性来设置年龄处理方式。
设置针对儿童的年龄处理方式
以下示例表明广告请求应按针对儿童的年龄处理方式处理:
Swift
// Indicates that ad requests should have child age treatment.
MobileAds.shared.requestConfiguration.ageRestrictedTreatment = .child
Objective-C
// Indicates that ad requests should have child age treatment.
GADMobileAds.sharedInstance.requestConfiguration.ageRestrictedTreatment =
GADAgeRestrictedTreatmentChild;
设置针对青少年的年龄处理方式
以下示例表明广告请求应按针对青少年的年龄处理方式处理:
Swift
// Indicates that ad requests should have teen age treatment.
MobileAds.shared.requestConfiguration.ageRestrictedTreatment = .teen
Objective-C
// Indicates that ad requests should have teen age treatment.
GADMobileAds.sharedInstance.requestConfiguration.ageRestrictedTreatment =
GADAgeRestrictedTreatmentTeen;
不设置特定的年龄处理方式
以下示例表明广告请求不应按特定年龄的处理方式处理:
Swift
// Indicates that ad requests should have unspecified age treatment.
MobileAds.shared.requestConfiguration.ageRestrictedTreatment = .unspecified
Objective-C
// Indicates that ad requests should have unspecified age treatment.
GADMobileAds.sharedInstance.requestConfiguration.ageRestrictedTreatment =
GADAgeRestrictedTreatmentUnspecified;
从 TFCD 和 TFUA 迁移到年龄处理方式设置
年龄处理方式设置取代了已弃用的 tagForChildDirectedTreatment (TFCD) 和 tagForUnderAgeOfConsent (TFUA) 属性。
下表列出了 tagForChildDirectedTreatment 和 tagForUnderAgeOfConsent 设置及其对等的年龄处理方式:
TFCD
tagForChildDirectedTreatment |
年龄处理方式 |
|---|---|
tagForChildDirectedTreatment = true |
GADAgeRestrictedTreatmentChild |
tagForChildDirectedTreatment = false |
GADAgeRestrictedTreatmentUnspecified |
未为 tagForChildDirectedTreatment 分配值 |
GADAgeRestrictedTreatmentUnspecified |
| 无对等处理方式 | GADAgeRestrictedTreatmentTeen |
TFUA
tagForUnderAgeOfConsent |
年龄处理方式 |
|---|---|
tagForUnderAgeOfConsent = true |
GADAgeRestrictedTreatmentChild |
tagForUnderAgeOfConsent = false |
GADAgeRestrictedTreatmentUnspecified |
未为 tagForUnderAgeOfConsent 分配值 |
GADAgeRestrictedTreatmentUnspecified |
| 无对等处理方式 | GADAgeRestrictedTreatmentTeen |
了解年龄处理方式与 TFCD 和 TFUA 的相互作用
如果您同时设置了年龄处理方式和 TFCD/TFUA,Google 会采用最保守的处理方式。
面向儿童的设置
为了遵守《儿童在线隐私保护法》(COPPA) 的规定,我们提供了一项名为 tagForChildDirectedTreatment 的设置。
作为应用开发者,您可以在发出广告请求时表明是否希望 Google 将您的内容视为面向儿童的内容。如果您表明希望 Google 将您的内容视为面向儿童的内容,Google 便会采取相应措施,针对该广告请求停用针对用户兴趣投放广告 (IBA) 和再营销广告。具体的设置选项如下:
- 将
tagForChildDirectedTreatment设置为true,以表明您希望根据 COPPA 的规定将您的内容视为面向儿童的内容。这会阻止传输广告标识符 (IDFA)。 - 将
tagForChildDirectedTreatment设置为false,以表明您不希望根据《儿童在线隐私保护法》(COPPA) 的规定将您的内容视为面向儿童的内容。 - 如果您不希望表明您想如何根据 COPPA 的规定来认定您的内容,请不要设置
tagForChildDirectedTreatment。
以下示例表明您希望根据 COPPA 的规定将您的内容视为面向儿童的内容:
Swift
MobileAds.shared.requestConfiguration.tagForChildDirectedTreatment = true
Objective-C
GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment = @YES;
设置此标记,即表示您确认此通知准确无误,且您有权代表应用的所有者行事。您了解,滥用此设置可能会导致您的 Google 账号被终止。
未达到同意年龄的用户
您可以对广告请求进行标记,确保针对欧洲经济区 (EEA) 未达到同意年龄的用户进行适当处理。这项功能旨在帮助您遵守《一般数据保护条例》(GDPR)。需要说明的是,您可能还须承担 GDPR 规定的其他法律义务。具体请查看欧盟发布的指导原则,并咨询您的法律顾问。另请注意,Google 的工具旨在协助您遵守相关法规,但并不能免除任何特定发布商按照法律要求所需承担的义务。 详细了解 GDPR 给发布商带来了哪些影响。
使用这项功能时,将来的所有广告请求中都会包含一个用于表示用户位于欧洲且未达到同意年龄的标记 (TFUA) 参数。此参数会禁止针对该广告请求投放个性化广告,包括再营销广告。它还会禁止向第三方广告供应商(例如广告衡量像素和第三方广告服务器)发送请求。
通过在 GADMobileAds.requestConfiguration 对象上设置 tagForUnderAgeOfConsent 属性并传入 true,该设置可用于所有版本的 Google Mobile Ads SDK。
- 将
tagForUnderAgeOfConsent设置为true,以表明您希望按适合未达到同意年龄的用户的方式处理广告请求。这也会阻止传输 IDFA。 - 如果未设置
tagForUnderAgeOfConsent,则表明您不希望按适合未达到同意年龄的用户的方式处理广告请求。
以下示例表明您希望广告请求中包含 TFUA 参数:
Swift
MobileAds.shared.requestConfiguration.tagForUnderAgeOfConsent = true
Objective-C
GADMobileAds.sharedInstance.requestConfiguration.tagForUnderAgeOfConsent = @YES;
不应将用于启用面向儿童的设置的标记和 tagForUnderAgeOfConsent 同时设置为 true。如果同时设置为 true,则以“面向儿童的设置”为准。
广告内容过滤
应用可以使用 GADRequestConfiguration 的 maxAdContentRating 属性为所有广告请求设置广告内容分级上限。此上限设置适用于该会话剩余时间内未来的所有广告请求。此属性可能的值依数字内容标签分类而定,并应该是以下常量之一:
GADMaxAdContentRatingGeneralGADMaxAdContentRatingParentalGuidanceGADMaxAdContentRatingTeenGADMaxAdContentRatingMatureAudience
以下代码会配置所有广告请求,以指定返回的广告内容所对应的数字内容标签不应高于 GADMaxAdContentRatingGeneral。
Swift
MobileAds.shared.requestConfiguration.maxAdContentRating =
GADMaxAdContentRating.general
Objective-C
GADMobileAds.sharedInstance.requestConfiguration.maxAdContentRating =
GADMaxAdContentRatingGeneral;
Publisher Privacy Treatment(Beta 版)
Publisher Privacy Treatment (PPT) API 是一种可选工具,可让应用使用 GADRequestConfiguration 的 publisherPrivacyPersonalizationState 属性表明是否针对所有广告请求关闭广告个性化设置。使用这项功能时,在会话的剩余时间内,未来的所有广告请求中都会包含一个发布商隐私保护处理措施 (PPT) 参数。
默认情况下,向 Google 发送的广告请求会返回个性化广告。以下代码会针对所有广告请求关闭广告个性化设置:
Swift
MobileAds.shared.requestConfiguration.publisherPrivacyPersonalizationState =
.disabled
Objective-C
GADMobileAds.sharedInstance.requestConfiguration.publisherPrivacyPersonalizationState =
GADPublisherPrivacyPersonalizationStateDisabled;
GADRequest
GADRequest 对象可收集随广告请求一起发送的定位信息。
添加广告联盟额外信息
广告联盟额外信息是指随广告请求一起发送的额外详细信息,专属于单个广告来源。
以下代码段为 Google 设置了一个额外的参数键 collapsible(值为 bottom):
Swift
let request = Request()
let extras = Extras()
extras.additionalParameters = ["collapsible": "bottom"]
request.register(extras)
adLoader?.load(request)
Objective-C
GADRequest *request = [GADRequest request];
GADExtras *extras = [[GADExtras alloc] init];
extras.additionalParameters = @{@"collapsible": @"bottom"};
[request registerAdNetworkExtras:extras];
[self.adLoader loadRequest:request];
内容网址
在请求广告时,应用可能会传递自身正在提供的内容的网址。这样就能进行关键字定位,以便根据内容来匹配广告。
例如,如果您的应用在显示来自 https://www.example.com 的内容时请求广告,您可传递此网址来定位相关的关键字:
Swift
let request = Request()
request.contentURL = "https://www.example.com"
Objective-C
GADRequest *request = [GADRequest request];
request.contentURL = @"https://www.example.com";
常见问题解答
- 当广告自动刷新时会使用什么定位?
- 广告刷新时,之前指定的
GADRequest对象会再次用于定位。要设置新的定位,请在GADBannerView上使用新的GADRequest对象明确调用loadRequest。 - 如何将更多定位参数传递到中介广告联盟?
- 如需了解如何将定位信息发送到中介广告联盟,请参阅中介。