本指南介绍如何向广告请求提供定位信息。
若要查看广告定位的实际运作情况,请下载 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;
GAMRequest
GAMRequest 对象可收集随广告请求一起发送的定位信息。
添加广告联盟额外信息
广告联盟额外信息是指随广告请求一起发送的额外详细信息,专属于单个广告来源。
以下代码段为 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 = AdManagerRequest()
request.contentURL = "https://www.example.com"
Objective-C
GAMRequest *request = [GAMRequest request];
request.contentURL = @"https://www.example.com";
自定义定位
在 Ad Manager 界面中配置键值对后,在广告请求中设置包含这些键值的自定义定位条件。然后,定位到这些键值的订单项便可响应该广告请求来投放广告。如需为一个键定位多个值,请输入以英文逗号分隔的值字符串。
Swift
let request = AdManagerRequest()
request.customTargeting = ["gender" : "male", "section" : "health,fitness"];
Objective-C
GAMRequest *request = [GAMRequest request];
request.customTargeting = @{@"gender" : @"male", @"section" : @"health,fitness"};
品牌保障(Beta 版)
针对各种受众群体显示动态内容的应用可以通过 neighboringContentURLs 属性提供一个简短的网址列表。相邻内容网址与 contentURL 属性的区别在于,前者仅用于品牌保障。
假设您的应用显示的内容来自 Feed 中的 4 个网址,并且该 Feed 中还包含广告。您可以请求与这些网址的内容分级相近的广告,具体传递方式如下:
Swift
let request = AdManagerRequest()
request.neighboringContentURLs =
["https://www.example1.com", "https://www.example2.com",
"https://www.example3.com", "https://www.example4.com"]
Objective-C
GAMRequest *request = [GAMRequest request];
request.neighboringContentURLs =
@[@"https://www.example1.com", @"https://www.example2.com",
@"https://www.example3.com", @"https://www.example4.com"];
发布商提供的标识符 (PPID)
您可以设置 PPID,用于实现跨设备的频次上限、受众群细分和定位、广告依序轮播和其他基于受众群体的广告投放控制。
PPID 设置是通过 GAMRequest 完成的:
Swift
let request = AdManagerRequest()
request.publisherProvidedID = "AB123456789"
Objective-C
GAMRequest *request = [GAMRequest request];
request.publisherProvidedID = @"AB123456789";
有关 iOS API Demo 应用中 PPID 的实现方式,请参阅 Ad Manager PPID 示例:
发布商提供的信号
您可以在广告请求中,将受众群体和情境数据作为发布商提供的信号 (PPS) 进行发送。借助 PPS,您可以通过标准类目,将您的受众群体特征传递给所有交易类型中的出价方,从而利用您的用户数据提升程序化变现能力。您的受众群体特征可能包括行为数据和兴趣数据(IAB 受众群体类目 1.1)以及情境数据(IAB 内容类目 2.2)。
Swift
let extras = Extras()
extras.additionalParameters = [
// Set the demographic to an audience with an "Age Range" of 30-34 and an
// interest in mergers and acquisitions.
"IAB_AUDIENCE_1_1": [6, 284],
// Set the content to sedan, station wagon and SUV automotive values.
"IAB_CONTENT_2_2": [4, 5, 6]
]
let request = AdManagerRequest()
request.register(extras)
Objective-C
GADExtras *extras = [[GADExtras alloc] init];
extras.additionalParameters = @{
// Set the demographic to an audience with an "Age Range" of 30-34 and an
// interest in mergers and acquisitions.
@"IAB_AUDIENCE_1_1":@[@6, @284],
// Set the content to sedan, station wagon and SUV automotive values.
@"IAB_CONTENT_2_2":@[@4,@5,@6]
};
GAMRequest *request = [GAMRequest request];
[request registerAdNetworkExtras:extras];
常见问题解答
- 当广告自动刷新时会使用什么定位?
- 广告刷新时,之前指定的
GAMRequest对象会再次用于定位。要设置新的定位,请在GAMBannerView上使用新的GAMRequest对象明确调用loadRequest。 - 如何将更多定位参数传递到中介广告联盟?
- 如需了解如何将定位信息发送到中介广告联盟,请参阅中介。