This how-to guide covers the ‘Prebid-Rendered’ approach for integrating the Prebid SDK into your app with the GMA SDK. It utilizes:
If you do not have GMA SDK in the app yet, refer to the Google Integration Documentation.
Another way to integrate GAM into your app is with the GAM Bidding-Only integration.
Tradeoffs between these integration approaches:
Aspect | Bidding-Only Integration | Prebid-Rendered Integration |
---|---|---|
App code has direct access to bids | ||
Support for MRAID 3.0 | ||
Support for SKAdnetwork | ||
Loads data from Prebid Cache | ||
Supports instream video | ||
Triggers billing and Notice URLs | ||
Supports Third Party Rendering libraries |
Notes:
The GAM Prebid-Rendered Integration method assumes that you have the following components:
Here’s how the ad bidding-auction-rendering process works in this integration scenario.
Assuming your app already has AdUnits integrated with the GMA SDK, the technical implementation of Prebid mobile into your app will involve these major steps:
The AdOps team will need to create line items in GAM. The creatives used depend on which media formats your adunits utilize:
AdUnit Format | Line Item Targeting | Creative Type | Prebid Cache? | Ad Ops Details |
---|---|---|---|---|
HTML banner, interstitial banner or video, non-instream video | hb_pb hb_format=banner |
3rd party HTML that loads google_mobile_app_ads.js | no | link |
Instream Video | hb_pb hb_format=video inventoryType in (instream, mobile app) |
VastUrl pointing to Prebid Cache | yes | link |
Rewarded Video | hb_pb hb_format=video inventoryType in (instream, mobile app) rewarded adunits |
VastUrl pointing to prebid-mobile-rewarded-vast.xml | no | link |
In-app native | hb_pb hb_format=native |
GAM native | no | link |
Notes:
This information may be useful when comparing data across various reporting systems:
Scenario | 3pHTML Creative | VastUrl Creative | GAM Native Creative |
---|---|---|---|
Rendering Method | js in iframe fires an event | GMA SDK player | App code with data from PBSDK |
Fires Prebid win event | always | never | always |
Fires Prebid imp event | never | VAST impression tag | never |
Fires OpenRTB burl | never | n/a | never |
Fires OpenRTB nurl | never | n/a | never |
Fires OpenMeasurement events | PBSDK | n/a | PBSDK |
Notes:
First, a little bit of setup is needed.
Prebid SDK provides rendering integration into the GMA SDK setup with the app events mechanism. To integrate Prebid Event Handlers into your app, add the following line to your Podfile:
pod 'PrebidMobileGAMEventHandlers'
Warning: GMA SDK is a closed library that sometimes works in unexpected ways. The GADMobileAds.sharedInstance().start()
should be called in all bundles where it is used. Otherwise, GMA SDK won’t load the ads with an error of: adView:didFailToReceiveAdWithError: SDK tried to perform a networking task before being initialized.
To avoid this error add the following line to your app right after initialization of GMA SDK:
GAMUtils.shared.initializeGAM()
This section covers integration details for different ad formats. In each scenario, you’ll be asked for a configId
- this is a key worked out with your Prebid Server provider. It’s used at runtime to pull in the bidders and parameters specific to this adunit. Depending on your Prebid Server partner, it may be a UUID or constructed out of parts like an account number and adunit name.
Integration example:
// 1. Create an Event Handler
let eventHandler = GAMBannerEventHandler(adUnitID: GAM_AD_UNIT_ID,
validGADAdSizes: [NSValueFromGADAdSize(adSize)])
// 2. Create a Banner View
let banner = BannerView(configID: CONFIG_ID,
eventHandler: eventHandler)
banner.delegate = self
addBannerToUI(banner: banner)
// 3. Load an Ad
banner.loadAd()
To create the GAMBannerEventHandler
you should provide:
BannerView
- is a view that will display the particular ad. It should be added to the UI. To create a BannerView you should provide:
configID
- an ID of Stored Impression on the Prebid servereventHandler
- the instance of the banner event handlerYou should also add the instance of BannerView
to the UI.
Call the method loadAd()
which will:
For non-instream Banner Video you also need to specify the ad format:
banner.adFormat = .video
The rest of the code will be the same as for integration of Display Banner.
GAM setup:
Integration:
GAMBannerView
with BannerView
in the UI.BannerViewDelegate
in the ViewController.GAMBannerView
, GAMRequest
, and implementation of the GADBannerViewDelegate
.BannerAdUnit
.Integration example:
// 1. Create Event Handler
let eventHandler = GAMInterstitialEventHandler(adUnitID: GAM_AD_UNIT_ID)
// 2. Create Interstitial Ad Unit
interstitial = InterstitialRenderingAdUnit (configID: CONFIG_ID,
minSizePercentage: CGSize(width: 30, height: 30),
eventHandler: eventHandler)
interstitial.delegate = self
// 3. Load an Ad
interstitial.loadAd()
/// .......
// 4. Show Ad
if interstitial.isReady {
interstitial.show(from: self)
}
The default ad format for interstitial is .banner. In order to make a multiformat bid request
, set the respective values in the adFormats
property.
// Make bid request for video ad
adUnit?.adFormats = [.video]
// Make bid request for both video amd disply ads
adUnit?.adFormats = [.video, .banner]
// Make bid request for banner ad (default behaviour)
adUnit?.adFormats = [.banner]
To create an event handler you should provide a GAM Ad Unit.
Initialize the InterstitialRenderingAdUnit
with properties:
configID
- an ID of Stored Impression on the Prebid serverminSizePercentage
- specifies the minimum width and height percent an ad may occupy of a device’s real estate.eventHandler
- the instance of the interstitial event handlerNOTE: the
minSizePercentage
- plays an important role in the bidding process for display ads. If provided space is not enough demand partners won’t respond with bids.
Call the method loadAd()
which will make a bid request to Prebid Server.
Wait for the Prebid Server to return an ad and show it to the user in any suitable time.
// MARK: InterstitialRenderingAdUnitDelegate
func interstitialDidReceiveAd(_ interstitial: InterstitialAdUnit) {
// Now the ad is ready for display
}
GAM setup:
Integration:
GAMInterstitialAd
with InterstitialRenderingAdUnit
in the View Controller.InterstitialAdUnitDelegate
in the View Controller.GAMInterstitialAd
, GAMRequest
.InterstitialAdUnit
.Integration example:
// 1. Create an Event Handler
let eventHandler = GAMRewardedEventHandler(adUnitID: GAM_AD_UNIT_ID)
// 2. Create an Ad Unit
rewardedAd = RewardedAdUnit(configID: CONFIG_ID,
eventHandler: eventHandler)
rewardedAd.delegate = self
// 3. Load an Ad
rewardedAd.loadAd()
/// .......
// 4. Display Ad
if rewardedAd.isReady {
rewardedAd.show(from: self)
}
The proccess for displaying the Rewarded Ad is the same as for the Interstitial Ad.
To be notified when a user earns a reward - implement the method of RewardedAdUnitDelegate
:
- (void)rewardedAdUserDidEarnReward:(RewardedAdUnit *)rewardedAd;
The reward object is stored in the RewardedAdUnit
:
if let reward = rewardedAd.reward as? GADAdReward {
// ...
}
To create an event handler you should provide a GAM Ad Unit ID.
Create the RewardedAdUnit
object with parameters:
configID
- an ID of Stored Impression on the Prebid servereventHandler
- the instance of rewarded event handlerCall the loadAd()
method which will make a bid request to Prebid server.
Wait for the ad to load and display it to the user in any suitable time.
// MARK: RewardedAdUnitDelegate
func rewardedAdDidReceiveAd(_ rewardedAd: RewardedAdUnit) {
// Now the ad is ready for display
}
GAM setup:
Integration:
GADRewardedAd
with RewardedAdUnit
in the View Controller.RewardedAdUnitDelegate
in the View Controller.GAMRequest
.RewardedVideoAdUnit
.Each ad unit in the original integration method is a subclass of the AdUnit
class, which provides the following properties and methods for the additional configuration.
If set on a given banner adunit, the fetchDemand
function will be called every periodMillis
until stopAutoRefresh
is called. Each call to fetchDemand
will invoke the onComplete
function. This refresh only pertains to Prebid Mobile and not to any ad server refresh processes. It is suggested that the adServes refresh be turned off.
Halts the auto-refresh behavior for a given Prebid Mobile ad unit. If no auto-refresh behavior has been set, stopAutoRefresh
will be ignored.
Resumes a stopped autorefresh for the ad unit with the previously-defined autorefresh value.
(requires SDK v2.1.6)
The Global Placement ID (GPID) is a key that uniquely identifies a specific instance of an adunit. Some bidders require this value. An important scenario is “infinite scroll” – if your app creates instances of an adunit dynamically as the user scrolls through content, the the GPID must be different for each by appending some kind of sequence or ID. e.g. “/newsfeed#7”
Using the following method, you can set the impression-level GPID value to the bid request:
adUnit.setGPID("/36117602/hnp-sfgate.com/Homepage/AP300")