ConsoliAds Mediation Integration

You are here:
Estimated reading time: 8 min
ConsoliAds Android SDK Integration

Getting Started

This documentation will help you integrate ConsoliAds Mediation Android SDK to get instant access to the best ad networks around the globe for optimized mobile ad analytics and earnings.

Before you proceed to integrate, make sure you have:

•   Registered at ConsoliAds portal
•   Logged in to the ConsoliAds dashboard ConsoliAds portal

Create an App

NOTE: You can skip this step if you’ve already created your app on ConsoliAds dashboard

1.From the left side bar, navigate to Apps-> New App

2.Simply import your Live app or manually enter the required information and proceed to ‘Finish’ to instantly create your app

Download Android SDK

1.Download the latest ConsoliAds Android SDK for your required from https://portal.consoliads.com/download/Android

Setting Up Project Dependencies

Integrating SDK

Once the ConsoliAds mediation SDK is downloaded:
•   copy all ‘.aar’ files to your android project inside the “libs” folder. Please create a “libs” folder inside your Android Studio app if it does not exist.

•  Open your Project level “build.gradle” and write the following under allprojects -> repositories section:

flatDir { dirs 'libs' }

•  Open your app level “build.gradle” and write the following lines in the dependencies section to import ConsoliAds mediation:

implementation(name: 'consoliadsmediation', ext: 'aar')
implementation(name: 'consoliads-mediation', ext: 'aar')
implementation(name: 'consoliadsplugin', ext: 'aar')
implementation(name: 'loaderlibrary', ext: 'aar')

•   Find “libConfigureServer.jar” in ConsoliAds mediation package and place it in the root directory of the project.

Adding Dependencies

ConsoliAds mediation SDK requires following libraries as dependencies. Open your app level “build.gradle” and add following dependencies:

implementation 
'com.google.android.gms:play-services-basement:17.1.1'
implementation 
'com.google.android.gms:play-services-location:17.0.0'
implementation 
'com.google.android.gms:play-services-ads-identifier:17.0.0' 
implementation 'com.android.volley:volley:1.1.1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.code.gson:gson:2.8.5’

** Your project settings should be ready to support ConsoliAds in your android code to add all the ad placements for all supported ad formats **

 

Ready to Code

SDK Initialization

ConsoliAds mediation SDK needs a Product Name and Bundle Identifier before initialization. Please declare as:

ConsoliAds.Instance().productName = “Fitness Guide";
ConsoliAds.Instance().bundleIdentifier = “com.mystudio.fitnessguide";

NOTE: Always import the required packages using your IDE

Now initialize by:

 public void initialize(boolean isDevMode, final boolean userConsent, Activity aRef)

Parameter details:
•   isDevMode: when TRUE, simulates the development environment and fetches all settings from ‘Dev Placeholders’. Complete app development should be done with ‘Dev Mode’ ON. When your app is ready to be published, please note:
               •   ‘Dev Mode’ MUST BE FALSE
               •   If you make your build with ‘Dev Mode’ TRUE, the ad configurations from ‘Dev. Placeholder and Ads‘ tab on the dashboard would be used.
               •   If you make your build with ‘Dev Mode’ FALSE, the ad configurations from ‘Live Placeholder and Ads’ tab on the dashboard would be used.
•   userConsent: TRUE if user agrees to share his data and opts for personalized ads, FALSE otherwise. This flag is used for GDPR and CCPA compliance.
•   aRef: Reference of the active Activity

Initialize Placeholders

Once initialized, the SDK is ready to show ads. However, showing ads requires placeholders to have ad networks added:
•   Go to your ConsoliAds dashboard Apps -> Manage -> <app>-> Placeholders & Ads
•   Add required ad networks (Interstitial, Video, Rewarded Video, Banner, Native, Icon) to your app as shown below:

 

Show Interstitial/Video Ad

Now add the following lines of code to show an interstitial ad in your app:

ConsoliAds.Instance.ShowInterstitial(int sceneIndex, Activity aRef)

Parameter details:

   sceneIndex: index of the placeholder from ‘Placeholders & Ads’ section on the ConsoliAds dashboard e.g. if MainMenu is your first placeholder and you wish to show Interstitial on it, then your code will look like:

ConsoliAds.Instance.ShowInterstitial(0);

   aRef: Reference of the active Activity

NOTE: the respective placeholder must have an ad network added from the ConsoliAds dashboard, else no ad will be displayed

Show Rewarded Video Ad

Load Rewarded Ad

Showing rewarded video requires loading it beforehand. Use the following to load a rewarded ad:

 ConsoliAds.Instance.LoadRewarded(int sceneIndex);

It is highly recommended to call LoadRewarded(sceneIndex) as early as possible to allow videos to be pre-loaded.

Availability of Rewarded Ad

Despite having the ad load called, rewarded video availability should be explicitly checked. Check rewarded video ad availability by using following method:

ConsoliAds.Instance.IsRewardedVideoAvailable (int sceneIndex);

Return value (boolean):
•   True if the ad is available
•   False if the ad is not available
Show Rewarded Video

ConsoliAds.Instance.ShowRewardedVideo(int sceneIndex, Activity aRef)

Parameter details:

•   sceneIndex: index of the placeholder from ‘Placeholders & Ads’ section on the ConsoliAds dashboard e.g. if MainMenu is your first placeholder and you wish to show Interstitial on it, then your code will look like:

ConsoliAds.Instance.ShowInterstitial(0);

•   aRef: Reference of the active Activity

NOTE: the respective placeholder must have an ad network added from the ConsoliAds dashboard, else no ad will be displayed

Reward Users

In order to reward your user, a callback needs to be implemented with your lines of code to incentivize the user. ConsoliAds mediation SDK implements a single callback irregardless of any ad network used.

Implement the interface ConsoliAdsRewardedListener to provide the following definition of the method to reward your users: 

public void onRewardedVideoAdCompletedEvent()
	{
		// Write your code to reward your user here
	}

Show Banner Ad

To show banner ad you need to first add the following view to your required activity xml:

<com.consoliads.mediation.bannerads.CAMediatedBannerView
android:id="@+id/consoli_banner_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp"
/>

Get the banner view as follows:

CAMediatedBannerView mediatedBannerView = findViewById(R.id.consoli_banner_view);

Now use the following code to display the banner:

ConsoliAds.Instance().ShowBanner(currentScene , MainActivity.this , mediatedBannerView);

Hide Banner Ad

To hide banner, use the following:

mediatedBannerView.setVisibility(View.GONE);

Add Banner Listener

To receive callbacks for banner ad type, add banner listener on the mediated view as follows:

cAMediatedBannerView.setBannerListener(ConsoliAdsBannerListener consoliAdsBannerListener);

Show Native Ad

Add the following NativeView in your xml where you want to show the native ad:

<?xml version="1.0" encoding="utf-8"?>

<com.consoliads.mediation.nativeads.CANativeAdView 
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#FFF"
android:visibility="gone"
android:id="@+id/native_ad_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="4dp">

<RelativeLayout
android:id="@+id/ad_top_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.consoliads.mediation.nativeads.CAAppIconView
android:id="@+id/native_ad_icon"
android:layout_width="35dp"
android:layout_height="35dp" />

<LinearLayout
android:layout_toStartOf="@id/ad_choices_container"
android:layout_toLeftOf="@id/ad_choices_container"
android:layout_toEndOf="@id/native_ad_icon"
android:layout_toRightOf="@id/native_ad_icon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="4dp"
android:paddingRight="4dp">

<TextView
android:id="@+id/native_ad_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:textColor="@android:color/black"
android:textSize="15sp" />

<TextView
android:id="@+id/native_ad_sub_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:textColor="@android:color/darker_gray"
android:textSize="12sp" />

</LinearLayout>

<com.consoliads.mediation.nativeads.CAAdChoicesView
android:layout_margin="4dp"
android:id="@+id/ad_choices_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
/>

</RelativeLayout>

<com.consoliads.mediation.nativeads.CAMediaView
android:layout_marginTop="2dp"
android:layout_above="@+id/ad_bottom_view"
android:layout_below="@+id/ad_top_view"
android:id="@+id/native_ad_media"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

<RelativeLayout
android:layout_marginTop="2dp"
android:id="@+id/ad_bottom_view"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
android:gravity="top|start|left"
android:layout_toLeftOf="@+id/native_ad_call_to_action"
android:layout_toStartOf="@+id/native_ad_call_to_action"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/native_ad_body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center_vertical"
android:lines="2"
android:textColor="@android:color/black"
android:textSize="12sp" />

<TextView
android:id="@+id/native_ad_sponsored_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:textColor="@android:color/darker_gray"
android:textSize="12sp" />

</LinearLayout>
<com.consoliads.mediation.nativeads.CACallToActionView
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="@+id/native_ad_call_to_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="#4286F4"
android:padding="4dp"
android:textColor="@android:color/white"
android:textSize="12sp" />

</RelativeLayout>
 </RelativeLayout>
</com.consoliads.mediation.nativeads.CANativeAdView>

Declare native ad components in your activity:

TextView title , subtitle , body , sponsored;
CANativeAdView adView;
CAAdChoicesView adChoicesView;
CAAppIconView appIconView;
CAMediaView mediaView;
CACallToActionView actionView;
MediatedNativeAd mediatedNativeAd;

Now initialize:

title = findViewById(R.id.native_ad_title);
subtitle = findViewById(R.id.native_ad_sub_title);
body = findViewById(R.id.native_ad_body);
sponsored = findViewById(R.id.native_ad_sponsored_label);
adView = findViewById(R.id.native_ad_frame);
adChoicesView = findViewById(R.id.ad_choices_container);
appIconView = findViewById(R.id.native_ad_icon);
mediaView = findViewById(R.id.native_ad_media);
actionView = findViewById(R.id.native_ad_call_to_action);

Show native ad using:

 ConsoliAds.Instance().loadNativeAd(scene, NativeAdActivity.this, new ConsoliAdsNativeListener() {

@Override
   public void onNativeAdLoaded(MediatedNativeAd ad) {
   	Log.i("ConsoliAdsListners","onNativeAdLoaded");
mediatedNativeAd = ad;
adView.setVisibility(View.VISIBLE);
actionView.setTextColor("#ffffff");
actionView.setTextSize_UNIT_SP(12);
mediatedNativeAd.setSponsered(sponsored);
mediatedNativeAd.setAdTitle(title);
mediatedNativeAd.setAdSubTitle(subtitle);
mediatedNativeAd.setAdBody(body);
mediatedNativeAd.registerViewForInteraction(NativeAdActivity.this , appIconView , mediaView , actionView , adView,adChoicesView);
   }
@Override
public void onNativeAdLoadFailed() {
Log.i("ConsoliAdsListners","onNativeAdLoadFailed");
}
});

You can destroy native ad using:

 if(mediatedNativeAd != null)
{
   mediatedNativeAd.destroy();
}

Show Icon Ad

Add the following xml in your required activity view:

 <com.consoliads.sdk.iconads.IconAdView
android:id="@+id/consoli_icon_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</com.consoliads.sdk.iconads.IconAdView>

Load and show icon ad using:

IconAdView iconAdView = findViewById(R.id.consoli_icon_view);
IconAdBase iconAdBase = (IconAdBase)
ConsoliAds.Instance().loadIconAd(currentScene , MainActivity.this ,
consoliAdsIconListener);
If( iconAdBase != null ){
iconAdView.setIconAd(iconAdBase , IconAnimationConstant.PULSE)
}

Icon ads can be shown with different types of animations. You can pass following possible enum values to the setIcon function

1)  NONE
2) SHAKE
3) PULSE

 

Configure Server

Configure Server performs a sync of your app on the dashboard that makes use of your given app information. The sync performs the following:

1. Integrated Ad Networks: all the integrated ad networks are pushed to the dashboard to make sure that changes only to the respective ad networks can be done.

NOTE: Configure Server DOES NOT change any Live configurations of the app. The settings have to be ‘Move To Live’ before the app goes Live on the app store

Now open the command prompt (or terminal in mac) and go to the root directory of the project to run the following command:

java -jar libConfigureServer.jar userSignature appPackage platform

NOTE: make sure that you had already moved the libConfigureServer.jar when going through ‘Integrating SDK’ section of this documentation

Parameter details:

1. userSignature: essential to identify the user according to his role and rights provided on the ConsoliAds dashboard in order to configure settings of the specific app

a. The user signature can be obtained by going to your Personal Info by clicking on your name in the right corner of the top bar on your ConsoliAds dashboard.

2.appPackage: your app’s unique package name such as com.x.y

3.platform: (google, apple, amazon) is used by ConsoliAds ONLY to fetch the information of your app according to the given platform from the ConsoliAds dashboard

A sample call for configure server looks like:

java -jar libConfigureServer.jar 5d4b02b39dc419548ea8183e8d3ea170 com.seasonapps.myfitnessguide google

** Congratulations, You are ready to build your app on to your android mobile device to see all the ad placements showing ads according to your Test Mode **

 

Hide All Ads

If you want to hide all ads, except Rewarded Ads, from your entire app, use the following:

ConsoliAds.Instance.hideAllAds();

NOTE: You only need to call this method once in your script to hide all ads from your app

Using More Apps URL and Support Email

•   The more apps URL and support email are added against a particular brand
•   When an app of the respective brand is configured, the more apps URL and support email are available for use
•   To access more apps URL, use:

ConsoliAds.Instance.MoreFunURL()

•   To access support email, use:

ConsoliAds.Instance.SupportEmail()

Applying Dev Settings to Live

In order to see the ‘Dev Mode’ settings on ConsoliAds dashboard, open the ‘Placeholder and Ads‘ tab in the details of your specific app then click ‘Dev. Placeholder & Ads’ as shown below:

 

Here you will see all the changes you have made from the inspector. Click ‘Apply on Live App’ to apply these configurations to your live app.

App Settings on ConsoliAds Dashboard

After successfully integrating your app with ConsoliAds SDK, following app settings can be explored on the ConsoliAds dashboard in the App Details section:

Test Mode

By Default a new application is in Test Mode. In Test Mode only test ads are shown. Test Mode can ONLY be disabled by importing your app’s Live credentials in the Details tab.

Ad Network IDs

If you are using Admob, Facebook Audience Network or Chartboost you need to provide their Ad IDs on the dashboard in your app Ad Networks section.

All other integrated ad networks will automatically go Live once your app’s Test Mode is disabled.

Ad Filters

Apply all ad filters, for the integrated ad networks, with complete ease from the ConsoliAds dashboard in the Ad Filters section of the app details.

Debug Logs

If enabled, debug logs will be shown for your app in respective editors for Android and iOS.

Child Directed

Child Directed enables your application with complete COPPA compliance.

Hide Ads

All ads, except Rewarded Videos, can be completely turned OFF using Hide Ads on the dashboard.

Auto Mediation

Auto Mediation automatically optimizes your ad networks for each region and each ad format pertaining to every placeholder in your app such that you get the best eCPMs.

We highly recommend to use Auto Mediation in order to witness instant revenue increments upto 20%

For Advance Development

Check Interstitial Availability

You can also check for interstitial ad availability for a specific placeholder using the following method.

ConsoliAds.Instance.IsInterstitialAvailable (int sceneIndex);

Return value(boolean):
•   True if the ad is available
•   False if the ad is not available

More Interface Listeners

ConsoliAds implements single callback events for all Ad Networks. Following callbacks can be used as per need:

 public interface ConsoliAdsListener {
   void onConsoliAdsInitializationSuccess();
}

Interstitial Listeners

Add the following in onCreate() of your Activity to set interstitial listener:

 ConsoliAds.Instance().setConsoliAdsInterstitialListener(this); 
public interface ConsoliAdsInterstitialListener { 
  void onInterstitialAdShownEvent();
  void onInterstitialAdClickedEvent();
  void onInterstitialAdClosedEvent();
  void onInterstitialAdFailedToShowEvent();
}

Rewarded Video Listeners

Add the following in onCreate() of your Activity to set rewarded video listener:

 ConsoliAds.Instance().setConsoliAdsRewardedListener(this);
public interface ConsoliAdsRewardedListener {
  void onRewardedVideoAdLoadedEvent();
  void onRewardedVideoAdShownEvent();
  void onRewardedVideoAdCompletedEvent();
  void onRewardedVideoAdClickEvent();
  void onRewardedVideoAdFailToLoadEvent();
  void onRewardedVideoAdFailToShowEvent();
  void onRewardedVideoAdClosedEvent();
}

Banner Listeners

 public interface ConsoliAdsBannerListener {
   void onBannerAdShownEvent();
   void onBannerAdFailToShowEvent();
   void onBannerAdClickEvent();
   void onBannerAdRefreshEvent();
}

Icon Listeners

 public interface ConsoliAdsIconListener {
  void onIconAdLoadEvent();
  void onIconAdLoadFailedEvent();
  void onIconAdRefreshEvent();
  void onIconAdShownEvent();
  void onIconAdClosedEvent();
  void onIconAdClickEvent();
}

Native Listeners

public abstract class ConsoliAdsNativeListener {
public abstract void onNativeAdLoaded(MediatedNativeAd
mediatedNativeAd);
public void onNativeAdLoadFailed(){}
public void onNativeAdClicked(){}
public void onNativeAdShown(){}
public void onNativeAdFailedToShow(){}
}

Multiple Native Ads in a View

To load native ads in list use:

 private void loadNativeAd(){
ConsoliAds.Instance().loadNativeAd(Integer.parseInt(sceneIndex),
ConsoliAdsListActivity.this, new ConsoliAdsNativeListener() {
@Override
public void onNativeAdLoaded(MediatedNativeAd mediatedNativeAd)
{
dataList.add(listIndex , mediatedNativeAd);
listViewAdapter.notifyDataSetChanged();
}
@Override
public void onNativeAdLoadFailed() {
Log.i("ConsoliAdsListners","onNativeAdLoadFailed");
}
});
}

Use this code in RecyclerView Adapter:

private class ConsoliadsNativeAdViewHolder extends
RecyclerView.ViewHolder {
TextView title , subtitle , body , sponsered;
CANativeAdView adView;
CAAdChoicesView adChoicesView;
CAAppIconView appIconView;
CAMediaView mediaView;
CACallToActionView actionView;
ConsoliadsNativeAdViewHolder(View itemView) {
super(itemView);
title = itemView.findViewById(R.id.native_ad_title);
subtitle = itemView.findViewById(R.id.native_ad_sub_title);
body = itemView.findViewById(R.id.native_ad_body);
sponsored =
itemView.findViewById(R.id.native_ad_sponsored_label);
adView = itemView.findViewById(R.id.native_ad_frame);
adChoicesView = itemView.findViewById(R.id.ad_choices_container);
appIconView = itemView.findViewById(R.id.native_ad_icon);
mediaView = itemView.findViewById(R.id.native_ad_media);
actionView = 
itemView.findViewById(R.id.native_ad_call_to_action);
}
}

Bind this view in your Adapter:

 ConsoliadsNativeAdViewHolder consoliadsNativeAdViewHolder =
(ConsoliadsNativeAdViewHolder) holder;
MediatedNativeAd mediatedNativeAd = (MediatedNativeAd) recipeList.get(position);
consoliadsNativeAdViewHolder.actionView.setTextColor("#ffffff");
consoliadsNativeAdViewHolder.actionView.setTextSize_UNIT_SP(12);
mediatedNativeAd.setSponsered(consoliadsNativeAdViewHolder.sponsered);
mediatedNativeAd.setAdTitle(consoliadsNativeAdViewHolder.title);
mediatedNativeAd.setAdSubTitle(consoliadsNativeAdViewHolder.subtitle);
mediatedNativeAd.setAdBody(consoliadsNativeAdViewHolder.body);
mediatedNativeAd.registerViewForInteraction((Activity) context,
consoliadsNativeAdViewHolder.appIconView ,
consoliadsNativeAdViewHolder.mediaView ,
consoliadsNativeAdViewHolder.actionView ,
consoliadsNativeAdViewHolder.adView,consoliadsNativeAdViewHolder.adCho
icesView);

More Help Sources of Integration

ConsoliAds Sample Project:

You can download the sample project from https://portal.consoliads.com/download/Android to see complete ConsoliAds integration already implemented for all ad formats

Youtube Videos:

You can watch short integrations videos on your youtube channel, https://www.youtube.com/watch?v=nExp4zfb0xc, to further explore integrations with ConsoliAds.

ConsoliAds GitHub forum

If you are having any technical issues, you can visit https://github.com/teamconsoliads/sampleapp-android to view known issues, share problems and suggestions.

Was this article helpful?
Dislike 1
Views: 2154