admob | Android

Getting Started with Android Integration

Step 1: Creating an InMobi Account

To set up an InMobi account:

  1. Sign up as a publisher.

  2. Complete the e-mail verification for your account.

Step 2: Registering your App

  1. Click Add an App, and then click the link as shown below.
  2. Name your app, and then select your platform and proceed.
  3. Read the condition about properties directed to children below 13 years, and then select the check box if it applies to you.

    Note: For apps without a URL, the test mode is enabled by default. Once live, you can click the link to enter the URL on the dashboard as shown below.
    Your app is ready to monetize.

Step 3: Creating Placement Ids

Placement Ids are InMobi’s terminology for AdMob’s ad-unit ids. For example, if you are trying to monetize a banner ad unit via InMobi network, you need to create a placement id of type “Banner”.

Refer the following table for successful monetization.

AdMob Ad Unit Type InMobi Placement Type
Banner Banner
Interstitial Interstitial
Rewarded Interstitial Rewarded Video
Native Native Content
  1. Select the relevant ad format to define the placement of your ad.

  2. Tag the placement for superior monetization, based on the ad unit’s location and context in the app.

Step 4: Filling out the Payout Information

Create, verify and activate your payment profile to make your earning tangible. InMobi follows a payout cycle of 60 days. This means that your earnings for a given month will be credited to you at the end of the 60-day payout cycle. You have the option of receiving your payouts via PayPal or wire transfer/RTGS.

For more information about payment terms, see here.

Step 5: Configuring InMobi as an Ad Source on AdMob’s Dashboard

  1. Log on to your AdMob account.
  2. Navigate to the specific ad-unit that you want to monetize via the InMobi SDK.
  3. Under mediation navigate to ad-sources (if you have integrated solely with AdMob, number of ad sources will be one). Select new ad network, and then add InMobi as ad source.

  4. In the Network Settings page for InMobi, insert your InMobi account ID and placement ID.

    Your account ID is available in your InMobi account as illustrated in the screenshot below.

    Placement ID is under the placements section as illustrated in the screenshot below.

  5. Setting up Ad network optimization: For automatic eCPM optimization, the publisher must provide his/her InMobi reporting API credentials in the AdMob UI.
    Reach out to InMobi support to generate the secret key required for this feature.

Setting up Rewarded Interstitials

You can configure the reward either on AdMob’s dashboard or on InMobi’s dashboard.

To configure the same on InMobi’s dashboard, choose Use third-party ad network settings.

Fill in the key-value pair for the reward details, which the InMobi SDK will honour once the user completes watching the video. AdMob will in turn pass this back in the reward callback. For example, you could fill in the following reward details:

Key = Coins, Value = 1000

While setting up the rewards on InMobi dashboard, make sure the reward value is in the form of Integer.

Setting up Native Ads

Ensure not to change key names on InMobi dashboard when creating a native content placement type on the InMobi dashboard to support a native ad unit on AdMob’s dashboard. This is to ensure that the InMobi integration works seamlessly on native ad formats.

Notes:

  • InMobi Adapter doesn’t honor shouldRequestMultipleImages flag for Native Ads in AdMob SDK.
  • InMobi Adapter also doesn’t honor getImageOrientation/preferredImageOrientation flag in AdMob SDK.

Step 6: Integrating InMobi SDK via AdMob Adapter

Integrating the InMobi SDK and the AdMob Adapter is fairly seamless. To get an ad from InMobi, you need to incorporate both InMobi SDK and the Adapter.

Adding the InMobi SDK to your Project

Method 1: Pulling the latest SDK via jCenter

If you are using Gradle to build your Android applications, you can pull the latest version of the SDK from jCenter.

To do so:

  1. Include this 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.
    compile 'com.inmobi.monetization:inmobi-ads:6.0.0'
    			
  3. Sync your Gradle project to ensure that the dependency is downloaded by the build system.

Method 2: Adding the SDK library to your application project

Alternately, 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.

compile fileTree(dir: 'libs', include: ['*.jar'])
		

Adding and Verifying the Dependencies

To monetize with the InMobi ad SDK, you must add the following dependencies:

  • Google Play Services

    The InMobi SDK for Android needs the Google Play Services library to enable better ad targeting via the Google Play Advertising ID. Additionally, the SDK also uses the Google Play Services for getting a location fix, should the User consent to collecting location.

    To add the Google Play Services client library to your application:

    1. Add the following line to the application module’s dependency element.
      compile 'com.google.android.gms:play-services:8.4.0'
      				
    2. Sync your Gradle project to ensure that the dependencies are included.
    3. Add the following element to your application manifest.
      <meta-data android:name="com.google.android.gms.version"
      android:value="@integer/google_play_services_version" />
      				
  • Picasso

    The InMobi SDK for Android uses the popular Picasso library for loading the ad assets.

    To add the Picasso library to your application:

    1. Add the following line to the application module’s dependency element in the Gradle build script.
      compile 'com.squareup.picasso:picasso:2.5.2'
      				
    2. Sync your Gradle project to ensure that the dependencies are included.
  • Support Library

    For the Native Strands ad format, you must add the support-v4 library.

    To do so, add the following line to the application module’s dependency element in the Gradle build script.

    compile 'com.android.support:appcompat-v7:24.0.0'
    			

Changing the Manifest File

Granting Permissions

You must include the following mandatory permissions in your application manifest. Failure to include these permissions will affect your ability to monetize your application on the InMobi network.

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
		

In addition to the mandatory permissions above, it is highly recommended that you include either the ACCESS_COARSE_LOCATION or the ACCESS_FINE_LOCATION to enable better ad targeting. This is not a mandatory permission; however, including it will enable accurate ad targeting.

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
		

For further improved targeting, you can add the ACCESS_WIFI_STATE and the CHANGE_WIFI_STATE permissions to the manifest.

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
		

If you are requesting for rich-media ads, you can add the following permissions.

<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
		

Showing Full-screen Ad Overlays

If you are integrating interstitial ads, you must include the following activity element in your application manifest.

<activity
        android:name="com.inmobi.rendering.InMobiAdActivity"
        android:configChanges="keyboardHidden|orientation|keyboard|smallestScreenSize|screenSize|screenLayout"
        android:hardwareAccelerated="true"
        android:resizeableActivity="false"
        android:theme="@android:style/Theme.NoTitleBar"
        tools:ignore="UnusedAttribute" />
		

Attribution of App Installs

For attribution of app installs, add the following in the manifest file:

<receiver
     android:name="com.inmobi.commons.core.utilities.uid.ImIdShareBroadCastReceiver"
     android:enabled="true"
     android:exported="true"
     tools:ignore="ExportedReceiver">
          <intent-filter>
              <action android:name="com.inmobi.share.id"/>
          </intent-filter>
 </receiver>
		

Hardware Acceleration

Hardware acceleration allows you to display HTML5 video ads. To do this, add hardwareAccelerated:true element to the application tag.

Proguard Configuration

Proguarding helps to remove unused symbols and reduce the final application footprint. The following proguard directives should be added to your application’s proguard configuration file.

-keepattributes SourceFile,LineNumberTable
-keep class com.inmobi.** { *; }
-keep public class com.google.android.gms.**
-dontwarn com.google.android.gms.**
-dontwarn com.squareup.picasso.**
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient{
     public *;
}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient$Info{
     public *;
}
# skip the Picasso library classes
-keep class com.squareup.picasso.** {*;}
-dontwarn com.squareup.picasso.**
-dontwarn com.squareup.okhttp.**
# skip Moat classes
-keep class com.moat.** {*;}
-dontwarn com.moat.**
# skip AVID classes
-keep class com.integralads.avid.library.* {*;}
		

Preparing your App for Android N

SDK 6.0.0 for Android is compatible with Android N (API level 24), the latest version of the Android platform. You can start monetizing on Android N with minimal changes to your application manifest.

Declare the InMobiAdActivity element in your application like so if your app is targeting API level 24 or higher.

<activity
    android:name="com.inmobi.rendering.InMobiAdActivity"
    android:configChanges="keyboardHidden|orientation|keyboard|smallestScreenSize|screenSize|screenLayout"
    android:hardwareAccelerated="true"
    android:resizeableActivity="false"
    android:theme="@android:style/Theme.NoTitleBar"
    tools:ignore="UnusedAttribute" />
		

In particular, note the android:resizeableActivity=”false” attribute and configuring this activity for screenLayout changes.

Adding the InMobi Adapter to your Project

Download the adapter from here. Add the InMobi adapter to your Android Studio project.

Code Steps

The code steps remain the same as they are for regular AdMob integration for fetching and loading an ad. Use the AdMob account ID to initialize the AdMob SDK and AdMob “ad unit id” to request and fetch an ad.

More Information

Download the sample code from here.

The latest documentation and code samples for the AdMob SDK are available here.

Step 7: Testing the Integration

To ensure AdMob SDK relays the ad request to InMobi for testing:

  • Set manual Ad network optimization for every network including AdMob. Uncheck the Ad network optimization check box.
  • Set manual eCPM floors for all networks keeping the eCPM floor for InMobi higher than other networks, this will ensure that the ad request gets relayed to InMobi for testing. In the example below, InMobi floor is set to $5 and AdMob is set to $0.01.

After performing the steps above, you can test and relay the requests to InMobi SDK for ad loads.

Enabling Key SDK Logs

You can add the following line to your Activity where you are integrating the ad-units to enable key SDK logs.

InMobiSdk.setLogLevel(LogLevel.DEBUG);
		

You can also leverage feedback available on the diagnostics tab on the ad unit and ad request if you have enabled “Test Mode” on InMobi portal.


Step 8: Advanced

Passing User Location

You can call the setLocation() API of MediationAdRequest class of the Admob SDK to pass on the location information in the mediation ad request object.

InMobi highly recommends passing location data to enable richer targeting ads for monetization.

Passing User Demographic

InMobi supports the following parameters:

Key Name Value Description
InMobiNetworkKeys.AGE_GROUP InMobiNetworkValues.ABOVE_55,
InMobiNetworkValues.BELOW_18,
InMobiNetworkValues.BETWEEN_18_AND_20,
InMobiNetworkValues.BETWEEN_25_AND_34,
InMobiNetworkValues.BETWEEN_35_AND_54,
InMobiNetworkValues.BETWEEN_21_AND_24
The age group of the user
InMobiNetworkKeys.HOUSEHOLD_INCOME InMobiNetworkValues.ABOVE_USD_150K,
InMobiNetworkValues.BELOW_USD_5K,
InMobiNetworkValues.BETWEEN_USD_100K_AND_150K,
InMobiNetworkValues.BETWEEN_USD_10K_AND_15K,
InMobiNetworkValues.BETWEEN_USD_15K_AND_20K,
InMobiNetworkValues.BETWEEN_USD_20K_AND_25K,
InMobiNetworkValues.BETWEEN_USD_25K_AND_50K,
InMobiNetworkValues.BETWEEN_USD_50K_AND_75K,
InMobiNetworkValues.BETWEEN_USD_5K_AND_10K,
InMobiNetworkValues.BETWEEN_USD_75K_AND_100K
The house hold income of user in US Dollars
InMobiNetworkKeys.EDUCATION InMobiNetworkValues.EDUCATION_HIGHSCHOOLORLESS,
InMobiNetworkValues.EDUCATION_COLLEGEORGRADUATE,
InMobiNetworkValues.EDUCATION_POSTGRADUATEORABOVE

The education level:

  • High school, or less
  • College, or graduate
  • Postgraduate or above
InMobiNetworkKeys.ETHNICITY InMobiNetworkValues.ETHNICITY_ASIAN,
InMobiNetworkValues.ETHNICITY_HISPANIC,
InMobiNetworkValues.ETHNICITY_AFRICAN_AMERICAN,
InMobiNetworkValues.ETHNICITY_CAUCASIAN,
InMobiNetworkValues.ETHNICITY_OTHER

Ethnic group of the user:

  • Asian
  • Hispanic
  • Africanamerican
  • Caucasian
  • Other
InMobiNetworkKeys.INCOME Any String Approximate annual household income (in US Dollars)
InMobiNetworkKeys.AGE Any String The age of the user
InMobiNetworkKeys.INTERESTS Any String Any additional relevant description of the user, or their preferences, separated by commas. Valid acceptable values are mentioned below
InMobiNetworkKeys.POSTAL_CODE Any String The postal code (usually a five-digit number)
InMobiNetworkKeys.AREA_CODE Any String The area code (part of the telephone number)
InMobiNetworkKeys.LANGUAGE Any String The native language of the user (if known)
InMobiNetworkKeys.NATIONALITY Any String Nationality of the user
InMobiNetworkKeys.ImIdType_LOGIN InMobiNetworkValues.ImIdType_LOGIN Indicates a login ID in the publisher’s domain
InMobiNetworkKeys.ImIdType_SESSION InMobiNetworkValues.ImIdType_SESSION Indicates a session ID in the publisher’s domain
InMobiNetworkKeys.CITY Any String City
InMobiNetworkKeys.STATE Any String State
InMobiNetworkKeys.COUNTRY Any String Country
InMobiNetworkKeys.LOGLEVEL InMobiNetworkValues.LOGLEVEL_NONE,
InMobiNetworkValues.LOGLEVEL_DEBUG,
InMobiNetworkValues.LOGLEVEL_ERROR
Log level for InMobi SDK