inmobi-ad-tracker-iat | Audience Bidding for MoPub (Android)

Setup

In order to start setting up, you’ve to ensure that the steps mentioned here have already been incorporated. In addition to these steps, you’ve to add one more library to your project.

Step 1: Adding the SDK to your Project

Option 1: Pulling the Latest SDK via JCenter (Recommended)

If you are using Gradle to build your Android applications, you can pull the latest version of the SDK from JCenter as described below:

  1. Include JCenter in your top-level build.gradle file
        allprojects {
            repositories {
                jcenter()
            }
        }
    		
  2. Add the following line to the dependencies element in your application module’s build.gradle.
        implementation 'com.inmobi.monetization:inmobi-mopub-plugin:9.0.7.0'
    		

    Note : If the version is X.Y.Z.A , X.Y.Z denotes the compatible media SDK version whereas A denotes the patch number.

  3. Sync your Gradle project to ensure that the dependency is downloaded by the build system.

Option 2: Adding the SDK Library to your Application Project

Alternatively, you can download the latest version of InMobi’s SDK here and copy the library to your application module’s libs/ directory.

To add the library to your project’s dependencies, add this line to the dependencies element in your module’s build.gradle:

    implementation fileTree(dir: 'libs', include: ['*.aar])
	

Step 2: Integrating MoPub Plugin

Step 2.1: Audience Bidding

Note: Contact your account manager for Audience Bidding placement setup.

To use the InMobi Audience Bidding SDK, here is how you can expect the flow to go:

  • The InMobi Audience Bidder SDK will make an ad request and return a bid token
  • The bid token from the ad network will have an updated MoPub Ad Object and have pricing keywords attached
  • You then call loadAd() on the MoPub ad object as before
  • If InMobi is selected to fill, The InMobi Audience Bidder SDK will handle the rendering
Step 2.1.1: Enabling Audience Bidding Setup on MoPub

To enable Audience Bidding, you will need to do 2 things:

  1. Set up the line item to use the specific keywords with pricing used by the IMAudienceBidder class.
  2. Update your existing MoPub implementation.
Step 2.1.1.1: Setting Up the MoPub Line Items

Option 1 (Setting up Line Items Manually)

  1. Click on Orders -> Create Order
  2. Create a new order
    • Give your order a name (ex. Audience_Bidding_Test)
    • Enter in an advertiser name (ex. InMobi)
  3. Line item type
    • Give your line item a name (ex.IMAB_Banner_0.50)
    • Select type: Network Line Item
    • Select Network: Custom SDK network
    • Custom event class:
      • Banner: com.inmobi.plugin.mopub.IMABCustomEventBanner
      • Interstitial: com.inmobi.plugin.mopub.IMABCustomEventInterstitial
    • Custom event data: {}
    • Under "Budget & schedule", please enter the rate that matches what you have set up on your InMobi + AerServ dashboard for your eCPM (ex. 0.50)
  4. Ad unit targeting
    • Select the app and ad unit for your line item
  5. Audience Targeting
Enter the keyword in the "Keyword targeting" in this format IMAB:0.00 (ex. IMAB:0.50)

eCPM

Keyword

eCPM

Keyword

0.01 IMAB:0.01 5.00 IMAB:5.00
0.05 IMAB:0.05 6.00 IMAB:6.00
0.10 IMAB:0.10 7.00 IMAB:7.00
0.20 IMAB:0.20 8.00 IMAB:8.00
0.30 IMAB:0.30 9.00 IMAB:9.00
0.40 IMAB:0.40 10.00 IMAB:10.00
0.50 IMAB:0.50 11.00 IMAB:11.00
0.60 IMAB:0.60 12.00 IMAB:12.00
0.70 IMAB:0.70 13.00 IMAB:13.00
0.80 IMAB:0.80 14.00 IMAB:14.00
0.90 IMAB:0.90 15.00 IMAB:15.00
1.00 IMAB:1.00 16.00 IMAB:16.00
1.10 IMAB:1.10 17.00 IMAB:17.00
1.20 IMAB:1.20 18.00 IMAB:18.00
1.30 IMAB:1.30 19.00 IMAB:19.00
1.40 IMAB:1.40 20.00 IMAB:20.00
1.50 IMAB:1.50 21.00 IMAB:21.00
1.60 IMAB:1.60 22.00 IMAB:22.00
1.70 IMAB:1.70 23.00 IMAB:23.00
1.80 IMAB:1.80 24.00 IMAB:24.00
1.90 IMAB:1.90 25.00 IMAB:25.00
2.00 IMAB:2.00 26.00 IMAB:26.00
2.50 IMAB:2.50 27.00 IMAB:27.00
3.00 IMAB:3.00 28.00 IMAB:28.00
3.50 IMAB:3.50 29.00 IMAB:29.00
4.00 IMAB:4.00 30.00 IMAB:30.00

Option 2 (Setting up Line Items with an Automated Script)

Add a Chrome extension to your browser. Download extension here.

  1. Login to the MoPub Dashboard
  2. Create your order
  3. Create the first line item under the order
    • Line Item Setup:
      • Type & Priority: Network Line Item
      • Network: Custom SDK Network
      • Custom Event Class:
        • Banner: com.inmobi.plugin.mopub.IMABCustomEventBanner
        • Interstitial: com.inmobi.plugin.mopub.IMABCustomEventInterstitial
      • Example:

      • Under the "Audience Targeting" section:
        • Please enter a keyword in this format: IMAB:0.01
        • Example:

  4. Staying on the current tab, open the extension.
  5. Input the order name and the first line item name
  6. Click 'Run' to execute
  7. Wait for all the line items to be created

Banner Ads

Step 1: Setting up a Banner Ad

To display a banner ad on your app, you would first need to create a banner placement ID. After adding your app, select BANNER AD to create a placement for the ad type - Banner. Once you create the banner placement, the placement ID is available.

Step 2: Adding a Banner Ad to your App

Creating a Banner Ad

To add a banner ad in Android code, create an instance of IMABMoPubBanner:

IMABMoPubBanner bannerAd = new IMABMoPubBanner(context, <placementID>, <widthInDp>, <heightInDp>, listener);
	

Notes:

  • The IMABMoPubBanner class is not thread-safe. A banner instance must be created on the UI thread.
  • Similarly, all methods on this instance must be called on the UI thread. Not doing so will lead to unpredictable behavior and may affect your ability to monetize with InMobi.

Step 3: Requesting for Bid

Requesting for a bid requires you to call the IMABMoPubBanner#requestBid(...) method on the instance you just created to request for a bid. Note that there are two API(s) available to request for a bid -

  • IMABMoPubBanner#requestBid(moPubView, timeoutInMillis) : When you pass a MoPubView instance, the InMobi SDK automatically takes care of setting the keyword to this instance and saving the InMobiBanner instance for future usage in CustomEvent class.
    /**
    * A sample code to request bid with MoPubView
    */
    public class YourActivity {
        private IMABMoPubBanner banner;
        private MoPubView moPubView;
       public void requestBid() {
           // Write code to initialise your MoPub ad object and then do the following
           banner = new IMABMoPubBanner(context, <placementId>, 320, 50, new IMABMoPubListener<MoPubView, InMobiBanner>() {
               /**
                * The callback to notify that bid fetch was successful
                * @param moPubAdObject a MoPub ad object passed in requestBid. It will be null if the MoPub ad object was not passed while calling the requestBid API
                * @param imAdObject a InMobi ad object.
                * @param keyword a keyword derived from the bid received.
               */
                @Override
                public void onBidReceived(@Nullable MoPubView moPubAdObject,
                                          @NonNull InMobiBanner inMobiBanner, @NonNull String keyword) {
                    Log.d(TAG, "Keywords received:" + keyword);
                    // Load your MoPub ad here
                }
               /**
                * The callback to notify that bid fetch resulted into failure
                * @param moPubAdObject a MoPub ad object passed in requestBid.
                *                      It will be null if the MoPub ad object was not passed while calling the requestBid API
                * @param error a {@link Error} to inform what went wrong while fetching the bid
               */
                @Override
                public void onBidFailed(@Nullable MoPubView moPubAdObject, @NonNull Error error) {
                    Log.d(TAG, "Bid failure :" + error.getMessage());
                    // Load your MoPub ad here
                }
           // Requesting for bid, where timeout is 5seconds
           banner.requestBid(moPubView, 5000);
       }
    }
    		
  • IMABMoPubBanner#requestBid(timeoutInMillis) : In case you don’t wish to pass the MoPubView instance, then you need to take care of not only setting the keyword to the MoPubView instance (for which bid was requested) but also you’ve to save the InMobiBanner instance so that you can use it in the CustomEvent for rendering the ad in case InMobi wins the auction. Also, note that the IMAB keyword set to the MoPubView must be cleared off post each ad opportunity and before loading the banner ad again.
    /**
    * A sample code to request bid without MoPubView
    */
    public class YourActivity {
        private IMABMoPubBanner banner;
        private MoPubView moPubView;
       public void requestBid() {
           // Write code to initialise your MoPub ad object and then do the following
           banner = new IMABMoPubBanner(context, <placementId>, 320, 50, new IMABMoPubListener<MoPubView, InMobiBanner>() {
               /**
                * The callback to notify that bid fetch was successful
                * @param moPubAdObject a MoPub ad object passed in requestBid. It will be null if the MoPub ad object was not passed while calling the requestBid API
                * @param imAdObject a InMobi ad object.
                * @param keyword a keyword derived from the bid received.
               */
                @Override
                public void onBidReceived(@Nullable MoPubView moPubAdObject,
                                          @NonNull InMobiBanner inMobiBanner, @NonNull String keyword) {
                    Log.d(TAG, "Keywords received:" + keyword);
                    // Since MoPubView has not been passed in the request, you need to do the following
                    String oldKeyword = mopubView.getKeywords();
                    moPubView.setKeywords(TextUtils.isEmpty(oldKeyword) ? keyword :
                        String.format("%s,%s", oldKeyword, keyword));
                    Map<String, Object> localExtras = moPubView.getLocalExtras();
                    localExtras.put(IMABCustomEventBanner.AD_OBJECT_KEY, inMobiBanner);
                    moPubView.setLocalExtras(localExtras);
                    // Load your MoPub ad here
                }
               /**
                * The callback to notify that bid fetch resulted into failure
                * @param moPubAdObject a MoPub ad object passed in requestBid.
                *                      It will be null if the MoPub ad object was not passed while calling the requestBid API
                * @param error a {@link Error} to inform what went wrong while fetching the bid
               */
                @Override
                public void onBidFailed(@Nullable MoPubView moPubAdObject, @NonNull Error error) {
                    Log.d(TAG, "Bid failure :" + error.getMessage());
                    // Load your MoPub ad here
                }
           // Requesting for bid, where timeout is 5seconds
           banner.requestBid(5000);
       }
    }
    		

Step 4: Setting up for MoPubView refresh

In case your MoPubView has auto refresh feature enabled, then simply you need to request a bid for every success/failure for callback, as mentioned below.

/**
* A sample code to request bid without MoPubView
*/
public class YourActivity {
    private IMABMoPubBanner banner;
    private MoPubView moPubView;
    private MoPubView.BannerAdListener bannerAdListener = new MoPubView.BannerAdListener() {
        @Override
        public void onBannerLoaded(MoPubView banner) {
            Log.d(TAG, "Banner loaded");
            // Requesting for bid, where timeout is 5seconds
            banner.requestBid(moPubView, 5000);
        }
        @Override
        public void onBannerFailed(MoPubView banner, MoPubErrorCode errorCode) {
            Log.d(KLOG_TAG, "Banner load failed : " + errorCode.toString());
            // Requesting for bid, where timeout is 5seconds
            banner.requestBid(moPubView, 5000);
        }
    };
    // Other code
}
	

Interstitial Ads

Step 1: Setting up an Interstitial Ad

  1. To display an Interstitial ad, you need an interstitial placement ID.
  2. After adding your app, select INTERSTITIAL AD to create a placement for ad type Interstitial.
  3. Once you successfully create the placement, the placement ID is available.

Step 2: Adding an Interstitial Ad to your App

Creating an Interstitial Ad

To create an interstitial ad, create an instance of an IMABMoPubInterstitial like so:

IMABMoPubInterstitial interstitialAd = new IMABMoPubInterstitial(context, <placementID>, listener);
	

Notes:

  • The IMABMoPubInterstitial class is not thread-safe. An interstitial instance must be created on the UI thread.
  • Similarly, all methods on this instance must be called on the UI thread. Not doing so will lead to unpredictable behavior and may affect your ability to monetize with InMobi.

Step 3: Requesting for Bid

Requesting for a bid requires you to call the IMABMoPubInterstitial#requestBid(...) method on the instance you just created to request for a bid. Note that there are two API(s) available to request for a bid -

  • IMABMoPubInterstitial#requestBid(moPubInterstitial, timeoutInMillis) : When you pass a MoPubInterstitial instance, the InMobi SDK automatically takes care of setting the keyword to this instance and saving the InMobiInterstitial instance for future usage in CustomEvent class.
    /**
    * A sample code to request bid with MoPubView
    */
    public class YourActivity {
        private IMABMoPubInterstitial interstitial;
        private MoPubInterstitial moPubInterstitial;
       public void requestBid() {
           // Write code to initialise your MoPub ad object and then do the following
           interstitial = new IMABMoPubInterstitial(context, <placementId>, new IMABMoPubListener<MoPubInterstitial, InMobiInterstitial>() {
               /**
                * The callback to notify that bid fetch was successful
                * @param moPubAdObject a MoPub ad object passed in requestBid. It will be null if the MoPub ad object was not passed while calling the requestBid API
                * @param imAdObject a InMobi ad object.
                * @param keyword a keyword derived from the bid received.
               */
                @Override
                public void onBidReceived(@Nullable MoPubInterstitial moPubAdObject,
                                          @NonNull InMobiInterstitial inMobiInterstitial, @NonNull String keyword) {
                    Log.d(TAG, "Keywords received:" + keyword);
                    // Load your MoPub ad here
                }
               /**
                * The callback to notify that bid fetch resulted into failure
                * @param moPubAdObject a MoPub ad object passed in requestBid.
                *                      It will be null if the MoPub ad object was not passed while calling the requestBid API
                * @param error a {@link Error} to inform what went wrong while fetching the bid
               */
                @Override
                public void onBidFailed(@Nullable MoPubInterstitial moPubAdObject, @NonNull Error error) {
                    Log.d(TAG, "Bid failure :" + error.getMessage());
                    // Load your MoPub ad here
                }
           // Requesting for bid, where timeout is 5seconds
           interstitial.requestBid(moPubInterstitial, 5000);
       }
    }
    		
  • IMABMoPubInterstitial#requestBid(timeoutInMillis) : In case you don’t wish to pass the MoPubView instance, then you need to take care of not only setting the keyword to the MoPubView instance (for which bid was requested) but also you’ve to save the InMobiInterstitial instance so that you can use it in the CustomEvent for rendering the ad in case InMobi wins the auction. Also, note that the IMAB keyword set to the MoPubInterstitial must be cleared off post each ad opportunity and before loading the interstitial ad again.
    /**
    * A sample code to request bid without MoPubView
    */
    public class YourActivity {
        private IMABMoPubInterstitial interstitial;
        private MoPubInterstitial moPubInterstitial;
       public void requestBid() {
           // Write code to initialise your MoPub ad object and then do the following
           interstitial = new IMABMoPubInterstitial(context, <placementId>, new IMABMoPubListener<MoPubInterstitial, InMobiInterstitial>() {
               /**
                * The callback to notify that bid fetch was successful
                * @param moPubAdObject a MoPub ad object passed in requestBid. It will be null if the MoPub ad object was not passed while calling the requestBid API
                * @param imAdObject a InMobi ad object.
                * @param keyword a keyword derived from the bid received.
               */
                @Override
                public void onBidReceived(@Nullable MoPubInterstitial moPubAdObject,
                                          @NonNull InMobiInterstitial inMobiInterstitial, @NonNull String keyword) {
                    Log.d(TAG, "Keywords received:" + keyword);
                    // Since MoPubInterstitial has not been passed in the request, you need to do the following
                    String oldKeyword = moPubInterstitial.getKeywords();
                    moPubInterstitial.setKeywords(TextUtils.isEmpty(oldKeyword) ? keyword :
                        String.format("%s,%s", oldKeyword, keyword));
                    Map<String, Object> localExtras = moPubInterstitial.getLocalExtras();
                    localExtras.put(IMABCustomEventInterstitial.AD_OBJECT_KEY, inMobiInterstitial);
                    moPubInterstitial.setLocalExtras(localExtras);
                    // Load your MoPub ad here
                }
               /**
                * The callback to notify that bid fetch resulted into failure
                * @param moPubAdObject a MoPub ad object passed in requestBid.
                *                      It will be null if the MoPub ad object was not passed while calling the requestBid API
                * @param error a {@link Error} to inform what went wrong while fetching the bid
               */
                @Override
                public void onBidFailed(@Nullable MoPubInterstitial moPubAdObject, @NonNull Error error) {
                    Log.d(TAG, "Bid failure :" + error.getMessage());
                    // Load your MoPub ad here
                }
           // Requesting for bid, where timeout is 5seconds
           interstitial.requestBid(5000);
       }
    }