Install MoPub SDK

Detailed instructions on how to install the MoPub Android SDK can be found in the original repo. However for the sake of simplicity you can import MoPub Android SDK using the following lines in your module level build.gradle file.

compile('com.mopub:mopub-sdk:5.13.1@aar') {
    transitive = true
    exclude module: 'libAvid-mopub'
    exclude module: 'moat-mobile-app-kit'
}

To fully support all of MoPub features you must add to your app's AndroidManfiest.xml file the following activities inside the applicacion tag:

<activity
    android:name="com.mopub.mobileads.MoPubActivity"
    android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
    android:name="com.mopub.mobileads.MraidActivity"
    android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
    android:name="com.mopub.common.MoPubBrowser"
    android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
    android:name="com.mopub.mobileads.MraidVideoPlayerActivity"
    android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
    android:name="com.mopub.mobileads.RewardedMraidActivity"
    android:configChanges="keyboardHidden|orientation|screenSize" />

Create app in MoPub Dashboard

If you already have created the app you will use in the MoPub Dashboard you can skip this section.

Create a new Android app on the MoPub Dashboard.

2050

Create placements in MoPub Dashboard

Create a new Ad Unit on the MoPub Dashboard. Select the ad format you want to display. For this example we will select a 320x50 Banner but PN Lite also supports 300x250 Banners and Interstitials.

1840

Once it's created you'll get a confirmation that looks like the image below. Copy the Ad Unit ID they provide since you'll need it later to make ad requests.

1428

Create Order and Line Items in MoPub Dashboard

The next step is creating an Order to set up the Line items

Create a new Order and use the name of the app as the Order name and Advertiser as well. This is not mandatory, just a good practice to avoid confusion.

2270

After inserting the Order info, you need to create an initial Line Item. Set the type to Network and Priority to 12. This means the Line Item will compete with other ad networks and MoPub Marketplace.

Feel free to use any name for the Line Item but the recommended format is:

APP_NAME FORMAT ECPM OS

Here you can see and example:

Wrapper 320x50 0.01 Android

In the network type choose Custom Native Network

In the class field add the full name of the PN Lite Adapter class you will use. There's one for each format. In this sample we'll use the one for 320x50 Banner.

  • net.pubnative.lite.adapters.mopub.headerbidding.HyBidHeaderBiddingBannerCustomEvent (320x50 Banner)
  • net.pubnative.lite.adapters.mopub.headerbidding.HyBidHeaderBiddingMRectCustomEvent (300x250 Banner)
  • net.pubnative.lite.adapters.mopub.headerbidding.HyBidHeaderBiddingLeaderboardCustomEvent (728x90 Tablet Banner)
    • net.pubnative.lite.adapters.mopub.headerbidding.HyBidHeaderBiddingInterstitialCustomEvent (Interstitial)

Finally on the Data field you need to specify which PubNative Ad Zone ID corresponds to this Line Item. This is needed so the adapter know how to get the ad from the PN Lite SDK Ad Cache. Please add the following JSON into the field:

{"pn_zone_id": "AD_ZONE_ID"}

2280

After adding the eCPM, you need to assign the line item to an Ad unit. This will guarantee that this line item will compete in the waterfall when a request for this Ad unit is made:

2210

Finally here comes the most important part:

We will use keywords to target our line item on the waterfall when competing with other networks on the same eCPM. In order to make this work, it's very important that when you make the request to MoPub from your app, you use the keywords generated by the HeaderBiddingUtils class from PN Lite.

The keywords are generated with the following format:

pn_bid:X.XX

Basically X.XX being the eCPM received from the bid with up to 2 decimals after the comma.

Samples:

eCPM: 1 USD Keyword: pn_bid:1.00

eCPM: 0.01 USD Keyword: pn_bid:0.01

eCPM: 0.3 USD Keyword: pn_bid:0.30

In the ideal situation there should be a Line item for every posible eCPM in that range but this will end up in thousands of line items, therefore it is better recommended to group the eCPMs in ranges, usually bigger for smaller payouts and smaller for larger payouts. For example:

Line item with eCPM 0.10 can include:

pn_bid:0.11

pn_bid:0.12

pn_bid:0.13

pn_bid:0.14

pn_bid:0.15

pn_bid:0.16

pn_bid:0.17

pn_bid:0.18

pn_bid:0.19

Then the one with 0.20 can do the same up the 0.29

For bigger eCPM Line Items it is recommended to have more granularity in the keywords to improve the matching on the waterfall.

1454