The Google Mobile Ads SDK supports monetizing your apps with an Ad Exchange property. This guide shows you how to configure your apps for all ad formats supported by Ad Exchange.
Prerequisites
Configure your app for accessing Ad Exchange
Update your app's Info.plist file to set the GADApplicationIdentifier
key with
a string value of your Ad Manager app ID (identified in the Ad Manager
UI).
Note also that failure to set the GADApplicationIdentifier
key in the
info.plist file as shown above results in a crash with the message:
Terminating app due to uncaught exception 'GADInvalidInitializationException',
reason: 'The Google Mobile Ads SDK was initialized without an application ID.
Google AdMob publishers, follow instructions at
https://goo.gle/admob-ios-update-plist to set a valid
application ID. Google Ad Manager publishers, follow instructions at
https://goo.gle/ad-manager-ios-update-plist.'
Next, you can select an ad format to display. The rest of this guide implements the banner format to illustrate how you can load an ad from Ad Exchange. The same steps can apply to any ad formats supported by the Google Mobile Ads SDK.
Load an ad from Ad Exchange
You can use an Ad Exchange web property code with a trailing forward slash, in your app in place of an ad unit ID.
In order to load and display banner ads, GAMBannerView
requires an adUnitID
.
You can set this property to an Ad Exchange web property ID as follow:
override func viewDidLoad() {
super.viewDidLoad()
...
bannerView.adUnitID = "ca-mb-app-pub-5629679302779023/"
bannerView.rootViewController = self
}
Note that failure to add a trailing forward slash to the Ad Exchange web property code as shown above results in an ad request error with the message:
Invalid Request. Cannot determine request type. Is your ad unit id correct?
Note also that you can convert an Ad Exchange web property code into an ad unit.
After that you can use the Ad Manager UI to generate an Ad Exchange
Tag and copy it into your
app. The generated tag should have the Ad Exchange web property code, followed
by descendant ad unit IDs without a trailing forward slash, for example:
ca-mb-app-pub-5629679302779023/banner
Once the GAMBannerView
is in place and its properties configured, you can
load an ad and customize the
behavior of your ad using ad
events.
That's it! Your app is now ready to load and display banner ads from Ad Exchange.
In addition, you can use an Ad Exchange web property to load and display other ad formats from Ad Exchange by following respective guides:
(Approved European publishers only) Add price floors
You can submit a request for the "Price floors" feature.
Once approved, you can include a public floor or private floor in the ad request
using the pubf
and pvtf
parameters respectively. In the following code
example, replace "123" with the floor prices in micros and your network's
default currency. Example of how
micros are applied: if your default currency is USD, entering "6000000" is the
equivalent of $6.00.
Swift
let extras = GADAdNetworkExtras()
extras.additionalParameters = ["pubf": "123", "pvtf": "123"]
let request = GAMRequest()
request.register(extras)
Objective-C
GADAdNetworkExtras *extras = [[GADAdNetworkExtras alloc] init];
extras.additionalParameters = @{@"pubf": @"123", @"pvtf": @"123"};
GAMRequest *request = [GAMRequest request];
[request registerAdNetworkExtras:extras];