NextGen SDK | Android | AdMob Integration

Integration Guide for Publishers with AdMob as a Primary Ad Server

(Android NextGen SDK version 22.6.0)

Assumptions

You have a AdMob mediation integrated into your project.If not, please see the AdMob documentation.
You have a Smaato SPX account and have created necessary ad spaces.If not please, see our SPX documentation.

Note: to avoidany unexpected behaviours in case if you create an instance of AdMob’s AdView manually, but not via xml, it is important to pass only Activity’s Context into AdView’s constructor

Important Details About GDPR

As a publisher, you should integrate a Consent Management Platform (CMP) and request for vendor and purpose consents as outlined in IAB Europe’s Mobile In-App CMP API v1.0: Transparency & Consent Framework. You can find a reference implementation of a web-based CMP and the corresponding native wrappers here in the IAB’s GDPR-Transparency-and-Consent-Framework.

If you are embedding your own custom CMP, the collected end-user consent information needs to be stored in SharedPreferences using the following keys:

KeyTypeDescription
IABConsent_CMPPresentBooleanSet to “YES” if a CMP that follows the IAB specification is present in the application.
IABConsent_SubjectToGDPRString1” = Subject to GDPR
0” = Not subject to GDPR
-1” = Undetermined (default before initialization)
IABConsent_ConsentStringStringBase64-encoded consent string as defined in Consent string and vendor list format v1.1
IABConsent_ParsedPurposeConsentsStringString of “0”s and “1”s, where the character at position N indicates the consent status to purposeID N as defined in the Global Vendor List
IABConsent_ParsedVendorConsentsStringString of “0”s and “1”s, where the character at position N indicates the consent status to vendorID N as defined in the Global Vendor List

Important Note: If the key IABConsent_SubjectToGDPR is set to “1”, then you as a publisher need to make sure the key IABConsent_ConsentString contains a valid consent string (user was asked to provide consent before serving the ad). Otherwise, such ad requests will be dropped on the server-side without a return.

Important Details About CCPA

The California Consumer Privacy Act (CCPA) was created to provide California consumers with greater transparency and control over their personal information. In many ways, the CCPA is a first of its kind regulation in the United States that seeks to create broad privacy and data protection rules that apply to all industries doing business in the jurisdiction of California, rather than focusing on a single sector or specific data collection and use practices.

For more information about the CCPA regulation, please check out the Smaato FAQ.

For Publishers with California- Based Users

As a publisher, you need to make sure to request consent from California-based users (to give or refuse consent / to opt-out or opt-in ) about private data transfer. This answer should be saved in SharedPreferences with key “IABUSPrivacy_String” in the US Privacy String format (CCPA Opt-Out Storage Format).

The Smaato NextGen SDK reads this value in the key “IABUSPrivacy_String” if it exists and uses this as an optional parameter for all ad requests. You can use SmaatoSdk#getUsPrivacyString method to get a value which is currently stored under the “IABUSPrivacy_String” key. Note that default value is an empty string.

Sample of US Privacy String Saving in SharedPreferences

SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context)
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("IABUSPrivacy_String", "iab string");
editor.commit();

Important Note About Fullscreen Adspaces

Currently, only the Interstitial Multi-Ad Format is compatible with Fullscreen Adspaces with Smaato NextGen SDK. In order to monetize your fullscreen Adspaces in SPX with Smaato NextGen SDK, you need to select the option for Interstitial (Display & Video). All other Fullscreen options will not work at this time.

Please check if the Interstitial (Display & Video) feature is enabled in your SPX account. If you do not see the option for Interstitial (Display & Video) in the Ad Format dropdown, please contact your Smaato Account Manager to enable this.

  • When creating your Fullscreen Adspaces in SPX, choose the Interstitial (Display & video) option as the Ad format. (Image 1)
  • For the Creative Type you will have three options to choose from (Image 2):
    • Display Only for Rich Media Ads.
    • Video Only for Video Ads.
    • Display and Video will support either Rich Media or Video Ads.

Image 1: Ad Format dropdown selection

Image 2: Creative Type dropdown selections

Ads for Testing Purposes

Important Note: All AdSpaces can be used on both Android and iOS platforms and do not require any SPX changes. It is mandatory to include the following Publisher ID for testing purposes. You will also need to use the Adspace IDs provided in the table below.
Please Also Note: These IDs must be replaced with your real publisher ID and Adspace ID/s before publishing the app to the stores, you will need to re-compile your app for this purpose.

Publisher ID: 1100042525  
Adspace IDTypeDescription
130626424Rich MediaBanner / Med-rect / Leaderboard / Skyscraper
130635694Static ImageBanner / Med-rect / Leaderboard / Skyscraper
130635706MRAIDBanner / Med-rect / Leaderboard / Skyscraper
130626426Rich Media / VideoInterstitial (Video with an end-card + Rich Media Interstitial for 320×480, 480×320, 1024×768 & 768×1024)
130626427VideoSkippable Video
130626428RewardedRewarded Video
130635048RewardedRewarded Video without an end-card

Demo App for Sample Integration

Download latest Demo App Apk from here.

AdMob Dashboard Setup

1. Go to the AdMob Dashboard. – https://apps.admob.com/v2/mediation/groups/list 

2. Click on Create Mediation Group.

3. Select your Ad format.

  • Your options are Banner, Interstitial, and Rewarded Video.

4. In the next tab, select your desired parameter settings.

5. For the Add Ad unit option under Ad unit, select the Ad unit that needs to be targeted with the mediation.

6. Under Ad sources, click on ADD CUSTOM EVENT. 

  • Then provide a Label and your desired eCPM.
  • Under Configure Ad units, provide the class name details:
    • For Banner: com.smaato.sdk.adapters.admob.banner.SMAAdMobSmaatoBannerAdapter
    • For Interstitial: com.smaato.sdk.adapters.admob.interstitial.SMAAdMobSmaatoInterstitialAdapter
    • Rewarded Video: com.smaato.sdk.adapters.admob.rewarded.SMAAdMobSmaatoRewardedVideoAdapter
    • Native: com.smaato.sdk.adapters.admob.nativead.SMAAdMobSmaatoNativeAdapter
  • Pass parameter for the SPX Adspace ID:
    • adSpaceId=<YOUR_SPX_ADSPACE_ID> (e.g. adSpaceId=133149964)

SDK Integration

Configure your Android project

Add the following repository setup to your project’s main build.gradle file:

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "https://s3.amazonaws.com/smaato-sdk-releases/"
        }
    }
}

Set the compile options to Java 8, (i.e. place the following line into your application module build.gradle file):

android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

Important Note: Smaato SDK minSdkVersion is Android 4.1 (API level 16).

Integration Options

This integration currently supports the Google Mobile Ads SDK version 20.3.0

Due to the modular structure of SDK, you can select different integration options. Here are some configuration examples, which should be added into your build.gradle

Banner (with Rich Media support)

build.gradle

implementation 'com.smaato.android.sdk:admob-banner-adapter:22.6.0'

For supporting AdMob/ GAM version 20.3 or above

build.gradle

implementation 'com.smaato.android.sdk:admob-banner-adapter-20-3:22.6.0'

Interstitial (with Video & Rich Media support)

build.gradle

implementation 'com.smaato.android.sdk:admob-interstitial-adapter:22.6.0'

For supporting AdMob/ GAM version 20.3 or above

build.gradle

implementation 'com.smaato.android.sdk:admob-interstitial-adapter-20-3:22.6.0'

Interstitial (with Rich Media support only)

build.gradle

implementation 'com.smaato.android.sdk:admob-interstitial-adapter:22.6.0' {
   exclude module: "module-video"
}

For supporting AdMob/ GAM version 20.3 or above

build.gradle

implementation 'com.smaato.android.sdk:admob-interstitial-adapter-20-3:22.6.0' {
   exclude module: "module-video"
}

Interstitial (with Video support only)

build.gradle

implementation 'com.smaato.android.sdk:admob-interstitial-adapter:22.6.0' {
   exclude module: "module-richmedia"
}

For supporting AdMob/ GAM version 20.3 or above

build.gradle

implementation 'com.smaato.android.sdk:admob-interstitial-adapter-20-3:22.6.0' {
   exclude module: "module-richmedia"
}

Rewarded Video

build.gradle

implementation 'com.smaato.android.sdk:admob-rewarded-video-adapter:22.6.0'

For supporting AdMob/ GAM version 20.3 or above

build.gradle

implementation 'com.smaato.android.sdk:admob-rewarded-video-adapter-20-3:22.6.0'

Native

implementation 'com.smaato.android.sdk:admob-native-adapter:22.6.0'

For supporting AdMob/ GAM version 20.3 or above

implementation 'com.smaato.android.sdk:admob-native-adapter-20-3:22.6.0'

Handling onDestroy for Ads in GAM version 20.3 onwards :

As Google Ad Manager and AdMob has removed support for destroying Ads by overriding the onDestory() callback hence we have introduced our own method
to handle that part for publishers – SMAAdMobAdapter.onDestroy()

This needs to be called in onDestroy of the activity containing the Ad.

Example given below :

public override fun onDestroy() {
    super.onDestroy()
    SMAAdMobAdapter.onDestroy()
}

Permissions

Add the following permissions to your application AndroidManifest.xml file:

Mandatory permissions:

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

Optional permissions:

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

If your application targets Android 5.0 (API level 21) or higher, then add the following line to your application AndroidManifest.xml file:

<uses-feature android:name="android.hardware.location.network" />

Optional Configuration:


i) If your application targets Android 9 Pie (API level 28) or higher, in order to send HTTP requests (using the unencrypted HTTP protocol instead of HTTPS, so that more Ads can be shown), then you need to configure the networkSecurityConfig attribute in the application tag in AndroidManifest.xml:

android:networkSecurityConfig="@xml/network_security_config"

ii) Now create the network_security_config.xml in the XML resource directory with:

android:networkSecurityConfig="@xml/network_security_config"
<code><?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true" />
</network-security-config>

For more details regarding the Network security configuration, please see the official Google documentation: https://developer.android.com/training/articles/security-config

Proguard Configuration

If you’re using Proguard in your project, please add the following lines to your Proguard config file, as per your requirements:

 -keep public class com.smaato.sdk.** { *; }
    -keep public interface com.smaato.sdk.** { *; }

SDK initialization

Add to your Application.OnCreate() method the following line, which initializes the Smaato SDK.

<code>SmaatoSdk.init(this, publisherId);


Optional configuration
You can configure additional parameters for the SDK by passing the Config parameter to the init method.


Additionally, it is recommended to configure the SDK with user information. This is an optional step and can be implemented at a later time using the following configurations:

Config config = Config.builder()
        .setLogLevel(LogLevel.INFO)
        .setHttpsOnly(false)
        .build();
  
SmaatoSdk.init(this, config, publisherId);

GPSEnabled flag allows to get user’s location by Smaato SDK automatically and put it inside ad requests.

Supported Callbacks

Banners

Callback MessageReason
onBannerLoadedThis will be invoked when an advertisement is successfully received.
onBannerFailedThis will be invoked when an advertisement request is failed or time-to-live of the ad has been expired.
onBannerClickedThis will be invoked when a click event is registered for an advertisement.
onBannerImpressionThis will be invoked when an impression occurred.

Interstitials

Callback MessageReason
onInterstitialLoadedThis will be invoked when an advertisement is successfully received
onInterstitialFailedThis will be invoked when there was an error during loading/showing an ad or time-to-live of the ad has been expired.
onInterstitialShownThis will be invoked when a Fullscreen Interstitial Ad ad is opened.
onInterstitialDismissedThis will be invoked when a Fullscreen Interstitial Ad ad is closed.
onInterstitialClickedThis will be invoked when a user clicks on an ad.
onInterstitialImpressionThis will be invoked when an impression occurred.

Rewarded Video

Callback MessageReason
onRewardedVideoLoadSuccessThis will be invoked when the Rewarded Video Ad is successfully received.
onRewardedVideoLoadFailureThis will be invoked when there was an error during loading/showing an ad or time-to-live of the Rewarded Video Ad is expired.
onRewardedVideoPlaybackErrorThis will be invoked when there is an error during the Rewarded Video Ad playback.
onRewardedVideoClosedThis will be invoked when the Rewarded Video Ad is closed.
onRewardedVideoClickedThis will be invoked when the Rewarded Video Ad is clicked.
onRewardedVideoStartedThis will be invoked when the Rewarded Video Ad starts playing.
onRewardedVideoCompletedThis will be invoked when the Rewarded Video Ad is completed and the user should be rewarded.
Doc Feedback Product Feedback

Last Modified: March 13, 2024 at 2:59 pm