Here’s how to integrate the Prebid SDK with AppLovin MAX.
These are the required components:
Here’s how the ad bidding-auction-rendering process works in this integration scenario.
Steps 1-2 Prebid SDK makes a bid request. Prebid Server runs an auction and returns the winning bid.
Step 3 MAX SDK makes an ad request. MAX returns the waterfall with respective placements.
Step 4 For each Prebid placement, the MAX SDK sequentially instantiates one of Prebid’s adapter functions.
Step 5 The adapter function verifies the targeting keywords of the winning bid and the custom properties of the given placement. If they match the adapter will render the winning bid. Otherwise, adpater will fail with “no ad” immediately and the next placement will instantiate the same adapter but for another custom properties.
Assuming your app is already integrated with the AppLovin MAX SDK, the technical implementation of Prebid mobile into your app will involve these major steps:
The Ad Operations team will need to create a Custom Network in AppLovin.
This information may be useful when comparing data across various reporting systems:
Scenario | Tracked? |
---|---|
Fires Prebid win event | yes |
Fires Prebid imp event | no |
Fires OpenRTB burl | no (1) |
Fires OpenRTB nurl | no (1) |
Fires OpenMeasurement events | yes |
Notes:
Prebid SDK is integrated into AppLovin MAX setup via custom adapters. To integrate Prebid Adapters into your app, add the following lines into your build.gradle files:
Root build.gradle
allprojects {
repositories {
...
mavenCentral()
...
}
}
App module build.gradle:
implementation('org.prebid:prebid-mobile-sdk-max-adapters:x.x.x')
Integration example:
// 1. Create MaxAdView
adView = MaxAdView(adUnitId, requireContext())
adView?.setListener(createListener())
adWrapperView.addView(adView)
// 2. Create MaxMediationBannerUtils
val mediationUtils = MaxMediationBannerUtils(adView)
// 3. Create MediationBannerAdUnit
adUnit = MediationBannerAdUnit(
requireContext(),
configId,
AdSize(width, height),
mediationUtils
)
// 4. Make a bid request
adUnit?.fetchDemand {
// 5. Make an ad request to MAX
adView?.loadAd()
}
This step is totally the same as for original MAX integration. You don’t have to make any modifications here.
The MaxMediationBannerUtils
is a helper class, which performs certain utilty work for the MediationBannerAdUnit
, like passing the targeting keywords to the adapters and checking the visibility of the ad view.
The MediationBannerAdUnit
is a part of Prebid mediation API. This class is responsible for making bid request and providing the winning bid and targeting keywords to mediating SDKs.
The fetchDemand
method makes a bid request to prebid server and provides a result in a completion handler.
Now you should make a regular MAX’s ad request. Everything else will be handled by prebid adapters.
Integration example:
// 1. Create MaxInterstitialAd
maxInterstitialAd = MaxInterstitialAd(adUnitId, activity)
maxInterstitialAd?.setListener(createListener())
// 2. Create MaxMediationInterstitialUtils
val mediationUtils = MaxMediationInterstitialUtils(maxInterstitialAd)
// 3. Create MediationInterstitialAdUnit
adUnit = MediationInterstitialAdUnit(
activity,
configId,
EnumSet.of(AdUnitFormat.BANNER),
mediationUtils
)
// 4. Make a bid request
adUnit?.fetchDemand {
// 5. Make an ad request to MAX
maxInterstitialAd?.loadAd()
}
The default ad format for interstitial is DISPLAY. In order to make a multiformat bid request
, set the respective values into the adUnitFormats
parameter.
adUnit = MediationInterstitialAdUnit(
activity,
configId,
EnumSet.of(AdUnitFormat.BANNER, AdUnitFormat.VIDEO),
mediationUtils
)
This step is totally the same as for original MAX integration. You don’t have to make any modifications here.
The MaxMediationInterstitialUtils
is a helper class, which performs certain utilty work for the MediationInterstitialAdUnit
, like passing the targeting keywords to the adapters and checking the visibility of the ad view.
The MediationInterstitialAdUnit
is part of the prebid mediation API. This class is responsible for making a bid request and providing a winning bid to the mediating SDKs.
The fetchDemand
method makes a bid request to prebid server and provides a result in a completion handler.
Now you should make a regular MAX’s ad request. Everything else will be handled by GMA SDK and prebid adapters.
Once you receive the ad it will be ready for display. Folow the MAX instructions about how to do it.
Integration example:
// 1. Get an instance of MaxRewardedAd
maxRewardedAd = MaxRewardedAd.getInstance(adUnitId, activity)
maxRewardedAd?.setListener(createListener())
// 2. Create MaxMediationRewardedUtils
val mediationUtils = MaxMediationRewardedUtils(maxRewardedAd)
// 3. Create MediationRewardedVideoAdUnit
adUnit = MediationRewardedVideoAdUnit(
activity,
configId,
mediationUtils
)
// 4. Make a bid request
adUnit?.fetchDemand {
// 5. Make an ad request to MAX
maxRewardedAd?.loadAd()
}
The way of displaying the rewarded ad is the same as for the Interstitial Ad.
To be notified when user earns a reward follow the MAX intructions.
This step is totally the same as for original MAX integration. You don’t have to make any modifications here.
The MaxMediationRewardedUtils
is a helper class, which performs certain utilty work for the MediationRewardedVideoAdUnit
, like passing the targeting keywords to the adapters.
The MediationRewardeVideoAdUnit
is part of the prebid mediation API. This class is responsible for making a bid request and providing a winning bid and targeting keywords to the adapters.
The fetchDemand
method makes a bid request to the prebid server and provides a result in a completion handler.
Now you should make a regular MAX’s ad request. Everything else will be handled by GMA SDK and prebid adapters.
Once the rewarded ad is received you can display it. Folow the MAX instructions for the details.
Integration example:
// 1. Create MaxNativeAdLoader
nativeAdLoader = MaxNativeAdLoader(adUnitId, requireActivity())
nativeAdLoader.setNativeAdListener(createNativeAdListener(viewContainer))
nativeAdLoader.setRevenueListener(createRevenueListener())
// 2. Create and configure MediationNativeAdUnit
nativeAdUnit = NativeAdUnit(configId)
nativeAdUnit.setContextType(NativeAdUnit.CONTEXT_TYPE.SOCIAL_CENTRIC)
nativeAdUnit.setPlacementType(NativeAdUnit.PLACEMENTTYPE.CONTENT_FEED)
nativeAdUnit.setContextSubType(NativeAdUnit.CONTEXTSUBTYPE.GENERAL_SOCIAL)
// 3. Set up assets for bid request
// See the code below
// 4. Set up event tracker for bid request
// See the code below
// 5. Make a bid request
nativeAdUnit.fetchDemand(nativeAdLoader) {
// 6. Make an ad request to MAX
self?.nativeAdLoader?.loadAd(into: self?.createNativeAdView())
}
Prepare the MaxNativeAdLoader
object before you make a bid request. It will be needed for prebid mediation utils.
The NativeAdUnit
class is responsible for making a bid request and providing a winning bid and targeting keywords. Fot the better targetting you should provide additional properties like conteaxtType
and placemantType
.
The bid request for native ads should have the description of expected assets. The full spec for the native template you can find in the Native Ad Specification from IAB.
The example of creating the assets array:
val title = NativeTitleAsset()
title.setLength(90)
title.isRequired = true
nativeAdUnit.addAsset(title)
val icon = NativeImageAsset(20, 20, 20, 20)
icon.imageType = NativeImageAsset.IMAGE_TYPE.ICON
icon.isRequired = true
nativeAdUnit.addAsset(icon)
val image = NativeImageAsset(200, 200, 200, 200)
image.imageType = NativeImageAsset.IMAGE_TYPE.MAIN
image.isRequired = true
nativeAdUnit.addAsset(image)
val data = NativeDataAsset()
data.len = 90
data.dataType = NativeDataAsset.DATA_TYPE.SPONSORED
data.isRequired = true
nativeAdUnit.addAsset(data)
val body = NativeDataAsset()
body.isRequired = true
body.dataType = NativeDataAsset.DATA_TYPE.DESC
nativeAdUnit.addAsset(body)
val cta = NativeDataAsset()
cta.isRequired = true
cta.dataType = NativeDataAsset.DATA_TYPE.CTATEXT
nativeAdUnit.addAsset(cta)
The bid request for mative ads may have a descrition of expected event trackers. The full spec for the Native template you can find in the Native Ad Specification from IAB.
The example of creating the event trackers array:
val methods: ArrayList<NativeEventTracker.EVENT_TRACKING_METHOD> = ArrayList()
methods.add(NativeEventTracker.EVENT_TRACKING_METHOD.IMAGE)
methods.add(NativeEventTracker.EVENT_TRACKING_METHOD.JS)
try {
val tracker = NativeEventTracker(NativeEventTracker.EVENT_TYPE.IMPRESSION, methods)
nativeAdUnit.addEventTracker(tracker)
} catch (e: Exception) {
e.printStackTrace()
}
The fetchDemand
method makes a bid request to prebid server and provides a result in a completion handler.
Now just load a native ad from MAX according to the MAX instructions.