Native Ads Integration For Android English - Hiroaki-Shinoda/Geniee-Android-SDK GitHub Wiki

Native Ads Integration For Android

Native Ads are a component-based ad format that allow publisher to display the customized ads on the application, how layouts headlines and call to action button. By choosing colors, image size and fonts etc for your application, you are able to display natural, well matched advertisement that can give better user experience. Ad impressions, ad clicks tracking, processing Advertising SDK.

Preparation

Preparation Integration for Native Ads, please look at [Install Android SDK] below.
You must install Geniee SDK to project.
Install Android SDK

Class and Interface

Android native ad delivery, use the following class.

  • GNNativeAdRequest : Class to Request Native Ad with asynchronous
  • GNNativeAd : Class to provide information of Native Ad
  • GNNativeAdRequestListener Interface to receive loading event of Native Ad

Initialize SDK

Initialize SDK with the global App.

  1. Initialize SDK with the global
    (Ex:Initialization when Application is started.)
    import android.app.Application;
    import jp.co.geniee.gnadsdk.common.GNAdSDK;
    
    public class MyApplication extends Application {
        GNAdSDK gnadsdk = null;
        @Override
        public void onCreate() {
            GNAdSDK gnadsdk = GNAdSDK.getInstatnce(getApplicationContext());
            gnadsdk.init();
        }
    }
    

Set Up Native Ads

  1. Add SDK to your project. Install Android SDK

  2. Import GNNativeAd

    import jp.co.geniee.sdk.ads.nativead.GNNativeAd;
    import jp.co.geniee.sdk.ads.nativead.GNNativeAdRequest;
    import jp.co.geniee.sdk.ads.nativead.GNNativeAdRequestListener;
    import jp.co.geniee.gnadsdk.common.GNAdLogger;
    
  3. Implement GNNativeAdRequestListener interface

    public class NativeAdSampleActivity extends ListActivity implements GNNativeAdRequestListener {
    }
    
  4. Declare GNNativeAdRequest variable

    GNNativeAdRequest nativeAdRequest;
    
  5. Initialize GNNativeAdRequest instance

  • Initialize API
    public GNNativeAdRequest(Context context, String zoneids)
    
  • Example for using Initialize API
    nativeAdRequest = new GNNativeAdRequest(this, "YOUR_SSP_APP_ID");
    

thisParameter sets Context of App.
YOUR_SSP_APP_ID sets managementID of AdZones in Geniee.

  1. Set Implementation class of GNNativeAdRequestListener interface

Native ad load event, you will be notified by the implementation class via the interface.
Set the implementation variables of GNNativeAdRequestListener interface.
java nativeAdRequest.setAdListener(this);

  1. Load NativeAds
    nativeAdRequest.loadAds(this);
    

this parameter sets Context of App.

  1. Implement GNNativeAdRequestListener interface
    Implement CallBack function of GNNativeAdRequestListener to receive the result of native ad loading event.
    public abstract void onNativeAdsLoaded(GNNativeAd[] nativeAds);
    public abstract void onNativeAdsFailedToLoad();
    public abstract boolean onShouldStartInternalBrowserWithClick(String landingURL);
    

Received native ads GNNativeAd is return by an array of nativeAds arguments.
Distribution processing of multiple native advertising, done in GNNativeAd of zoneID information.
The number of elements in the array nativeAds :
- one : Select one APP_ID when Initialize GNNativeAdRequest
- Multiple : Select Multiple APP_ID when Initialize GNNativeAdRequest

  • Example for implement ListActivity:
    import jp.co.geniee.sdk.ads.nativead.GNNativeAd;
    import jp.co.geniee.sdk.ads.nativead.GNNativeAdRequest;
    import jp.co.geniee.sdk.ads.nativead.GNNativeAdRequestListener;
    import jp.co.geniee.gnadsdk.common.GNAdLogger;
    
    public class NativeAdSampleActivity extends ListActivity implements GNNativeAdRequestListener {
    GNNativeAdRequest nativeAdRequest;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        nativeAdRequest = new GNNativeAdRequest(this, "YOUR_SSP_APP_ID");
        nativeAdRequest.setAdListener(this);
        //nativeAdRequest.setGeoLocationEnable(true);
        nativeAdRequest.loadAds(this);
    }
    
    @Override
    public void onNativeAdsLoaded(GNNativeAd[] nativeAds) {
        for(int i=0; i<nativeAds.length; i++) {
            queueAds.enqueue(nativeAds[i]);
        }
    }
    
    @Override
    public void onNativeAdsFailedToLoad() {
        Log.w("NativeAdSampleActivity","onNativeAdsFailedToLoad");
    }
    
    @Override
    public boolean onShouldStartInternalBrowserWithClick(String landingURL) {
        Log.i("NativeAdSampleActivity","onShouldStartInternalBrowserWithClick : " + landingURL);
        return false;
    }
    

Get Ads in multiple AdZones at the same time

  • In order to get the multiple AdZones of advertising at the same time,
    you need to initialize the instance by specifying APPID of multiple AdZones.

  • It is possible to get maximum 10 Ads at the same time.

  • Separate multiple APP_ID by comma, Do not put SPACE between APP_ID.

    nativeAdRequest = new GNNativeAdRequest(this, "APPID1,APPID2,APPID3,...,APPID10");
    

Rendering Native Ad

You need to render Native Ad based on information of received data.

  • Type of information data, refer definition of GNNativeAd class

  • If the information data (String type) is not set, it will be ""

  • If the information data (int, double type) is not set, it will be 0

    Information Name Type Content of Information
    zoneID String ID for AdZone in Geniee
    advertiser String Name of client
    title String Title of feed advertisement
    description String description of advertisment
    cta String text for "call to action"
    icon_aspectRatio double Aspect ratio of icon image
    icon_url String URL of icon image
    icon_height int heigh of icon image
    icon_width int width of icon image
    screenshots_aspectRatio double aspect ratio of screenshot
    screenshots_url String URL of screenshot image
    screenshots_height int heigh of screenshot image
    screenshots_width int width of screenshot image
    app_appName String Name of App
    app_appid String App ID(iOS:number、Android:package)
    app_rating double Evaluation of App
    app_storeURL String URL of App store
    app_targetAge String Target age of App
  • Example for Implementation of ListActivity:
    When Setting is information of native ad in dashboard below :

    • title
    • description
    • icon image URL
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
    
        Object cell = getItem(position);
        //SDK: Rendering NativeAd content
        if (cell instanceof GNNativeAd) {
            holder.textView.setText(((GNNativeAd)cell).title);
            holder.imageView.setTag(((GNNativeAd)cell).icon_url);
            new ImageGetTask(holder.imageView, ((GNNativeAd)cell).icon_url).execute();
            //SDK: Report impression
            ((GNNativeAd)cell).onTrackingImpression();
        } else {
            // Cell display processing other than GNNativeAd
        }
        return convertView;
    }
    
  • Example for Implementation of ListActivity Image

    image

Native ad impressions report

  • When the Native Ad is rendered, you can extract the ad impression report.

  • For impressions native ads that has been previously reported, can not be reported again.

  • You need to request Native Ad again to display new advertisement.

    nativeAd.onTrackingImpression();
    

Native ad click tracking

  • When Native ad is clicked, it will lead to ad landing page in external browser.

    nativeAd.onTrackingClick();
    
  • Example for Implementation of ListActivity:

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        ListView listView = (ListView)parent;
        Object cell = listView.getItemAtPosition(position);
        if (cell instanceof GNNativeAd) {
            //SDK: Report click
            ((GNNativeAd)cell).onTrackingClick();
        }
    }
    

Landing page screen transition control when it is clicked

Landing page of Ads starts on an external browser by default,
Implement CallBack function of GNNativeAdRequestListener,
With URL of landing page it is possible to start in-app browser.
In addition, by the return value of function, to control the start-up of an external browser.
If it returns true, you will need to request AppSide landingURL.

  • false : Start the false external browser.

  • true : Do not start the true external browser.

    public boolean onShouldStartInternalBrowserWithClick(String landingURL)
    

Re-acquisition of native advertising

  • To view the new ads, you will need to re-acquire Native advertising.

    nativeAdRequest.loadAds(this);