本指南介绍了如何在植入了广告的应用中接收测试广告。我们建议在开发期间使用测试广告;这样当您测试点击行为时,既不会影响预订型广告系列的统计信息,也不会向广告客户收费。
前提条件
- 完成入门指南。
演示广告单元
启用测试的最快方法是使用 Google 提供的演示广告单元。这些广告单元未与您的 Ad Manager 账号相关联,因此在使用这些广告单元时,您的账号不会产生无效流量。
下面列出了多个演示广告单元,分别对应一种格式的特定测试广告素材:
广告格式 | 演示广告单元 ID |
---|---|
开屏广告 | /21775744923/example/app-open |
自适应横幅广告 | /21775744923/example/adaptive-banner |
固定大小的横幅广告 | /21775744923/example/fixed-size-banner |
插页式广告 | /21775744923/example/interstitial |
激励广告 | /21775744923/example/rewarded |
插页式激励广告 | /21775744923/example/rewarded-interstitial |
原生代码 | /21775744923/example/native |
原生视频广告 | /21775744923/example/native-video |
启用测试设备(测试模式)
如果您希望使用实际投放的广告进行更严格的测试,那么您现在可以将您的设备配置为测试设备,并使用您在 Ad Manager 界面中自行创建的广告单元 ID。
请按照以下步骤操作,将您的设备添加为测试设备。
以编程方式添加测试设备
如果您希望在应用开发过程中测试广告,请按照以下步骤以编程方式注册您的测试设备。
- 加载您的已植入广告的应用,并发出广告请求。
- 检查控制台中有没有类似以下内容的消息:
将测试设备 ID 复制到剪贴板。<Google> To get test ads on this device, set: GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = @[ @"2077ef9a63d2b398840261c8221a0c9b" ];
- 修改代码,通过
testDeviceIdentifiers
设置测试设备 ID:
Swift
let testDeviceIdentifiers = ["2077ef9a63d2b398840261c8221a0c9b"]
MobileAds.shared.requestConfiguration.testDeviceIdentifiers = testDeviceIdentifiers
Objective-C
NSArray *testDeviceIdentifiers = @[ @"2077ef9a63d2b398840261c8221a0c9b" ];
GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = testDeviceIdentifiers;

For native advanced ads, the headline asset is prepended with the string
**Test mode**.
<img class="screenshot" src="/admob/images/native-testad-ios.png"
style="max-width:400px;"/>
Ads with this **Test mode** label are safe to click. Requests, impressions, and
clicks on ads in test mode will not show up in your account's reports.
<aside>Mediated ads do <em>NOT</em> render a **Test mode** label. See the section
below for details.</aside>
使用中介进行测试
Google 的演示广告单元只展示 Google 广告。如需测试中介配置,您必须使用“启用测试设备”的做法。
参与中介的广告不会呈现测试模式标签。所以,您要负责确保为每个中介广告联盟启用测试模式,以便这些广告联盟不会因为无效活动而举报您的账号。如需了解详情,请参阅每个广告联盟各自的中介指南。
如果您不确定某个中介广告联盟适配器是否提供测试模式,则最安全的做法是避免在开发期间点击来自该广告联盟的广告。您可以对所有广告格式使用 adNetworkClassName
属性,以确定哪个广告联盟投放了当前广告。