👨🏼‍💻How to show Huawei Ads with Smartadserver Mediation?

Berke Coban
Huawei Developers
Published in
5 min readMar 17, 2022

In this article, we will talk about showing Huawei ads with Smartadserver’s Display SDK (Android) through mediation.

Supported ad types are banner, interstitial, rewarded, and native ads.

What is ad mediation?

Ad Mediation gives multiple ad networks access to your ad inventory, and gets them to compete against each other for ad slots. This process increases competition among advertisers and in return, increases your ad revenue. The mediation platform checks what CPM all the various ad networks are offering and looks for the highest one.

Structure of Waterfall (method for ad buying)

Getting Started

Creating a Huawei Ad unit

First things first, We need to create our ad units in Huawei Ads Publisher Console. Check this link to start.

This medium post also might help you for getting a Huawei Ad slot id.

Smartadserver Publisher Console

We created our Huawei ad slots. Our next step will be enabling mediation from the Smartadserver console. Let’s get started.

🔹Log-in to the smartadserver console.

  • Click here to log in to the console.

🔹 Create a site and a page for the mediation.

This part can be skipped if you have already have a site ID and Page ID available for use.

Site ID and Page ID are mandatory for making ad request with Display SDK.

Go to “Inventory -> Sites & Pages” and create a site and a page for your Huawei mediation.

Sites&pages
Creating site
Creating page

🔹 Create Ad Format ID

Go to “Inventory -> Formats” and create an Ad unit for your Ad type (put 0x0 for the size and note your Format ID).

Note your format ID, We will use our Site,page, and format ID to make an ad request.

Creating ad format

🔹 Create a Mediation Campaign

  • Go to “Campaigns -> Campaign List” and create a new campaign,
  • Select mediation on the pop-up, give your campaign a name and an expiration date)
Creating mediation campaign for Huawei Ads

🔹 Create a New Insertion

Select “New Insertion” inside your created campaign. Each insertion represents one Huawei ad slot. For example, if you want to use one banner and one rewarded slot, you need to create 2 insertions.

  • Switch to classical mode UI from the left side of the web page, give your insertion a name, select “Mobile” as category, select “AdNetwork / Mediation” as channel and select “Pay Ads” for the type. Select other fields according to your needs and click “Save and Go to Next Step
configure ad insertion-1
  • On the “Placement tab”, select your ad format, and select the site and page that are created on step-2. Click “Save and Go to Next Step”.
configure ad insertion-2
  • On the “Creatives tab”, click “Template Library”, on Offical Templates select “In-App Mediation Custom Adapter”.
configure ad insertion-3
  • A section will be seen named “Predefined template”. Give it a name, and select the ad format type (Banner,Rewarded, etc.)
custom data example for banner ads

For the “Adapter Class” and “Placement info” check the table below :

Note: For the Placement info section you need to write only the Huawei ad unit id with no spaces. (except banner ads)

For the banner ads, you need to write 3 things. Your Huawei ad unit id, banner width, and banner height.

for 320x50 banner test ad write the following with no spaces :

testw6vs28auh,320,50

Banner Sizes :

banner sizes for Huawei Ads

Note: Only BANNER_SIZE_360_57 and BANNER_SIZE_360_144 are supported in the Chinese mainland.

Android Studio Preparations

Adding Smartadserver Display SDK

Smartadserver Display SDK requires Android Studio version 3.0 or higher, and minimum API level 19. Check the link below to integrate Display SDK into your android application.

Adding Huawei Ads Repo

🔹 In the project-level build.gradle, include Huawei’s Maven repository and jitpack io.

repositories {
maven { url 'https://developer.huawei.com/repo/' }
maven {url "https://jitpack.io"}
}

...

allprojects {
repositories {
maven { url 'https://developer.huawei.com/repo/' }
maven {url "https://jitpack.io"}
}
}

🔹 In the app-level build.gradle, include Huawei Ads mediation adapter library and Huawei support library of smartadserver (needed for personalized ads).

dependencies { implementation 'com.github.Explore-In-HMS:huawei.ads.smartadsserver_mediation:v1.0.0'

implementation 'com.smartadserver.android:smart-core-sdk-huawei-support:1.0.0'
}

⛔ To allow HTTP and HTTPS network requests on devices with targetSdkVersion 28 or later, configure the following information in the AndroidManifest.xml file (not adding it effects rewarded ads)

<application
...
android:usesCleartextTraffic="true"
>
...
</application>

Demo project with Banner ad mediation (Kotlin)

We enabled Huawei mediation from the console and made all the preparations in Android Studio now let’s start coding. 😊

Our XML layout will be like this. You can change the height of the ‘SASBannerView’ according to your Banner size. Let’s look at the Kotlin code.

This is our simple banner activity code. On line 20, replace fields with the site, page, and format id that you have created.

Conclusion

Now you have successfully learned how to show Huawei ads with smart’s display SDK. You can check our Github repository for more details.

Take care until next time :)

References

--

--