Mopub

Mediating AdTiming through Mopub (Native, Interstitial, video supported only) 

1. Add your new app and set up the ad placement of Native, Interstitial or video through Mopub platform
 
2. Navigate to Neworks → Custom Network → choose the SDK Network Type
 

mopub_adapter_1.png


mopub_adapter_2.png


mopub_adapter_3.png

3. Description of the settings for Custom Network

■ Custom Event class: Required field. It is the Implementation Class of Mopub Adapter.

• Interstitial: com.mopub.mobileads.AdtInterstitial
• Video: com.mopub.mobileads.AdtVideo
• Native: com.mopub.nativeads.AdtNative
■ Custom Event class Data: Required field. The Parameter passed to the Adapter.

• JSON-formatted String: {"app_key":"","placement_id":""}

4. Set up Segments, enable Segments, while disabled by default

mopub_adapter_4.png

5. Refer to the Mopub official documents for InterstitialAd and RewardedVideoAd: official website → The section of Interstitial and Rewarded Video
 
6. The call of Mopub Adapter(Native): Please refer to the case of Mopub Native Invocation:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView android:id="@+id/privacy_information_icon_image"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
/>

<!—Ads Title Optional -->
<TextView android:id="@+id/native_ad_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="title"
android:layout_below="@+id/privacy_information_icon_image"
/>

<—Ads icon Optional -->
<com.adtiming.mediationsdk.nativead.AdIconView
android:id="@+id/iconMediaView"
android:layout_width="250dp"
android:layout_height="175dp"
android:layout_below="@+id/native_ad_title"
android:layout_centerHorizontal="true">

  <ImageView android:id="@+id/native_ad_icon_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
/>
</com.adtiming.mediationsdk.nativead.AdIconView>

<!—Ads content Optional -->
<TextView android:id="@+id/native_ad_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/iconMediaView"
android:layout_centerHorizontal="true"
android:text="text"
/>

<!—Large Graph for Ads Optional -->
<com.adtiming.mediationsdk.nativead.MediaView
android:id="@+id/mediaView"
android:layout_width="250dp"
android:layout_height="175dp"
android:layout_below="@+id/native_ad_text"
android:layout_centerHorizontal="true" >
<ImageView android:id="@+id/native_ad_main_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
/>
</com.adtiming.mediationsdk.nativead.MediaView>
<!—Button for Ads Optional -->
<Button
android:id="@+id/ad_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:text="btn"
android:textAllCaps="false"
android:layout_below="@+id/mediaView"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
import com.mopub.nativeads.AdtMoPubStaticNativeAdRenderer;
import com.mopub.nativeads.AdtViewBinder;
import com.mopub.nativeads.MoPubNative;
import com.mopub.nativeads.NativeAd;
import com.mopub.nativeads.NativeErrorCode;
...
private MoPubNative moPubNative;
private RelativeLayout adParent;
private NativeAd mNativeAd;
//Load the ad
public void loadNativeAd(View view) {  
    adParent.removeAllViews();
    mNativeAd = null;
    AdtViewBinder viewBinder = new AdtViewBinder.Builder(R.layout.mopub_native_ad_layout)
       .privacyInformationIconImageId(R.id.privacy_information_icon_image)
       .titleId(R.id.native_ad_title)
       .textId(R.id.native_ad_text)
       .iconImageId(R.id.native_ad_icon_image)
       .mainImageId(R.id.native_ad_main_image)
       .callToActionId(R.id.ad_btn)
       .mediaViewId(R.id.mediaView)
       .adIconViewID(R.id.iconMediaView)
       .build();

    moPubStaticNativeAdRenderer = new AdtMoPubStaticNativeAdRenderer(viewBinder, this);
    // The parent container for native ads must be set
    moPubStaticNativeAdRenderer.setAdParent(adParent);
    moPubNative = new MoPubNative(this, adUnitId, this);
    moPubNative.registerAdRenderer(moPubStaticNativeAdRenderer);
    moPubNative.makeRequest();
}

//Show the ad
public void showNativeAd(View view) {
   if (mNativeAd == null) {
       return;
   }

   View adView = moPubStaticNativeAdRenderer.createAdView(this, null);
   RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
          RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
   layoutParams.addRule(Gravity.CENTER);
   adParent.removeAllViews();
   adParent.addView(adView, layoutParams);
   mNativeAd.prepare(adView);
   mNativeAd.renderAdView(adView);
}

//Successful callback of native ad loading of Mopub
@Override
public void onNativeLoad(NativeAd nativeAd) {
    mNativeAd = nativeAd;
    nativeAd.setMoPubNativeEventListener(new NativeAd.MoPubNativeEventListener() {
        @Override
        public void onImpression(View view) {
           Log.d(TAG, "---onImpression--");
        }

        @Override
        public void onClick(View view) {
           Log.d(TAG, "---onClick--");
        }
    });
}

//Failure callback of native ad loading of Mopub
@Override
public void onNativeFail(NativeErrorCode errorCode) {
    Log.d(TAG, "---onNativeFail--" + errorCode.toString());
}

 

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.