facebook

ConsoliAds Android SDK Integration (for v.13.x.x & above)

Getting Started

This documentation will help you integrate the ConsoliAds Ad network Unity plugin to get instant access  for optimized mobile ad analytics and earnings.

A nominal size increase of 1 MB is expected while integrating ConsoliAds AdNetwork.

Before you proceed to integrate, make sure you have:

Create an App

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

  1. From the left sidebar, 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

    Download the latest ConsoliAds Android SDK from: https://portal.consoliads.com/download/sdk

Setting Up Project Dependencies

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

implementation('com.consoliads:ca-analytics:v1.2.0')
implementation('com.consoliads:consoliadsplugin:13.1.9')
implementation('com.consoliads:loaderlibrary:v13.1.4')
implementation 'com.consoliads:consoliadsinapp:v1.1.4'


implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0' 
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.code.gson:gson:2.8.5'

If using Android Studio 2019 or below add the following lines in project level “build.gradle” under allprojects → repositories section else if you are using Android Studio 2020 add the following lines in settings.gradle under dependencyResolutionManagement → repositories section:

maven { url "https://maven.google.com" }

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

Ready to Code

SDK Initialization 

ConsoliAds SDK needs to be explicitly initialized, using the following code.

ConsoliadsSdk.getInstance().init(Activity activity, String userSignature, Boolean userConsent, boolean isDevMode , SDKPlatform sdkPlatform, new ConsoliadsSdkInitializationListener() {
@Override
public void onInitializationSuccess() { }
@Override
public void onInitializationError(String error) { }
});

activity: reference of the current Activity

userSignature: string to identify the user according to his role and rights provided on the ConsoliAds dashboard

    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 dashboard

    b.  Copy the required user signature for the above initialize argument

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 both. 

isDevMode: when true, it simulates the development environment and prevents developers from changing Live app settings. Complete app development should be done with ‘Dev Mode’ ON. When an app is ready to be published, ‘Dev Mode’ MUST BE turned OFF. (NOTE: Don’t forget to see ‘More About Dev Mode’ section before making the final build)

sdkPlatform: The platform on which your app is uploaded like SDKPlatform.Google, SDKPlatform.Samsung, SDKPlatform.Huawei etc.

NOTE: all initialize params cannot be modified once ConsoliAds is initialized

Interstitial/Video Ad

Load interstitial/Video Ad

Showing interstitial ads requires loading it beforehand. Use the following method to load an interstitial ad:

ConsoliadsSdk.getInstance().loadInterstitial();

OR

ConsoliadsSdk.getInstance().loadInterstitial(PlaceholderName placeholderName);

It is highly recommended to call LoadInterstitial() as early as possible to allow ads to be pre-loaded.

NOTE: calling LoadInterstitial multiple times does not results in multiple ad network requests

Check Interstitial/Video Ad Availability

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

ConsoliadsSdk.getInstance().isInterstitialAvailable();

OR

ConsoliadsSdk.getInstance().isInterstitialAvailable(PlaceholderName placeholderName);

PlaceholderName: enum of the placeholder (such as PlaceholderName.Default, PlaceholderName.Activity1) from the ‘Placeholders’ tab in your app details of the ConsoliAds dashboard. No placeholder value is required if you do not have your own placeholders added.

Return value (boolean):

  • True if the ad is available
  • False if the ad is not available

Show Interstitial/Video Ad

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

0ConsoliadsSdk.getInstance().showInterstitial(Activity aRef)

OR

ConsoliadsSdk.getInstance().showInterstitial(PlaceholderName placeholderName , Activity aRef)

Parameter details:

  • PlaceholderName:  enum of the placeholder (such as PlaceholderName.Default, PlaceholderName.Activity1) from the ‘Placeholders’ tab in your app details of the ConsoliAds dashboard. No placeholder value is required if you do not have your own placeholders added.
  • aRef: Reference of the Activity

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

Rewarded Video Ad

Load Rewarded Ad

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

ConsoliadsSdk.getInstance().loadRewardedVideoAd()

OR

ConsoliadsSdk.getInstance().loadRewardedVideoAd(PlaceholderName placeholderName);

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

Check the Availability of Rewarded Ad

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

ConsoliadsSdk.getInstance().isRewardedVideoAvailable();

OR

ConsoliadsSdk.getInstance().isRewardedVideoAvailable(PlaceholderName placeholderName);

PlaceholderName: enum of the placeholder (such as PlaceholderName.Default, PlaceholderName.MainMenu) from the ‘Placeholders’ tab in your app details of the ConsoliAds dashboard. No placeholder value is required if you do not have your own placeholders added.

Return value (boolean):

  • True if the ad is available
  • False if the ad is not available

Show Rewarded Ad

ConsoliadsSdk.getInstance().showRewardedVideoAd(Activity aRef);

OR

ConsoliadsSdk.getInstance().showRewardedVideoAd(PlaceholderName placeholderName, Activity aRef);

Parameter details:

  • PlaceholderName:  enum of the placeholder (such as PlaceholderName.Default, PlaceholderName.Activity1) from the ‘Placeholders’ tab in your app details of the ConsoliAds dashboard. No placeholder value is required if you do not have your own placeholders added.
  • 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. 

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

public void onRewardedVideoAdCompleted(PlaceholderName placeholderName, int reward) {

    // Write your code to reward your user here

}

Banner Ad

Show Banner Ad

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

< com.consoliads.sdk.bannerads.ConsoliadsSdkBannerView 
        android:layout_gravity="center_horizontal"
        android:id="@+id/consoli_banner_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

Get the banner view as follows:

ConsoliadsSdkBannerView consoliadsSdkBannerView; consoliadsSdkBannerView = findViewById(R.id.consoli_banner_view);

Now use the following code to display the banner:

ConsoliadsSdk.getInstance().showBanner(Activity activity, ConsoliadsSdkBannerSize bannerSize, consoliadsSdkBannerView, new ConsoliadsSdkBannerAdListener() {
@Override
public void onBannerAdLoaded(PlaceholderName placeholderName) {

     consoliadsSdkBannerView.setVisibility(View.VISIBLE);
}
@Override
public void onBannerAdFailedToLoad(PlaceholderName placeholderName, String reason) {
}
@Override
public void onBannerAdRefreshed(PlaceholderName placeholderName) {
}
@Override
public void onBannerAdClicked(PlaceholderName placeholderName, String ProductId) {
}
@Override
public void onBannerAdClosed(PlaceholderName placeholderName) {
}
});

OR

ConsoliadsSdk.getInstance().showBanner(PlaceholderName placeholderName,Activity activity, ConsoliadsSdkBannerSize bannerSize, consoliadsSdkBannerView, new ConsoliadsSdkBannerAdListener() {
@Override
public void onBannerAdLoaded(PlaceholderName placeholderName) {

      consoliadsSdkBannerView.setVisibility(View.VISIBLE);
}
@Override
public void onBannerAdFailedToLoad(PlaceholderName placeholderName, String reason) {
}
@Override
public void onBannerAdRefreshed(PlaceholderName placeholderName) {
}
@Override
public void onBannerAdClicked(PlaceholderName placeholderName, String ProductId) {
}
@Override
public void onBannerAdClosed(PlaceholderName placeholderName) {
}
});

Parameter details:

  • PlaceholderName:  enum of the placeholder (such as PlaceholderName.Default, PlaceholderName.Activity1) from the ‘Placeholders’ tab in your app details of the ConsoliAds dashboard. No placeholder value is required if you do not have your own placeholders added.
  • activity: Reference of the active Activity
  • bannerSize: Banner size you wish to use like ConsoliadsSdkBannerSize.Banner,ConsoliadsSdkBannerSize.LargeBanner,ConsoliadsSdkBannerSize.SmartBanner etc.

NOTE: ConsoliAds SDK supports only one banner per activity.

Hide Banner Ad

To hide Banner, use the following:

if (consoliadsSdkBannerView!= null) {
      consoliadsSdkBannerView.destroyBanner();
}

Native Ad

Show Native Ad

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

< LinearLayout
     android:layout_marginTop="16dp"
     android:orientation="vertical"
     android:layout_width="match_parent"
     android:layout_height="match_parent">

       < LinearLayout
           android:visibility="gone"
           android:id="@+id/native_container"
           android:orientation="vertical"
           android:background="#FFF"
           android:layout_margin="8dp"
           android:layout_width="match_parent"
           android:layout_height="wrap_content">

              < RelativeLayout
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content">

                   < TextView
                     android:id="@+id/ad"
                     android:textStyle="bold"
                     android:textColor="#FFF"
                     android:background="#FAA845"
                     android:textSize="10sp"
                     android:padding="2dp"
                     android:text="Ad"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content" />

                  < com.consoliads.sdk.PrivacyPolicy
                      android:id="@+id/native_privacy_policy"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_alignParentEnd="true"
                      android:layout_alignParentRight="true" />

              < /RelativeLayout>

              < LinearLayout
                 android:layout_margin="8dp"
                 android:orientation="vertical"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content">

                  < TextView
                     android:textSize="16sp"
                     android:id="@+id/tv_ad_title"
                     android:textStyle="bold"
                     android:textColor="@android:color/holo_blue_dark"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content" />

                  < ImageView
                     android:id="@+id/iv_ad_image"
                     android:scaleType="fitXY"
                     android:layout_marginLeft="32dp"
                     android:layout_marginRight="32dp"
                     android:layout_marginTop="16dp"
                     android:layout_marginBottom="16dp"
                     android:layout_width="match_parent"
                     android:layout_height="150dp" />

                  < RelativeLayout
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content">

                      < TextView
                         android:id="@+id/tv_ad_sub_title"
                         android:textStyle="bold"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content" />

                      < TextView
                         android:layout_marginRight="8dp"
                         android:layout_alignParentLeft="true"
                         android:layout_alignLeft="@+id/native_action_button"
                         android:layout_below="@id/tv_ad_sub_title"
                         android:id="@+id/tv_ad_description"
                         android:textSize="10sp"
                         android:textStyle="bold"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content" />

                      < com.consoliads.sdk.nativeads.ActionButton
                         android:layout_centerVertical="true"
                         android:id="@+id/native_action_button"
                         android:layout_alignParentRight="true"
                         android:layout_alignParentEnd="true"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content">

                      < /com.consoliads.sdk.nativeads.ActionButton>

                  < /RelativeLayout>

              < /LinearLayout>

       < /LinearLayout>

< /LinearLayout>

Declare native ad components in your activity:

ConsoliadsSdkNativeAd consoliadsSdkNativeAd;
LinearLayout nativeAdContainer;
PrivacyPolicy privacyPolicy;
TextView adTitle;
TextView adSubTitle;
TextView adDescription;
ImageView adImage;
ActionButton actionButton;

Now initialize the declared ad components:

nativeAdContainer = (LinearLayout) findViewById(R.id.native_container);
adTitle = (TextView) findViewById(R.id.tv_ad_title);
adSubTitle = (TextView) findViewById(R.id.tv_ad_sub_title);
adDescription = (TextView) findViewById(R.id.tv_ad_description);
adImage = (ImageView) findViewById(R.id.iv_ad_image);
actionButton = (ActionButton) findViewById(R.id.native_action_button);
privacyPolicy = (PrivacyPolicy) findViewById(R.id.native_privacy_policy);

Show native ad using:

ConsoliadsSdk.getInstance().showNative( new ConsoliadsSdkNativeAdListener() {
@Override
public void onAdLoaded(ConsoliadsSdkNativeAd nativeAd) {
      if (nativeAd != null){
            consoliadsSdkNativeAd = nativeAd;
            nativeAdContainer.setVisibility(View.VISIBLE);
            adTitle.setText(nativeAd.getAdTitle());
            adSubTitle.setText(nativeAd.getAdSubTitle());
            adDescription.setText(nativeAd.getAdDescription());
            nativeAd.setAdPrivacyPolicy(privacyPolicy);
            nativeAd.loadAdImage(adImage);
            nativeAd.registerClickToAction(actionButton);
      }
}
@Override
public void onAdFailedToLoad(PlaceholderName placeholderName, String error) {
}
@Override
public void onAdClicked(String ProductId) {
}
@Override
public void onLoggingImpression() {
}
@Override
public void onAdClosed() {
}
});

OR

ConsoliadsSdk.getInstance().showNative(PlaceholderName placeholderName, new 
ConsoliadsSdkNativeAdListener() {
@Override
public void onAdLoaded(ConsoliadsSdkNativeAd nativeAd) {
      if (nativeAd != null){
            consoliadsSdkNativeAd = nativeAd;
            nativeAdContainer.setVisibility(View.VISIBLE);
            adTitle.setText(nativeAd.getAdTitle());
            adSubTitle.setText(nativeAd.getAdSubTitle());
            adDescription.setText(nativeAd.getAdDescription());
            nativeAd.setAdPrivacyPolicy(privacyPolicy);
            nativeAd.loadAdImage(adImage);
            nativeAd.registerClickToAction(actionButton);
      }
}
@Override
public void onAdFailedToLoad(PlaceholderName placeholderName, String error) {
}
@Override
public void onAdClicked(String ProductId) {
}
@Override
public void onLoggingImpression() {
}
@Override
public void onAdClosed() {
}
});

Parameter details:

  • PlaceholderName:  enum of the placeholder (such as PlaceholderName.Default, PlaceholderName.Activity1) from the ‘Placeholders’ tab in your app details of the ConsoliAds dashboard. No placeholder value is required if you do not have your own placeholders added.

Hide Native Ad

You can destroy native ad using:

if (consoliadsSdkNativeAd!= null)
{
    consoliadsSdkNativeAd.hideNativeAd();
}

Icon Ad

Show Icon Ad

Add the following xml in your required activity view:

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

Load and show icon ad using:

IconAdView iconAdView;
iconAdView = findViewById(R.id.consoli_icon_view);
ConsoliadsSdk.getInstance().showIconAd(Activity activity,IconAdView iconAdView,new ConsoliadsSdkIconAdListener() {
      @Override
      public void onIconAdShown(PlaceholderName placeholderName) {
      }
      @Override
      public void onIconAdFailedToShow(PlaceholderName placeholderName, String s) {
      }
      @Override
      public void onIconAdClosed(PlaceholderName placeholderName) {
      }
      @Override
      public void onIconAdClicked(PlaceholderName placeholderName, String s) {
      }
      @Override
      public void onIconAdRefreshed(PlaceholderName placeholderName) {
      }
} ,ConsoliadsSdkIconSize iconSize);

OR

ConsoliadsSdk.getInstance().showIconAd(PlaceholderName placeholderName,Activity activity,IconAdView iconAdView,new ConsoliadsSdkIconAdListener() {
      @Override
      public void onIconAdShown(PlaceholderName placeholderName) {
      }
      @Override
      public void onIconAdFailedToShow(PlaceholderName placeholderName,String s) {
      }
      @Override
      public void onIconAdClosed(PlaceholderName placeholderName) {
      }
      @Override
      public void onIconAdClicked(PlaceholderName placeholderName,String s) {
      }
      @Override
      public void onIconAdRefreshed(PlaceholderName placeholderName) {
      }
} ,ConsoliadsSdkIconSize iconSize);

Parameter details:

  • PlaceholderName:  enum of the placeholder (such as PlaceholderName.Default, PlaceholderName.Activity1) from the ‘Placeholders’ tab in your app details of the ConsoliAds dashboard. No placeholder value is required if you do not have your own placeholders added.
  • activity: Reference of the active Activity

Hide Icon Ad

You can hide icon ad using following code:

if (iconAdView != null) {
    iconAdView.hideAd();
    iconAdView.setVisibility(View.GONE);
}

More About ‘Dev Mode’

  • Please note that the ‘Dev Mode’ has its own following settings to modify your app under development before impacting the LIVE app:
    • Test Mode
    • Hide All Ads
    • Ad Showing Mechanism
  • If you make your build with ‘Dev Mode’ enabled, the ad configurations from ‘Dev. Placeholder and Ads‘ tab on the dashboard would be used.
  • If you make your build with ‘Dev Mode’ disabled, the ad configurations from ‘Live Placeholder and Ads‘ tab on the dashboard would be used.

Applying Dev Settings to Live

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

Click ‘Apply to Live’ to apply these configurations to your live app.

NOTE: if the configurations are mistakenly applied to LIVE, you can undo by modifying the DEV configurations and applying again.

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 Filters

Apply all ad filters 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.

For Advance Development

More Interface Listeners

Interstitial Listeners

Implement the interface ConsoliadsSdkInterstitialAdListener in your class.

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

ConsoliadsSdk.getInstance().setSdkInterstitialAdListener(this);
public interface ConsoliadsSdkInterstitialAdListener {
    void onInterstitialAdLoaded(PlaceholderName placeholderName);
    void onInterstitialAdFailedToLoad(PlaceholderName placeholderName , String reason);
    void onInterstitialAdClosed(PlaceholderName placeholderName);
    void onInterstitialAdClicked(PlaceholderName placeholderName, String ProductId);
    void onInterstitialAdShown(PlaceholderName placeholderName);
    void onInterstitialAdFailedToShow(PlaceholderName placeholderName);
}

Rewarded Video Listeners

Implement the interface ConsoliadsSdkRewardedAdListener in your class.

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

ConsoliadsSdk.getInstance().setSdkRewardedAdListener(this);
public interface ConsoliAdsRewardedListener {
    void onRewardedVideoAdLoaded(PlaceholderName placeholderName);
    void onRewardedVideoAdFailedToLoad(PlaceholderName placeholderName, String reason);
    void onRewardedVideoAdShown(PlaceholderName placeholderName);
    void onRewardedVideoAdFailedToShow(PlaceholderName placeholderName, String reason);
    void onRewardedVideoAdCompleted(PlaceholderName placeholderName,int reward);
    void onRewardedVideoAdClosed(PlaceholderName placeholderName);
    void onRewardedVideoAdClicked(PlaceholderName placeholderName, String ProductId);
}

More Help Sources of Integration

ConsoliAds Sample Project:

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

Youtube Videos:

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

ConsoliAds GitHub forum:

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

Was this article helpful?
Dislike 0