Mediate Native Third Party Ad Networks (draft) - MoPub-Solutions-Eng/mopub.wiki.android.native.betasite GitHub Wiki
The MoPub SDK can mediate any native ad network SDK through our custom events capabilities. As a developer, this allows you to serve ads from multiple networks. In order to mediate third party native ads, you must have already integrated MoPub native ads.
Note: Please refer to our network supported page for certified versions
To set up native integration for a different network, see our documentation on Custom Events.
Native Third-Party Integration Guide
1. Set up a Third-Party Network in your MoPub Account
- Add a Built-in Network
- Navigate to the Networks section of your UI, select the “Add A Network”.
- Choose your desired network
- Enter your network's ad unit id in the field provided.
- Add a Custom Native Network
- Navigate to the Networks section of your UI, select the “Add A Network” > Custom Native Network.
- Name your custom network
- Enter your network's custom event class name and custom event data in the fields
Note: MoPub will automatically initiate the custom event class names, make sure the naming convention and location in the app match exactly what is listed above.
1. (Optional) Set up Revenue Reporting
2. Add the adapter (custom event) files to your project
Add a package folder named ‘nativeads’ into com.mopub
under your app’s src/
directory as below:
and copy the adapters from extras/com/mopub/nativeads folder which contains a set of custom events; simply copy the ones you want into your com.mopub.nativeads
under your app’s src/
directory.
If you don't have the extras folders in your SDK, you will need to clone the MoPub SDK repo:
git clone https://github.com/mopub/mopub-android-sdk.git
3. Link the third-party SDKs
Incorporate the third-party SDKs into your project. This typically involves having a line in your build.gradle
file. Specific instructions can be found by visiting the ad networks' developer pages. For example:
dependencies {
...
compile 'com.facebook.android:audience-network-sdk:4.15.0'
compile 'com.flurry.android:ads:6.5.0'
compile 'com.google.android.gms:play-services-ads:10.2.0'
}
4. Add the appropriate renderers for each network
To ensure your native ad views are laid out as intended, create and register the appropriate renderer for each network. Don't forget the default MoPubStaticNativeAdRenderer
. This varies on your integration. You only need to register the renderers once, and you should choose the most appropriate class to call it on. We recommend that you use the MoPubRecyclerAdapter
.
Creating the renderers:
// Some third party SDKs rely on the MoPub renderer as a default renderer.
final MoPubStaticNativeAdRenderer staticAdRender = new MoPubStaticNativeAdRenderer(
new ViewBinder.Builder(R.layout.native_ad_list_item)
.titleId(R.id.native_title)
.textId(R.id.native_text)
.mainImageId(R.id.native_main_image)
.iconImageId(R.id.native_icon_image)
.callToActionId(R.id.native_cta)
.privacyInformationIconImageId(R.id.native_privacy_information_icon_image)
.build());
// Facebook Audience Network
final FacebookAdRenderer facebookAdRenderer = new FacebookAdRenderer(
new ViewBinder.Builder(R.layout.native_ad_list_item)
.titleId(R.id.native_title)
.textId(R.id.native_text)
.mainImageId(R.id.native_main_image)
.iconImageId(R.id.native_icon_image)
.callToActionId(R.id.native_cta)
.privacyInformationIconImageId(R.id.native_privacy_information_icon_image)
.build());
// Flurry
Map<String, Integer> extraToResourceMap = new HashMap<>(3);
extraToResourceMap.put(FlurryCustomEventNative.EXTRA_SEC_BRANDING_LOGO,
R.id.flurry_native_brand_logo);
extraToResourceMap.put(FlurryCustomEventNative.EXTRA_APP_CATEGORY,
R.id.flurry_app_category);
extraToResourceMap.put(FlurryCustomEventNative.EXTRA_STAR_RATING_IMG,
R.id.flurry_star_rating_image);
ViewBinder flurryBinder = new ViewBinder.Builder(R.layout.native_ad_flurry_list_item)
.titleId(R.id.flurry_native_title)
.textId(R.id.flurry_native_text)
.mainImageId(R.id.flurry_native_main_image)
.iconImageId(R.id.flurry_native_icon_image)
.callToActionId(R.id.flurry_native_cta)
.addExtras(extraToResourceMap)
.build();
FlurryViewBinder flurryViewBinder = new FlurryViewBinder.Builder(flurryBinder)
.videoViewId(R.id.flurry_native_video_view)
.build();
final FlurryNativeAdRenderer flurryRenderer = new FlurryNativeAdRenderer(flurryViewBinder);
// AdMob
final GooglePlayServicesAdRenderer googlePlayServicesAdRenderer = new GooglePlayServicesAdRenderer(
new ViewBinder.Builder(R.layout.native_ad_list_item)
.titleId(R.id.native_title)
.textId(R.id.native_text)
.mainImageId(R.id.native_main_image)
.iconImageId(R.id.native_icon_image)
.callToActionId(R.id.native_cta)
.privacyInformationIconImageId(R.id.native_privacy_information_icon_image)
.build());
There are a few ways to use the MoPub Native SDK. Only choose one of these for your integration.
- Our recommendation is that you use
RecyclerView
withMoPubRecyclerAdapter
:
MoPubRecyclerAdapter classThatRegistersAdRenderers = new MoPubRecyclerAdapter(...);
- If you're using the
MoPubStreamAdPlacer
:
MoPubStreamAdPlacer classThatRegistersAdRenderers = new MoPubStreamAdPlacer(...);
- If you're using the
MoPubAdAdapter
:
MoPubAdAdapter classThatRegistersAdRenderers = new MoPubAdAdapter(...);
- If you're using
MoPubNative
for manual integration:
MoPubNative classThatRegistersAdRenderers = new MoPubNative(...);
Then register the ad renderers based on the way you're using the MoPub Native SDK.
Make sure to register the default MoPubStaticNativeAdRenderer
last:
classThatRegistersAdRenderers.registerAdRenderer(googlePlayServicesAdRenderer);
classThatRegistersAdRenderers.registerAdRenderer(flurryRenderer);
classThatRegistersAdRenderers.registerAdRenderer(facebookAdRenderer);
classThatRegistersAdRenderers.registerAdRenderer(staticAdRender);
5. You're good to go!
Be sure to set up corresponding network campaigns and target the proper ad units in your MoPub account. For additional questions, take a look at our Support Center.
Migrating Custom Native Network to Build-in Network
https://www.mopub.com/resources/docs/mopub-network-mediation/setting-up-ad-networks/
https://www.mopub.com/resources/docs/mopub-network-mediation/
https://www.mopub.com/resources/docs/mopub-network-mediation/admob-native/