NextGen SDK | Android | MoPub Integration

Integration Guide for Publishers with MoPub as a Primary

(Android NextGen SDK version 21.1.4)

Assumptions

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

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:

Key Type Description
IABConsent_CMPPresent Boolean

Set to “YES” if a CMP that follows the IAB specification is present in the application.

IABConsent_SubjectToGDPR String

1” = Subject to GDPR
0” = Not subject to GDPR
-1” = Undetermined (default before initialization)

IABConsent_ConsentString

String

Base64-encoded consent string as defined in Consent string and vendor list format v1.1
IABConsent_ParsedPurposeConsents String String 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_ParsedVendorConsents

String

String 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 About Fullscreen Adspaces

Currently, only the Interstitial Multi-Ad Format is compatible for 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

Publisher ID: 1100042525  
Adspace ID Type Description
130626424 Rich Media Banner / Med-rect / Leaderboard / Skyscraper
130635694 Static Image Banner / Med-rect / Leaderboard / Skyscraper
130635706 MRAID Banner / Med-rect / Leaderboard / Skyscraper
130626426 Rich Media / Video Interstitial (Video with an end-card + Rich Media Interstitial for 320×480, 480×320, 1024×768 & 768×1024)
130626427 Video Skippable Video
130626428 Rewarded Rewarded Video
130635048 Rewarded Rewarded Video without an end-card

MoPub Dashboard setup

1. Go to the MoPub Dashboard –https://app.mopub.com/networks

2. Click on “New network” button

3. Choose “Custom SDK network” from the bottom of the list

4. Set the desired parameters in the next two tabs.

5. On “App & ad unit setup” tab, set the following: 

    • Custom event classes:
      • For Banner: com.mopub.mobileads.SMAMoPubSmaatoBannerAdapter
      • For Interstitial: com.mopub.mobileads.SMAMoPubSmaatoInterstitialAdapter
      • For Rewarded Video: com.mopub.mobileads.SMAMoPubSmaatoRewardedVideoAdapter
    • Custom event class data:
      • {"adspaceId":"<YOUR_SPX_ADSPACE_ID>"}

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
    }
}

Integration Options

This integration currently supports the MoPub SDK version 5.8.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:mopub-banner-adapter:21.1.4'

Interstitial (with Video & Rich Media support)

build.gradle

implementation 'com.smaato.android.sdk:mopub-interstitial-adapter:21.1.4'

Interstitial (with Rich Media support only)

build.gradle

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

Interstitial (with Video support only)

build.gradle

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

Rewarded Video

build.gradle

implementation 'com.smaato.android.sdk:mopub-rewarded-video-adapter:21.1.4'

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" />

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

android:networkSecurityConfig="@xml/network_security_config"

Then create the network_security_config.xml in the xml resource directory with the content:

<?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 official Google documentation: https://developer.android.com/training/articles/security-config

SDK initialization

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

SmaatoSdk.init(this, publisherId);

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

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

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:

SmaatoSdk.setKeywords(...);
SmaatoSdk.setSearchQuery(...);
SmaatoSdk.setGender(...);
SmaatoSdk.setAge(...);
SmaatoSdk.setLatLng(...);
SmaatoSdk.setRegion(...);
SmaatoSdk.setLanguage(...);
SmaatoSdk.setZip(...);
SmaatoSdk.setCoppa(...);

Supported Callbacks

Banners

Callback Message Reason
onBannerLoaded This will be invoked when an advertisement is successfully received.
onBannerFailed This will be invoked when an advertisement request is failed or time-to-live of the ad has been expired.
onBannerClicked This will be invoked when a click event is registered for an advertisement.
onBannerImpression This will be invoked when an impression occurred.

Interstitials

Callback Message Reason
onInterstitialLoaded This will be invoked when an advertisement is successfully received
onInterstitialFailed This will be invoked when there was an error during loading/showing an ad or time-to-live of the ad has been expired.
onInterstitialShown This will be invoked when a Fullscreen Interstitial Ad ad is opened.
onInterstitialDismissed This will be invoked when a Fullscreen Interstitial Ad ad is closed.
onInterstitialClicked This will be invoked when a user clicks on an ad.
onInterstitialImpression This will be invoked when an impression occurred.

Rewarded Video

Callback Message Reason
onRewardedVideoLoadSuccess This will be invoked when the Rewarded Video Ad is successfully received.
onRewardedVideoLoadFailure This will be invoked when there was an error during loading/showing an ad or time-to-live of the Rewarded Video Ad is expired.
onRewardedVideoPlaybackError This will be invoked when there is an error during the Rewarded Video Ad playback.
onRewardedVideoClosed This will be invoked when the Rewarded Video Ad is closed.
onRewardedVideoClicked This will be invoked when the Rewarded Video Ad is clicked.
onRewardedVideoStarted This will be invoked when the Rewarded Video Ad starts playing.
onRewardedVideoCompleted This will be invoked when the Rewarded Video Ad is completed and the user should be rewarded.

Modified: October 11, 2019 at 2:15 pm