Integration of Media.Net Header Bidder for MoPub

This document helps in integration of Media.Net header bidder for MoPub in your project. Do go through the steps in our Getting Started Guide to add Media.Net SDK into your project before starting the integration.

Follow these simple steps for the integration:

There are 3 steps for the integration:

  1. Add Media.Net repository to your main Gradle file.
  2. Add Gradle Plugin dependencies to your main Gradle file.
  3. Apply the Media.Net Gradle Plugin and add dependency to your application Gradle file.

NOTE: Depending on the version of the Gradle plugin you have for your project the second and third steps are different. For Gradle plugin version 3.x.x and above the steps are discussed first. The steps for versions 2.x.x and below are discussed later.

1. Add Media.Net repository to your main Gradle file.

Add the maven repo into your repositories block of main Gradle file:

   maven { url "http://medianet.bintray.com/maven" }

Gradle Plugin Version 3.x.x and Above

2. Add the following dependency to your main Gradle file Gradle Plugin version 3.x.x and above.

Add the below dependency to your main Gradle file. See the image below for reference.

   dependencies {
    classpath "net.media.android:plugin2:1.0.0"
   }

3. Apply the plugin and the dependency to all your module Gradle files for Gradle Plugin version 3.x.x and above.

Add the below plugin and dependency to your module Gradle files. See the images below for reference.

  • It is necessary to add both the plugin and dependency together in a gradle file.
  • It is necessary to add these to all the submodules, which may contain dfp related code. For e.g. if you have a submodule called ‘mylocalmodule’, you need to apply the plugin and add the ‘mopub’ dependency to its gradle file.

Plugin to be applied

   apply plugin: "net.media.android.plugin2"

Dependency to be added

   implementation "net.media.android:mopub:1.2.5"

Gradle Plugin Version 2.x.x and below

2. Add the following dependency to your main Gradle file for Gradle Plugin version 2.x.x and below.

Add the below mentioned dependency to your main Gradle file as shown in the image.

   dependencies {
    classpath "net.media.android:plugin:0.0.3"
   }

3. Apply the plugin and the dependency to all your module Gradle files for Gradle Plugin version 2.x.x and below.

Add the below plugin and dependency to your module Gradle files. See the images below for reference.

  • It is necessary to add both the plugin and dependency together in a gradle file.
  • It is necessary to add these to all the submodules, which may contain dfp related code. For e.g. if you have a submodule called ‘mylocalmodule’, you need to apply the plugin and add the ‘mopub’ dependency to its gradle file.

Plugin to be applied

   apply plugin: "net.media.android.plugin"

Dependency to be added

   compile "net.media.android:mopub:1.2.5"

Passing custom data through MoPub Header Bidder [Optional]

Custom data like location-details and context can be set on the MoPubView object, which will be used by the MNet ad-views to contextualize the ads.

This step is optional yet highly recommended as it improves ad targeting and monetisation.

Here is an example for setting the keywords and location details on the MoPubView object

    MoPubView moPubView = (MoPubView) findViewById(R.id.mobpub_adview);
    moPubView.setKeywords(keywords);
    moPubView.setLocation(location);