Integration of Media.Net Header Bidder for DFP

This page will help you integrate Media.net Header Bidder to your project. Header bidder integration is available for Banner and Interstitial ads.

You can reach us at mobileapps@media.net if you have any queries during integration.

Following are the 4 steps to integrate header bidder:

  • Adding Repository
  • Adding Dependencies
  • Initialising MNet sdk
  • Integration of Header Bidding for Banner and/or Interstitial ads

Requirements

Media.Net Ad SDK requires the app to have the following:

  • Android 4.0.3 (API Version 15) and above.

Note: Android Studio and Gradle These instructions assume you are using Android Studio and Gradle. Most of the required AndroidManifest.XML entries (Except the Location permissions) and ProGuard changes are automatically added to your app. If you are using other build systems, the steps may vary.

Integration Steps

1. Adding Repository

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

   maven { url "http://medianet.bintray.com/media-net-android" }

2. Adding Dependencies

Add the below dependencies to your build.gradle file.

   dependencies  {
     compile "net.media.android:bidder-base:1.0.2"
     compile "net.media.android:dfp-bidder:1.0.2"
   }

3. Initialising the SDK

Initialize the Media.net SDK with the following code and customer ID in your app’s application class. Your 9-digit numeric customer ID could be obtained by contacting your Media.Net account manager.

   MNet.init(this, "XXXXXXXXX");

For Child-Directed content,

   MNet.init(this, "XXXXXXXXX", childDirectedContent);

4. Integration of Header Bidding for Banner and/or Interstitial ads

Integration for Banner Ads

The example below shows a way of integrating manual header bidding for banner ads.

  final PublisherAdRequest publisherAdRequest = new PublisherAdRequest.Builder()
        .setLocation(location)
        .setGender(PublisherAdRequest.GENDER_FEMALE)
        .setBirthday(date)
        .setContentUrl(contentUrl)
        .addCustomTargeting("pos", "bottom") // Set targeting values which would be used to identify and map ad-slots.
        .setContentUrl("http://www.example.com") //It's highly recommended to pass a content url if you have one.
        .build();

  DfpBidder.addBids(mPublisherAdView, publisherAdRequest, new DfpBidderCallback() {
      @Override public void onCompleted() {
             mPublisherAdView.loadAd(publisherAdRequest);
         }
     });

Integration for Interstitial Ads

The example below shows a way of integrating manual header bidding for interstitial ads.

  final PublisherAdRequest publisherAdRequest = new PublisherAdRequest.Builder()
        .setLocation(location)
        .setGender(PublisherAdRequest.GENDER_FEMALE)
        .setBirthday(date)
        .setContentUrl(contentUrl)
        .addCustomTargeting("pos", "bottom") // Set targeting values which would be used to identify and map ad-slots.
        .setContentUrl("http://www.example.com") //It's highly recommended to pass a content url if you have one.
        .build();

  DfpBidder.addBids(mPublisherInterstitialAd, publisherAdRequest, new DfpBidderCallback() {
         @Override public void onCompleted() {
             mPublisherInterstitialAd.loadAd(publisherAdRequest);
         }
     });

You can use the following function to pass the GDPR consent details to the SDK.

/**
 * Function to be used to update GDPR concent with Media.Net SDK
 *
 * @param   subjectToGdpr                 Possible values:  SubjectToGDPR.DISABLED
 *                                                          SubjectToGDPR.ENABLED
 *                                                          SubjectToGDPR.UNKNOWN
 *                                              
 * @param consentStatus                   Possible values:  ConsentStatus.UNKNOWN
 *                                                          ConsentStatus.GIVEN
 *                                                          ConsentStatus.REVOKED
 * @param consentString                   String representing consent string
 */
public static void updateGdprConsent(subjectToGdpr, consentStatus, String consentString)

The example below illustrates the usage -

MNet.updateGdprConsent(SubjectToGDPR.ENABLED, ConsentStatus.GIVEN, "consent_string");