Custom AdNetwork Android

From POKKT DOCUMENTATION
Jump to: navigation, search

Custom Ad Network

This guide is intended for publishers looking to add support for Video, banner and interstitial within Pokkt mediation with an Ad Network not listed or supported by POKKT. Supported Ad Networks are listed in publisher dashboard.

Define a Custom AdNetwork

Following are the requirement to enable custom ad network in our Pokkt Dashboard:

  1. Add option to add a custom ad network in AdNetwork, navigate to mediation tab and click on "New Network".
    bordered
  2. To add Custom ad network need to provide below details:
    bordered
    • Classname: Enter the fully qualified name of the class that implements the custom adnetwork.
    • Extra Param: If you wish to pass an argument to your custom adnetwork, enter the appropriate string.
    • AdFormat: Ad Format like Video , Interstitial and Banner.
    • ECPM: Put your expected value of ECPM which will in turn rank this network in comparison to other configured networks.

Video & Interstitial Custom AdNetwork

  1. Create a class in your application which will implement Pokkt AdNetwork.
  2. This newly created class will override following methods and implement code to request ads.
    • void initNetwork(Context context, AdNetworkInfo adNetworkInfo)
    • AdNetworkInfo getAdNetworkInfo(); //return adNetworkInfo
    • void cacheAd(AdConfig adConfig, Callbacks.WithSuccessAndFailure<Double, String> callbacks);
    • void showAd(AdConfig adConfig, Callbacks.WithOnlyFailure<String> failureCallback);
    • void notifyCachingTimeout(AdConfig adConfig); //handle timeout callback from Pokkt SDK
    • double getAdVC(AdConfig adConfig); //return reward amount
    • boolean supportsAdConfig(AdConfig adConfig); //return true
    • boolean isInitialised(); // return true if initialized else false
    • boolean isPokktNetwork(); //return false
    • boolean verifyCampaignForAdConfig(AdConfig adConfig, boolean verifyCached); //return true
  3. You must notify Pokkt of Ad caching and Ad show callbacks by calling the below methods in your ad callback methods:
    • callback.OnSuccess for Ad caching success
    • callback.OnFailure for Ad caching fail
    • callback.OnFailure for Ad show fail
  4. You must notify Pokkt of Ad Display Lifecycle by calling the below methods in your ad callback methods:
    • AdManager.getInstance().adDisplayed(adConfig, adNetworkInfo);
    • AdManager.getInstance().adCompleted(adConfig, adNetworkInfo);
    • AdManager.getInstance().adClosed(adConfig, adNetworkInfo);
    • AdManager.getInstance().adGratified(adConfig, rewardItem.getAmount(), adNetworkInfo);

Example: To notify POKKT SDK from your delegate methods.

AdNetwork Class Implementation
@Override
public void cacheAd(AdConfig config, Callbacks.WithSuccessAndFailure<Double, String> cachingcallback) {
….
}
@Override
public void showAd(AdConfig config, Callbacks.WithOnlyFailure<String> failureCallback) {
….
}
@Override
public void onRewardedVideoAdLoaded() { //This is your network delegate method
….
cachingcallback.onSuccess(amount); // cachingcallback you will get in Pokkt cache method
}
@Override
public void onRewardedVideoAdFailedToLoad(int errorCode) { //This is your network delegate method
….
cachingcallback.onFailure("Ad Load Failed ! "); // cachingcallback you will get in Pokkt cache method
}
@Override
public void onRewardedVideoAdOpened() { //This is your network delegate method
….
AdManager.getInstance().adDisplayed(adConfig, adNetworkInfo); // This is Pokkt Method.
}

  1. Create a class in your application which will implement Pokkt AdNetwork .
  2. This newly created class will override following additional method and implement code to request banner ads.
    • void initNetwork(Context context, AdNetworkInfo adNetworkInfo)
    • AdNetworkInfo getAdNetworkInfo(); //return adNetworkInfo
    • void loadBannerAd(AdConfig adConfig, BannerUnit bannerUnit, Callbacks.WithSuccessAndFailure<AdCampaign, String> callbacks);
    • void destroyBannerAd(AdConfig adConfig);
    • void notifyCachingTimeout(AdConfig adConfig); //handle timeout callback from Pokkt SDK
    • double getAdVC(AdConfig adConfig); //return reward amount
    • boolean supportsAdConfig(AdConfig adConfig); //return true
    • boolean isInitialised(); // return true if initialized else false
    • boolean isPokktNetwork(); //return false
    • boolean verifyCampaignForAdConfig(AdConfig adConfig, boolean verifyCached); //return true
  3. You must notify Pokkt of Banner loading callbacks by calling the below methods in your ad callback methods:
    • callback.onSuccess(null);
    • callback.onFailure("Ad Load Failed " + errorCode);

Example: To notify POKKT SDK from your delegates methods.

@Override
public void loadBannerAd(AdConfig adConfig, BannerUnit bannerUnit, Callbacks.WithSuccessAndFailure<AdCampaign,
String> callbacks) {
//load your banner
}
@Override
public void destroyBannerAd(AdConfig adConfig) {
//destroy your banner
}
@Override
public void onAdLoaded() {
List<PokktBannerView> containerList = bannerUnit.getContainerList();
   if (containerList.size() > 0 ) {
      PokktBannerView container = containerList.get( 0 );
      if (container.getChildAt( 0 ) == null ) {
         container.addView(adView);
      } else {
         container.removeView(container.getChildAt( 0 ));
         container.addView(adView);
      }
         callback.onSuccess( null );
      }
   }
}