In this documentation we explained how to use Huawei-MoPub mediation with in the different platforms.
Banner Ad | Interstitial Ad | Rewarded Ad | Native Ad | |
---|---|---|---|---|
Native (Java/Kotlin) | ✅ | ✅ | ✅ | ✅ |
Unity | ✅ | ✅ | ✅ | ❌ |
React Native | ❌ | ✅ | ❌ | ❌ |
Flutter | ✅ | ✅ | ✅ | ❌ |
- Sign in to Huawei Developer Console and create an AdUnit
Make sure to check the article on How to use Huawei Ads with MoPub mediation
- Sign in to your Huawei Developer Console and create an AdUnit
- Sign in to your MoPub console
- Go to one of your orders and create a new line item
- Select Network line item as the type
- Select Custom SDK network as the network
- Enter the Custom event class and Custom event data according to the type of your Ad. Refer to the section below.
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 |
Note: Using the event parameter keys while testing may result test ads to not return.
{
"adUnitID": "111", <-- Mandatory Field
"appid":"222",
"tagForChildProtection": "false",
"tagUnderAgeOfPromise": "false",
"tagAdContentClassification": "w",
"tagConsentString": ""
}
{
"adUnitID": "111", <-- Mandatory Field
"appid":"222",
"tagForChildProtection": "false",
"tagUnderAgeOfPromise": "false",
"tagAdContentClassification": "false",
"tagConsentString": "false",
"orientation_preference" : "1"
"ad_choices_placement" : "1"
"swap_margins" : "1"
}
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). |
|
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. |
|
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. |
|
tagConsentString | Sets the user consent string that complies with TCF 2.0. | String |
orientation_preference (Native specific) | Sets the orientation of an ad image. |
|
ad_choices_placement (Native specific) | Sets the AdChoices icon position |
|
swap_margins (Native specific) | Configure margin |
|
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
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.
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.)
Child protection has been added.
Uses 'com.huawei.hms:ads:3.4.41.304' dependency for GMS phones
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"
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.
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.
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.
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.
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
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.
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.
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.
Make sure to switch to the Android Platform from Build Settings -> Android -> Switch Platform
Edit -> Project Settings -> Player -> Other Settings
In Other Settings set minimum API level to at least 21.
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.
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.
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:!*~"
}
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.
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.
<TouchableOpacity style={{ width: 100, height: 30, backgroundColor: 'red', marginTop: 10 }} onPress={() =>
RNMoPubInterstitial.loadAd()
}>
<Text>
load ad
</Text>
</TouchableOpacity>
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 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.
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.
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');
},
);
void _loadInterstitialAd() {
interstitialAd = MoPubInterstitialAd(
'ad_unit_id',
(result, args) {
print('Interstitial $result');
},
reloadOnClosed: true,
);
}
RaisedButton(
onPressed: () async {
interstitialAd.show();
},
child: Text('Show interstitial'),
)
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 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.
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 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 (",").
Banner Ad |
Interstitial Ad |
Rewarded Ad |
Native Ad |
Banner Ad |
Interstitial Ad |
Rewarded Ad |
Native Ad |