You can use the Prebid SDK to monetize your app with a custom ad server or even without an ad server at all.
This guide outlines how to integrate the Prebid SDK into your app if you don’t fit into any of the other approaches documented on the site. Since there are many unknown details about your specific situation, guidance will remain general.
General components:
Custom integrations will need to determine whether they want to utilize Prebid SDK’s full rendering capacity, or just obtain bids to do their own rendering.
Here are the tradeoffs between two integration approaches:
Aspect | Bidding-Only Integration | Prebid-Rendered Integration |
---|---|---|
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 technical implementation of Prebid mobile into your app will involve these major steps:
If you’re using an ad server, the Ad Operations team will need to create line items. If you’re not using an ad server, the app code will need to generate an appropriate response to render the winning ad.
The creatives used depend on which media formats your adunits can utilize. The details for what creatives are needed for each ad format will depend on the type of integration:
The code implementation details depend on which rendering approach you’ve chosen:
While the default ad server for Prebid’s Mobile SDK is GAM, it can be expanded to include support for 3rd party ad servers through the fetchDemand function. This function returns the Prebid Server bidder key/values (targeting keys), which can then be passed to the ad server of choice.
In this mode, the developer is responsible for the following actions:
fetchDemand()
with extended targetingDict callbackThis approach is available for the following ad formats:
BannerAdUnit
VideoAdUnit
InterstitialAdUnit
VideoInterstitialAdUnit
RewardedVideoAdUnit
NativeRequest
The basic steps for these ad units you can find on the page for GAM Bidding Only integration. The difference is that you should use the fetchDemand
function with the following signature:
public void fetchDemand(OnFetchDemandResult listener) { ... }
public interface OnFetchDemandResult {
void onComplete(@NonNull BidInfo bidInfo);
}
Examples:
adUnit?.fetchDemand { bidInfo ->
if(bidInfo.getResultCode() == ResultCode.SUCCESS) {
val keywords = bidInfo.targetingKeywords
makeAdRequest(keywords)
}
}
The BidInfo
provides the following properties:
resultCode
- the object of type ResultCode
describing the status of the bid response.targetingKeywords
- the targeting keywords of the winning bidexp
- the number of seconds that may elapse between the auction and the actual impression. In this case, it indicates the approximate TTL of the bid in the Prebid Cache. Note that the actual expiration time of the bid will be less than this number due to the network and operational overhead. The Prebid SDK doesn’t make any adjustments to this value.nativeAdCacheId
- the local cache ID of the winning bid. Applied only to the native
ad format.events
- the map of some publically available event URLs attached to the bid. These can be used to enable Prebid Server-based analytics when the Prebid Universal Creative (PUC) is not involved in the rendering process. If the PUC is used for rendering, it will take care of hitting these events. These are the available event URLs:
seatbid.bid.ext.prebid.events.win
field. (requires SDK v2.1.6)seatbid.bid.ext.prebid.events.imp
field. (requires SDK v2.1.6)Code sample to extract the events:
val win = bidInfo.events.get(BidInfo.EVENT_WIN)
val imp = bidInfo.get(BidInfo.EVENT_IMP)
The integration and usage of the Rendering API is similar to any other ad SDK. It sends the bid requests to the Prebid Server and renders the winning bid.
Integration example:
// 1. Create an Ad View
bannerView = BannerView(requireContext(), configId, adSize)
bannerView?.setBannerListener(this)
// Add view to viewContainer
viewContainer?.addView(bannerView)
// 2. Load ad
bannerView?.loadAd()
loadAd()
should be called on the main thread.
Initialize the BannerAdView
with properties:
configId
- an ID of a Stored Impression on the Prebid serversize
- the size of the ad unit which will be used in the bid request.Call loadAd()
and SDK will:
Banner Video is the same as HTML banner, but you will also need to specify the bannerView.videoPlacementType
:
bannerView.videoPlacementType = PlacementType.IN_BANNER // or any other available type
Integration example:
// 1. Create an Interstitial Ad Unit
interstitialAdUnit = InterstitialAdUnit(requireContext(), configId, minSizePercentage)
interstitialAdUnit?.setInterstitialAdUnitListener(this)
// 2. Load Ad
interstitialAdUnit?.loadAd()
// .....
// 3. Show the ad
interstitialAdUnit?.show()
loadAd()
should be called on the main thread.
The default ad format for interstitial is DISPLAY. In order to make a multiformat bid request
, set the respective values into the adUnitFormats
parameter.
interstitialAdUnit = InterstitialAdUnit(
requireContext(),
configId,
EnumSet.of(AdUnitFormat.BANNER, AdUnitFormat.VIDEO))
Initialize the InterstitialAdUnit
with properties:
configId
- an ID of a Stored Impression on the Prebid serverminSizePercentage
- specifies the minimum width and height percent an ad may occupy of a device’s real estate.You can also assign the listener to process ad events.
NOTE: the
minSizePercentage
- plays an important role in the bidding process for display ads. If the provided space is not enough demand partners won’t respond with bids.
Call the loadAd()
to make a bid request.
Wait until the ad is loaded and present it to the user in any suitable time.
override fun onAdLoaded(interstitialAdUnit: InterstitialAdUnit) {
//Ad is ready for display
}
Integration example:
// 1. Create an Ad Unit
rewardedAdUnit = RewardedAdUnit(requireContext(), configId)
rewardedAdUnit?.setRewardedAdUnitListener(this)
// 2. Execute the loadAd function
rewardedAdUnit?.loadAd()
/// .......
// After the ad is loaded you can execute `show` to trigger ad display
rewardedAdUnit?.show()
loadAd()
should be called on the main thread.
Create the RewardedAdUnit
object with parameters:
adUnitId
- an ID of Stored Impression on the Prebid server.Call the loadAd()
to make a bid request.
Wait until the ad is loaded and present it to the user in any suitable time.
override fun onAdLoaded(rewardedAdUnit: RewardedAdUnit) {
//Ad is ready for display
}
The adPosition
property allows developers to specify the position of the ad within the publisher’s content. This property maps to the pos
field in the OpenRTB specification under the imp[].banner
or imp[].video
objects, depending on the ad format. The possible values for this field could be found in the respective specification.
You can set adPosition
by using the following method:
adUnit.setAdPosition(AdPosition.FOOTER);