Skip to content

Latest commit

 

History

History
483 lines (350 loc) · 19 KB

README.md

File metadata and controls

483 lines (350 loc) · 19 KB

Huawei-Mopub Mediation Github Documentation

Latest Version Kotlin
Supported Platforms

Introduction

In this documentation we explained how to use Huawei-MoPub mediation with in the different platforms.

Compatibility

Banner Ad Interstitial Ad Rewarded Ad Native Ad
Native (Java/Kotlin)
Unity
React Native
Flutter

How to start?

Create an ad unit on Huawei Publisher Service

  1. Sign in to Huawei Developer Console and create an AdUnit

Create a custom event on MoPub:

Make sure to check the article on How to use Huawei Ads with MoPub mediation

  1. Sign in to your Huawei Developer Console and create an AdUnit
  2. Sign in to your MoPub console
  3. Go to one of your orders and create a new line item
  4. Select Network line item as the type
  5. Select Custom SDK network as the network
  6. Enter the Custom event class and Custom event data according to the type of your Ad. Refer to the section below.

Custom event class

Ad Type Custom event class
Banner Ad com.hmscl.huawei.ads.mediation_adapter_mopub.banner
Interstitial Ad com.hmscl.huawei.ads.mediation_adapter_mopub.interstitial
Rewarded Video Ad com.hmscl.huawei.ads.mediation_adapter_mopub.rewarded
Native Ad (Basic) com.hmscl.huawei.ads.mediation_adapter_mopub.native_basic
Native Ad (Advanced) com.hmscl.huawei.ads.mediation_adapter_mopub.native_advanced

Custom Event Parameters

Note: Using the event parameter keys while testing may result test ads to not return.

Banner, Interstitial, Rewarded

{
    "adUnitID": "111",  <-- Mandatory Field
    "appid":"222",
    "tagForChildProtection": "false",
    "tagUnderAgeOfPromise": "false",
    "tagAdContentClassification": "w",
    "tagConsentString": ""
}

Native

{
    "adUnitID": "111",  <-- Mandatory Field
    "appid":"222",
    "tagForChildProtection": "false",
    "tagUnderAgeOfPromise": "false",
    "tagAdContentClassification": "false",
    "tagConsentString": "false",
    "orientation_preference" : "1"
    "ad_choices_placement" : "1"
    "swap_margins" : "1"
}

Parameters Description

Key Description Possible value
adUnitID Huawei Ads Unit ID String
appid Huawei Ads App ID String
tagForChildProtection Sets the tag for child-directed content, to comply with the Children's Online Privacy Protection Act (COPPA).
  • true: You want your ad content to be COPPA-compliant (interest-based ads and remarketing ads will be disabled for the ad request).
  • false: You do not want your ad content to be COPPA-compliant.
tagUnderAgeOfPromise Sets the tag for users in the European Economic Area (EEA) under the age of consent, to comply with the General Data Protection Regulation (GDPR). Ad requests with this tag enabled will be unable to obtain personalized ads.
  • true: You want the ad request to meet the ad standard for users under the age of consent.
  • false: You do not want the ad request to meet the ad standard for users under the age of consent.
tagAdContentClassification Sets the maximum ad content rating for the ad requests of your app. The ads obtained using this method have a content rating at or below the specified one.
  • w: content suitable for widespread audiences.
  • pi: content suitable for audiences under parental instructions.
  • j: content suitable for junior and older audiences.
  • a: content suitable only for adults.
tagConsentString Sets the user consent string that complies with TCF 2.0. String
orientation_preference (Native specific) Sets the orientation of an ad image.
  • 0: ANY
  • 1: PORTRAIT
  • 2: LANDSCAPE
ad_choices_placement (Native specific) Sets the AdChoices icon position
  • 0: TOP_LEFT
  • 1: TOP_RIGHT
  • 2: BOTTOM_RIGHT
  • 3: BOTTOM_LEFT
swap_margins (Native specific) Configure margin
  • true: Set margin on
  • false: Set margin off

Note: All values ​​must be String format.

Also all values can be set dynamically.

moPubNative.setLocalExtras(
    mapOf(
        TAG_FOR_CHILD_PROTECTION_KEY to true,
        TAG_FOR_UNDER_AGE_OF_PROMISE_KEY to true,
        TAG_FOR_AD_CONTENT_CLASSIFICATION_KEY to true,
        TAG_CONSENT_STRING to "TCF 2.0 String",
        KEY_EXTRA_ORIENTATION_PREFERENCE to 1,
        KEY_EXTRA_AD_CHOICES_PLACEMENT to 1,
        KEY_EXPERIMENTAL_EXTRA_SWAP_MARGINS to 1
    )
)

Note: Be aware that custom events parameters in Mopub platform will override your code side changes on the parameters.

Mediation Child Protection Document

Make sure to check the article on Huawei Mopub Mediation - Child Protection

Integrate the Huawei Mediation SDK

In the project-level build.gradle, include Huawei’s maven repository

repositories {
    google()
    jcenter() // Also, make sure jcenter() is included
    maven { url 'https://developer.huawei.com/repo/' } // Add this line
    maven {url "https://jitpack.io"} // Add this line
}

...

allprojects {
    repositories {
        google()
        jcenter() // Also, make sure jcenter() is included
        maven { url 'https://developer.huawei.com/repo/' } //Add this line
        maven {url "https://jitpack.io"} // Add this line
    }
}

In the app-level build.gradle, include Huawei Ads dependency (required by the adapter) and the Huawei mediation adapter

dependencies {
    implementation 'com.huawei.hms:ads:3.4.49.301'
    implementation 'com.github.Explore-In-HMS:huawei.ads.mopub_mediation:<latest_version>'
}

Check the latest Huawei Ads SDK here

Check the latest version of adapter here

Important:: To add Huawei Ads Kit SDK and Mediation adapter to the cross platforms apps, the native project should be opened with Android Studio.

Important: A device with Huawei Mobile Services (HMS) installed is required.

Permissions

The HUAWEI Ads SDK (com.huawei.hms:ads) has integrated the required permissions. Therefore, you do not need to apply for these permissions.

android.permission.ACCESS_NETWORK_STATE: Checks whether the current network is available.

android.permission.ACCESS_WIFI_STATE: Obtains the current Wi-Fi connection status and the information about WLAN hotspots.

android.permission.BLUETOOTH: Obtains the statuses of paired Bluetooth devices. (The permission can be removed if not necessary.)

android.permission.CAMERA: Displays AR ads in the Camera app. (The permission can be removed if not necessary.)

android.permission.READ_CALENDAR: Reads calendar events and their subscription statuses. (The permission can be removed if not necessary.)

android.permission.WRITE_CALENDAR: Creates a calendar event when a user clicks the subscription button in an ad. (The permission can be removed if not necessary.)

Version Change History

1.2.0

Child protection has been added.

1.1.1

Uses 'com.huawei.hms:ads:3.4.41.304' dependency for GMS phones

Platforms

Native

This section demonstrates how to use MoPub mediation feature with Huawei Ads Kit on Native Android app.

Firstly, integrate the MoPub SDK for Android:

MoPub Android SDK can be used for all ad types.

Note: Developers can find app level build.gradle in their project from "app-folder/app/build.gradle"

Banner Ads

To use Banner ads in Native android apps, please check the MoPub SDK. Click here to get more information about MoPub SDKs Banner Ad development.

Interstitial Ads

To use Interstitial ads in Native android apps, please check the MoPub SDK. Click here to get more information about MoPub SDKs Interstitial Ad development.

Rewarded Ads

To use Rewarded ads in Native android apps, please check the MoPub SDK. Click here to get more information about MoPub SDKs Rewarded Ad development.

Native Ads

To use Native ads in Native android apps, please check the MoPub SDK. Click here to get more information about MoPub SDKs Native Ad development.

Unity

This section demonstrates how to use MoPub mediation feature with Huawei Ads Kit on Unity.

Make sure to check the article on How to use Huawei Ads with Supported Ad Platforms in Unity ?

Supported Ad Formats are: Banner Ads, Interstitial Ads and Rewarded Ads.

Firstly, integrate the MoPub Unity SDK to Unity.

For more details on MoPub Unity SDK visit here

Banner Ads

To use Banner ads in Unity , please check the MoPub Unity SDK. Click here to get more information about Mopub Unity SDKs Banner Ad development.

Interstitial Ads

To use Interstitial ads in Unity, please check the MoPub Unity SDK. Click here to get more information about Mopub Unity SDKs Interstitial Ad development.

Rewarded Ads

To use Rewarded ads in Unity, please check the MoPub Unity SDK. Click here to get more information about Mopub Unity SDKs Banner Ad development.

Step 1:

Make sure to switch to the Android Platform from Build Settings -> Android -> Switch Platform

Step 2:

Edit -> Project Settings -> Player -> Other Settings
In Other Settings set minimum API level to at least 21.

Step 3:

Edit -> Project Settings -> Player -> Publishing Settings
In Publishing Settings select “Custom Main Gradle Template” , “Custom Base Gradle Template” and “Custom Greadle Properties Template”
This will let you override mainTemplate.gradle , baseProjectTemplate.gradle and gradleTemplate.properties files in the project.

Step 4:

baseProjectTemplate.gradle is equal to project-level gradle so you have to include Huawei's Maven repositories from the Integrate the Huawei Mediation SDK section from here
mainTemplate.gradle is equal to app-level build.gradle so you have to include dependencies from the Integrate the Huawei Mediation SDK section from here.

Step 5:

Open gradleTemplate.properties and add the following lines

android.useAndroidX=true
android.enableJetifier=true

After these configurations is completed you can display Huawei Ads.

Note: In case of any error on aaptOptions you can add the following line to aaptOptions in launcherTemplate.gradle which you override it by enabiling it from Edit -> Project Settings -> Player -> Publishing Settings

aaptOptions {
        noCompress = ['.ress', '.resource', '.obb'] + unityStreamingAssets.tokenize(', ')
        ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
    }

React Native

This section demonstrates how to use MoPub mediation feature with Huawei Ads Kit on React Native apps.

Make sure to check the article on How to use Huawei Ads with MoPub mediation (React Native)

Important: There is no official React Native SDK for MoPub, therefore third party SDKs has been used in the demonstrations.

Firstly, integrate the React Native MoPub SDK as below depending on type of ad:

For Interstitial ad react-native-mopub-sdk SDK can be used.

Note: Developers can find app level build.gradle in their project from "app-folder/android/app/build.gradle"

Then use the following sample codes based on specific ad types.

Sample Codes Based on Ad Types

Banner Ads

Banner ads are not supported with this SDK. To use banner ads in React Native app, please check the HMS Core Ads Kit React Native SDK. Click here to get more information about HMS Core React Native SDK.

Interstitial Ad

<TouchableOpacity style={{ width: 100, height: 30, backgroundColor: 'red', marginTop: 10 }} onPress={() =>
          RNMoPubInterstitial.loadAd()
        }>
          <Text>
            load ad
                    </Text>
        </TouchableOpacity>

Rewarded Ads

Rewarded ads are not supported with this SDK. To use Rewarded ads in React Native app, please check the HMS Core Ads Kit React Native SDK. Click here to get more information about HMS Core React Native SDK.

Native Ads

Native ads are not supported with this SDK. To use Native ads in React Native app, please check the HMS Core Ads Kit React Native SDK. Click here to get more information about HMS Core React Native SDK.

Flutter

This section demonstrates how to use MoPub mediation feature with Huawei Ads Kit on Flutter.

Make sure to check the article on How to show Huawei ads in Flutter using Mopub mediation?)

Important: There is no official Flutter SDK for MoPub therefore third party SDKs has been used in the demonstrations.

Firstly, integrate the MoPub Flutter SDK as below depending on type of ad:

For Banner , Interstitial and Rewarded ad types mopub_flutter SDK can be used.

Note: Developers can find app level build.gradle in their project from "app-folder/android/app/build.gradle"

Note: To avoid "java.lang.RuntimeException: Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider" error, an Admob ID needs to be added to the application. If both Admob and MoPub are not used in the project, add a sample Admob id to solve this exception.

Solution: Add this meta-data tag to the AndroidManifest.xml file (Open android side of the flutter project to edit Manifest file.)

<meta-data
 	android:name="com.google.android.gms.ads.APPLICATION_ID"
 	android:value="ca-app-pub-3940256099942544~3347511713"/>

Then use the following sample codes based on specific ad types.

Sample Codes Based on Ad Types

Banner Ad

try {
   MoPub.init('ad_unit_id', testMode: true).then((_) {
_  loadRewardedAd();
_  loadInterstitialAd();
         });
 } 
MoPubBannerAd(
   adUnitId: 'ad_unit_id',
   bannerSize: BannerSize.STANDARD,
   keepAlive: true,
   listener: (result, dynamic) {
     print('$result');
         },
      );

Interstitial Ad

void _loadInterstitialAd() {
  interstitialAd = MoPubInterstitialAd(
    'ad_unit_id',
        (result, args) {
      print('Interstitial $result');
    },
    reloadOnClosed: true,
  );
}
RaisedButton(
    onPressed: () async {
    interstitialAd.show();
    },
   child: Text('Show interstitial'),
 )

Rewarded Ads

void _loadRewardedAd() {
  videoAd = MoPubRewardedVideoAd('ad_unit_id',
          (result, args) {
        setState(() {
          rewardedResult = '${result.toString()}____$args';
        });
        print('$result');
        if (result == RewardedVideoAdResult.GRANT_REWARD) {
          print('Grant reward: $args');
        }
      }, reloadOnClosed: true);
}
RaisedButton(
onPressed: () async {
   var result = await videoAd.isReady();
   print('Is Ready $result');
   if (result) {
    videoAd.show();
  }
},
child: Text('Show Video'),
)

Native Ads

Native ads are not supported with this SDK. To use Native ads in Flutter app, please check the HMS Core Ads Kit Flutter SDK. Click here to get more information about HMS Core React Native SDK.

Cordova

Because MoPub ads for Cordova platform is not officially supported and there is no stable MoPub plugin for Cordova, MoPub-Huawei Ads Mediation is not possible on Cordova platform.

Huawei Ads can still be used on Cordova, for implementation click here.

Error Codes

Error code 700 : Your request has been failed. Make sure that you are using test AdUnit Id while testing the mediation.

Error code 3 : Ad request is successful but the server does not return available ad assets Make sure that you are using test AdUnit Id while testing the mediation.

MoPubErrorCode "NO_FILL" / "No ads found" : Make sure that your Custom Event Parameters are correct. Be aware that Custom Event Parameters are JSON's and it shouldn't end with a comma (",").

Screenshots

MoPub Ads

Banner Ad

Interstitial Ad

Rewarded Ad

Native Ad

Huawei Ads

Banner Ad

Interstitial Ad

Rewarded Ad

Native Ad