ConsoliAds Mediation Integration

You are here:
Estimated reading time: 7 min

Download Mediation Native SDK

Download ConsoliAds Android Mediation SDK here and download the required Ad Networks SDKs here

Create App on Portal

Login to your ConsoliAds portal and go to Apps-> New App to create your native app.

ConsoliAds Mediation Integration

Make sure that you have already created a brand to associate your app with. Import your app directly from the app store or create manually by providing all the required information and save, ConsoliAds will create your app with the following default placeholders:
•   Activity 1
•   Activity 2
•   Activity 3
•   Activity 4
•   Options A
•   Options B
•   About
•   Settings

Integrating ConsoliAds Mediation

After downloading ConsoliAds mediation SDK, copy all ‘.aar’ files to your android project inside “libs” folder. Please create “libs” folder inside your Android Studio app if it does not exists.

To add your desired Ad Network to ConsoliAds mediation, please visit Add/Remove Ad Network‘ section.

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

flatDir { dirs ‘libs’ }

Open your app level “build.gradle” and write the following line 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')

ConsoliAds Mediation Dependencies

ConsoliAds mediation 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'

Initializing ConsoliAds Mediation

Before initializing ConsoliAds mediation, you need to make sure that the app is created on ConsoliAds dashboard (go to the section New App on portal). For initializing ConsoliAds mediation, you need to provide your app’s Product Name and Bundle Identifier as follows:

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

Please import the required packages for the above (HINT: click on above line then press (Alt + Enter) to make instant import).

Implementing Call Back Events

ConsoliAds also provides callbacks for events such as initialization, native ad loaded, etc. Your activity needs to implement the Interface of desired Ad Type and override your required callback methods to receive event callbacks and register callback events as follows:

public interface ConsoliAdsListener {
   void onConsoliAdsInitializationSuccess();
}

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

public interface ConsoliAdsInterstitialListener {
   void onInterstitialAdShownEvent();
   void onInterstitialAdClickedEvent();
   void onInterstitialAdClosedEvent();
   void onInterstitialAdFailedToShowEvent();
}

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

public interface ConsoliAdsRewardedListener {
   void onRewardedVideoAdLoadedEvent();
   void onRewardedVideoAdShownEvent();
   void onRewardedVideoAdCompletedEvent();
   void onRewardedVideoAdClickEvent();
   void onRewardedVideoAdFailToLoadEvent();
   void onRewardedVideoAdFailToShowEvent();
   void onRewardedVideoAdClosedEvent();
}
public abstract class ConsoliAdsNativeListener {
   public abstract void onNativeAdLoaded(MediatedNativeAd mediatedNativeAd);
   public void onNativeAdLoadFailed(){}
   public void onNativeAdClicked(){}
   public void onNativeAdShown(){}
   public void onNativeAdFailedToShow(){}
}

Now register the interface as follows:

ConsoliAds.Instance().setConsoliAdsListener(this);
ConsoliAds.Instance().setConsoliAdsRewardedListener(this);
ConsoliAds.Instance().setConsoliAdsInterstitialListener(this);

NOTE: For native banner and icon ads, listeners need to be set in every load/show call.

Initialize ConsoliAds mediation by:

public void initialize(final boolean userConsent , boolean isCCPA  , Boolean isPermissionRequired , Activity activity_context)

This call requires the following mandatory parameters:
User Consent
TRUE means user has provided the consent and will be shown personalized ads, whereas FALSE means user is not willing to see personalized ads. It is developer’s responsibility to get user consent and pass it above initialization call.

CCPA
California Consumer Privacy Act (CCPA) Flag

isPermissionRequired
If this bit will be true in that case run time location permission will be handled by ConsoliAds SDK.
  Activity
The prevailing Activity upon initialization.
Note: You have to make sure that you have integrated ConsoliAds SDK for ConsoliAds mediation to work properly otherwise your app will crash. See section: Add/Remove Networks->Integrating ConsoliAds SDK.

Interstitial Ad

Once initialized, ConsoliAds mediation is ready to show ads.

   Login to your ConsoliAds portal and go to Apps->Mediation-> (Your APP)->Placeholders & Ads
   Add Interstitial and Video Ad slot as shown in the below figure:

ConsoliAds Mediation Integration

   Make sure you have added Ad Network’s IDs in the portal for the corresponding app.
NOTE: Interstitial ads are not required to be requested and loaded separately.

Check the availability of Interstitial Ad using the following code:

ConsoliAds.Instance().IsInterstitialAvailable(int sceneIndex)

Now show Interstitial Ad simply by the following code:

ConsoliAds.Instance().ShowInterstitial(sceneIndex, Activity);

This call requires the following mandatory parameters:
   Scene Index
Integer value for the index of the scene for which you want to show the Interstitial ad. As an example you should call above method with ‘0’ as scene index if you want to invoke the ad on your first scene regardless of its name.
   Activity
The prevailing Activity when showing the interstitial ad.

Rewarded Video

   Login to your ConsoliAds portal and go to Apps->Mediation-> (Your APP)->Placeholders & Ads
   Add Rewarded Video Ad slot as shown in the below figure:

ConsoliAds Mediation Integration

Check the availability of Rewarded Video Ad using the following code:

ConsoliAds.Instance().IsRewardedVideoAvailable(int sceneIndex)

Load Rewarded Video

Rewarded Video Ads in ConsoliAds are loaded and shown separately. Load rewarded video ad as follows:

ConsoliAds.Instance().LoadRewarded(sceneIndex);

NOTE: It is highly recommended that you call LoadRewarded(sceneIndex) as early as possible to allow videos to be preloaded.
This call requires:
   Scene Index
Integer value for the index of the scene for which you want to load the Rewarded video ad. As an example you should call above method with ‘0’ as scene index if you want to invoke the ad on your first scene regardless of its name.

Show Rewarded Video

Show Rewarded ad by simply the following code:

ConsoliAds.Instance().ShowRewardedVideo(sceneIndex , Activity);

This call requires the following two parameters:
   Scene Index
Integer value for the index of the scene for which you want to show the Rewarded Video ad. As an example you should call above method with ‘0’ as scene index if you want to invoke the ad on your first scene regardless of its name.
   Activity
The prevailing Activity when showing the Rewarded Video ad.

NOTE: To check call back events, go to the section ‘Events Callbacks’ below.

Banner Ad

   Login to your ConsoliAds portal and go to Apps->Mediation-> (Your APP)->Placeholders & Ads
   Add Banner Ad slot as shown in the below figure:

ConsoliAds Mediation Integration

To show banner ad simply add the following code:

• Add the following xml in your required activity view:

<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"
  app:BannerSize="None" />

• Add the following line in your activity java file:

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

   BannerSize

This attribute contains banner size during banner loading in case none selected then size will be selected according to configuration of ConsoliAds portal.

   Custom Banner

For Admob user can show custom banner by setting property of mediated view before show call;

cAMediatedBannerView.setCustomBanner(int width , int height);

   Set Banner Listener

To receive callbacks for banner ad-type users need to set banner listeners on mediated view as follows:

cAMediatedBannerView.setBannerListener(ConsoliAdsBannerListener consoliAdsBannerListener);

Simply call the following code to show the banner:

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

To hide banner ad call the following code:

ConsoliAds.Instance().hideBanner(mediatedBannerView);

NOTE: ConsoliAds mediation supports one banner per activity.

Native Ad

ConsoliAds is the platform that helps you integrate Native Ads from different ad networks. It follows two approaches:

Single Native Integration – native ad for a single placeholder
Multiple Native Integration – native ad on a list activity

   Login to your ConsoliAds portal and go to Apps->Mediation-> (Your APP)->Placeholders & Ads
   Add Native Ad slot as shown in the below figure:

ConsoliAds Mediation Integration

Show Single Native Ad

Ad the following NativeView in your xml where you want to show ConsoliNative 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 NativeAd component in your Activity.

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

Now initialize the nativeAd components.

   title = findViewById(R.id.native_ad_title);
   subtitle = findViewById(R.id.native_ad_sub_title);
   body = findViewById(R.id.native_ad_body);
   sponsered = 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);
   findViewById(R.id.btn_show_ad).setOnClickListener(this);
   findViewById(R.id.btn_destroy_ad).setOnClickListener(this);
   findViewById(R.id.btn_go_back).setOnClickListener(this);

To show native ad use this code:

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(sponsered);
       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");
   }
});

To destroy Native ad use this code:

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

Load Multiple Native Ads In RecyclerView.

To load native ads in list write this code to add it to your data list:

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);
       sponsered = 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.adChoicesView);

Icon Ad

   Icon ad comes in different sizes (Small, Medium, Large)
   Login to your ConsoliAds portal and go to Apps->Mediation->(Your APP)->Placeholders & Ads
   Add icon ad slot

ConsoliAds Mediation Integration

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

• Add the following line in your activity java file:

IconAdView iconAdView = findViewById(R.id.consoli_icon_view);

• Load and show Icon ad:

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

• IconAd Listener:

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

• IconAnimationConstant

Icon ad can be shown with different type of animations.

Types of Animations supported by ConsoliAds during set Icon ad, user needs to pass enum on setIcon function.

1)  NONE

2) SHAKE

3) PULSE

Configure Server

Configure server is a mandatory step. First, check for java support by typing the following command in command prompt (or terminal in mac).

java -version

Find “libConfigureServer.jar” in ConsoliAds-mediation package and place it in root directory of the project. Now open command prompt (or terminal in mac) and go to root directory of the project to run the following command.

java -jar libConfigureServer.jar userSignature AppPackage platform

Example:

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

User Signature: A user identification code which is present in the personal info tab of your account.

ConsoliAds Mediation Integration

 

ConsoliAds Mediation Sample App

You can download sample ConsoliAds project here
And you can find ConsoliAds sample application using list view for showing native ads inside list view in Android. You can also find it in documentation.

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.
Note: According to the Admob documentation if you are using play services version greater than 17.x then you have to make sure that you add your Admob appID inside AndroidManifest.xml file. Otherwise, your app will crash.

Was this article helpful?
Dislike 1
Views: 1546