Android SDK AdMob Adapter

2579 views 2019-01-29 Ofer Garnett 0

Getting Started

Latest Android version: 5.0.1
Release date: 16-Mar 2020

This document details the process of integrating YouAppi Android AdMob adapter with your Android app.

If you have any questions, please, feel free to email us: [email protected]

The basic steps of integration are:

Download YouAppi’s Android SDK AdMob Adapter

Android AdMob adapter can be found in YouAppi Android SDK package as youappi-sdk-android-admob.aar

Integration

Integrate using AAR files

  • Copy youappi-sdk-android-moat.aar and youappi-sdk-android-admob.aar files to the apps/libs folder of your project.
  • Add the following to the project build.gradle file inside the repositories section:
    repositories {
        flatDir {
            dirs 'libs'
        }
    }
  • Add to your app build.gradle file the following under dependencies section:
    dependencies {
        implementation name:'youappi-sdk-android-admob', ext:'aar'
        implementation name:'youappi-sdk-android-moat', ext:'aar'
        implementation 'com.google.code.gson:gson:2.6'
        implementation 'com.google.android.ads.consent:consent-library:1.0.4'
    }

Integrate using repository

  • Add the following to the project build.gradle file inside the repositories section:
    maven { url "http://repository.youappi.com/repository/release" }
    maven { url "https://maven.google.com" }
    
  • Add to your app build.gradle file the following under dependencies section:
    dependencies {
        implementation 'com.youappi.sdk:youappi-sdk-android-admob-moat:4.3.10'
        implementation 'com.google.android.ads.consent:consent-library:1.0.4'
    }

Proguard

If proguard is used, the following entries should be added:

-keep class com.youappi.sdk.mediation.admob.YouAppiInterstitialAd{*;}
-keep class com.youappi.sdk.mediation.admob.YouAppiInterstitialVideo{*;}
-keep class com.youappi.sdk.mediation.admob.YouAppiRewardedVideo{*;}
  • Create a new Android app

    • On ad mob platform go to apps section.
    • Press ADD APP button.

    • Follow through the steps of creating a new app.

    Add to your Android app ad units

    Add new ad units to your app by choosing your app and pressing ADD AD UNIT button

Rewarded Video

  • After pressing ADD AD UNIT button select Rewarded:

  • Fill your ad unit details and press CREATE AD UNIT button:

Interstitial Video and Interstitial Ad

  • After pressing ADD AD UNIT button select Interstitial

  • Fill your ad unit details and press CREATE AD UNIT button:

Create Mediation Group for YouAppi Rewarded Video

  • Choose Mediation tab and press CREATE MEDIATION GROUP button.
  • Fill mediation group details and press CONTINUE:

  • Fill mediation group details and press ADD AD UNITS to connect your mediation group with the rewarded video ad unit.

  • Press DONE to add the ad unit.
  • After the popup is closed and the ad unit is selected, on Ad Sources section press ADD CUSTOM EVENT button.
  • On the popup name your custom event, fill relevant eCPN and press CONTINUE:

  • On the next popup fill the class name of YouAppi rewarded video custom event: com.youappi.sdk.mediation.admob.YouAppiRewardedVideo
  • Fill the Parameter field with a JSON containing information about your access token and ad unit id. For example:
{ "accessToken": "821cfa77-3127-42b5-9e6b-0afcecf77c69", "adUnitId": "tesRewardedVideoAdUnit" }
  • Make sure to use your access token and to put ad unit id that contains only letters, numbers or underscores.

  • Press DONE to save the custom event.
  • Press SAVE to create the new mediation group.

Create Mediation Group for YouAppi Interstitial Video and Interstitial Ad

  • Choose Mediation tab and press CREATE MEDIATION GROUP button.
  • Fill mediation group details and press CONTINUE:

  • Fill mediation group details and press ADD AD UNITS to connect your mediation group with the interstitial ad and interstitial video ad units.

  • Press DONE to add the ad unit.
  • After the popup is closed and the ad unit is selected, on Ad Sources section press ADD CUSTOM EVENT button.
  • On the popup name your custom event, fill relevant eCPM and press CONTINUE:

  • On the next popup fill the class name of YouAppi rewarded video custom event:
    • com.youappi.sdk.mediation.admob.YouAppiInterstitialAd
    • com.youappi.sdk.mediation.admob.YouAppiInterstitialVideo
  • Fill the Parameter field with a JSON containing information about your access token and ad unit id. For example:

{ "accessToken": "821cfa77-3127-42b5-9e6b-0afcecf77c69", "adUnitId": "tesInterstitialAdUnit" }

  • Make sure to use your access token and to put ad unit id that contains only letters, numbers or underscores.

  • Press DONE to add the ad unit.
  • Press SAVE to create the new mediation group.

Use AdMob SDK to show YouAppi ad units

Init SDK

MobileAds.initialize(this,"<Replace with AdMob Token>");

Rewarded Video

Load

adMobRewardedVideo = MobileAds.getRewardedVideoAdInstance(this);
adMobRewardedVideo.loadAd("<Replace with AdMob Rewarded Video Ad Unit ID>", new AdRequest.Builder().build());

Show

adMobRewardedVideo.show();

Interstitial Video

Load

interstitialVideoAd = new InterstitialAd(this);
interstitialVideoAd.setAdUnitId("<Replace with AdMob Interstitial Video Ad Unit ID>");
interstitialVideoAd.loadAd(new AdRequest.Builder().build());

Show

if (interstitialVideoAd.isLoaded()) {
  interstitialVideoAd.show();
}

Interstitial Ad

Load

interstitialAd = new InterstitialAd(this);
interstitialAd.setAdUnitId("<Replace with AdMob Interstitial Ad Unit ID>");
interstitialAd.loadAd(new AdRequest.Builder().build());

Show

if (interstitialAd.isLoaded()) {
  interstitialAd.show();
}

According to General Data Protection Regulation (GDPR), you must make certain disclosures to your users in the European Economic Area (EEA) and obtain their consent to use cookies or other local storage, where legally required, and to use personal data (such as Advertising ID and IP address) to serve ads.

One option is to use the Consent SDK to present a Google-rendered consent form to your users. In this case, you must add the following dependencies

    • Add the following to the project build.gradle file inside the repositories section:
      maven { url "https://maven.google.com" }
      
    • Add to your app build.gradle file the following under dependencies section:
      dependencies {
          implementation 'com.google.android.ads.consent:consent-library:1.0.4'
      }

Also, you may forward consent to SDK manually (please, see an example below):

rewardedVideo.loadAd(UNIT_ID_REWARDED_VIDEO, new AdRequest.Builder()
                .addNetworkExtrasBundle(YouAppiRewardedVideo.class, bundleWithConsent()).build());
interstitialVideo.loadAd(new AdRequest.Builder()
                .addCustomEventExtrasBundle(YouAppiInterstitialVideo.class, bundleWithConsent()).build());
interstitialAd.loadAd(new AdRequest.Builder()
                .addCustomEventExtrasBundle(YouAppiInterstitialAd.class, bundleWithConsent()).build());
 private Bundle bundleWithConsent() {
    Bundle bundle = new Bundle();
    bundle.putBoolean("consent", true);
    return bundle;
  }

Demo App

A demo app showing a simple usage of the SDK can be found in the following Github repository:

https://github.com/YouAppi/youappi-sdk-android-demo

The demo app contains 4 modules:

      • app-demo – Shows how to use YouAppi’s SDK
      • app-demo-admob – Shows how to use YouAppi’s SDK with AdMob adapter
      • app-demo-mopub – Shows how to use YouAppi’s SDK with MoPub adapter
      • app-demo-nativeads – Shows how to use YouAppi’s SDK Native Ads

Please make sure to read the README.md file for further instructions.