Get Started with Avocarrot

Overview

Examples

Android

Overview

- Native Ads

List/Feed

Custom

- Standard IAB Formats

Banner

Interstitial

Video

- Others

Troubleshooting

Admob Android Adapter

Mopub Android Adapter

DFP Android Adapter

iOS

Overview

- Native Ads

List/Feed

Custom

- Standard IAB Formats

Banner

Interstitial

Video

- Others

Troubleshooting

- Adapters

Admob iOS Adapter

Mopub iOS Adapter

DFP iOS Adapter

API Documentation

Reporting API

Help

Supported Networks & Ad Types

General

Earnings

Payments and Accounting

Integration

Reporting

Mediation Network Optimization

Legal and Privacy

Updates

SDK Change Log

Android Change Log

iOS Change Log

List/Feed

Updated 4 days ago ​by Derek Lim

Overview

This tutorial helps you setup stream ads and receive your first Avocarrot Native ad.

Steam Ads

Native List/feed Ads is an ad unit that encapsulates native ads into a scroll collection.

Prerequisites

Create a List or Feed ad unit from your app on Avocarrot Dashboard 

Requirements & Dependencies

  • Android 4.0 (API Version 14) and up
  • support-annotations, v26.1.0
  • support-v4, v26.1.0
  • Recommended Google Play Services v11.4.2

We strongly recommend compiling your app using Google Play services, in order to use the Android Advertising IDinstead of the Device ID, as required by Google. Failing to correctly use the Android Advertising ID may result in your submission to the Play Store being rejected.

You must have a different adUnitId for every ad space placement in your app. If you use the same ID for multiple placements or the IDs from the testing/demo examples, reporting errors will occur and there will be no payout. Please ask your account manager for further details.

Setup SDK

The SDK is available via:
1. jCenter AAR (Recommended) 
2. Zipped AAR 

  1. Add the following rows in your app module build.gradle file:
     
    repositories {
        maven { url 'https://maven.google.com'}
        maven { url "https://s3.amazonaws.com/avocarrot-android-builds/dist/" }
    }
  2. Add the following dependencies:


    dependencies {
      ...
      compile 'com.avocarrot.sdk:mediation-sdk-nativead:4.7.1'
      compile 'com.google.android.gms:play-services-ads:11.4.2'
     }
  3. Update AndroidManifest.xml
     
    <?xml version="1.0" encoding="utf-8"?>
    <manifest ... >
       <!-- Required -->
       <uses-permission android:name="android.permission.INTERNET" />
       <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
       <!-- Optional -->
       <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
       <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
       <application ...>
          <activity> ... </activity>
          <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
       </application>
    </manifest>
  1. Include the Local .aar Libraries

    You can find local aar files in our sample project under libraries here
    Save the aar files under app module’s libs folder (eg: <project>/<app>/libs) Then add the following rows in your app module build.gradle file:

    repositories {
      flatDir {
        dirs 'libs'
      }
    }
    
  2. To install SDK, include the following dependencies:

    dependencies {
        compile(name: 'core', version:'4.7.1', ext: 'aar')
        compile(name: 'mediation-sdk', version:'4.7.1', ext: 'aar')
        compile(name: 'mediation-sdk-native-assets', version:'4.7.1', ext: 'aar')
        compile(name: 'mediation-sdk-nativead', version:'4.7.1', ext: 'aar')
        compile 'com.google.android.gms:play-services-ads:11.4.2'
    }
    
  3. Then add following rows in your app module proguard-rules.pro file:

    -keep class com.avocarrot.** { *; }
    -dontwarn com.avocarrot.**
    // To ensure GAID can be extract from Google play services
    -keep class com.google.android.gms.ads.identifier.AdvertisingIdClient$Info { *; }     
    
  4. Update AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest ... >
       <!-- Required -->
       <uses-permission android:name="android.permission.INTERNET" />
       <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
       <!-- Optional -->
       <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
       <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
       <application ...>
          <activity> ... </activity>
          <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
       </application>
    </manifest>
  • ACCESS_COARSE_LOCATION (recommended) – Grants the SDK permission to access approximate location based on cell tower.
  • ACCESS_FINE_LOCATION (recommended) – Grants the SDK permission to access a more accurate location based on GPS.
    Although not technically required, the LOCATION permissions make it possible for the SDK to send location-based data to advertisers. Sending better location data generally leads to better monetization.
  • WRITE_EXTERNAL_STORAGE (optional) – Allows the SDK to cache all ad assets (creatives, custom frames, etc.) in external memory. This can maximize performance by ensuring immediate delivery of ads and minimize network traffic used by the SDK by keeping cached ad assets available even after the user closes the app.
  • READ_PHONE_STATE (recommended) – Allows the SDK to handle calls interrupting video playback during videos.
If you’re already integrated with a demand buyer,  It is not mandatory to remove all SDKs, but we would recommend it in order to ensure a seamless and coherent integration with Avocarrot.
 When using SDK as a library project, you shouldn’t need to worry about merging AndroidManifest.xml changes or Proguard settings. If you run into problems, make sure manifestmerger.enabled is set to true in project.properties Please see the Android documentation here.

Setup List/Feed Ads

  1. Configure In-Feed Viewer
    All SDK method calls should be done from the main thread (Main thread, UI thread).

    Add the following code to your activity:

    StreamAdBaseAdapter adAdapter = new StreamAdBaseAdapter.Builder()
      .setAdapter(new MainAdapter(this))
      .setAdUnitId("YOUR_NATIVE_AD_UNIT_ID")
      .setViewBuilder(ListNativeAdView.BUILDER)
      .setNativeAdCallback(streamNativeAdListener)
      .build(this);
    listView.setAdapter(adAdapter);
    adAdapter.loadAd();
    
    StreamAdRecyclerAdapter adAdapter = new StreamAdRecyclerAdapter.Builder()
      .setAdapter(new MainAdapter(this))
      .setAdUnitId("YOUR_NATIVE_AD_UNIT_ID")
      .setViewBuilder(FeedNativeAdView.BUILDER)
      .setEventCallback(streamNativeAdListener)
      .build(this);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(adAdapter);
    adAdapter.loadAd();
    
  2. Setting DynamicNativeAdView Template.

    DynamicNativeAdView Template is a template that uses the template set on the dashboard and you can do "on the fly" changes to your native ads by customising them on your dashboard.
    .setAdViewBuilder(DynamicNativeAdView.BUILDER);
    Advance Customisation is not applicable to DynamicNativeAdView
  3. The method below starts the loading ad process:

    adAdapter.loadAd();
    After calling the loadAd() method, the in-feed ad download starts. If you call loadAd() again before the native ad is fully served, new request processing is cancelled. Only one request will be processed.  When in-feed ad download is completed, it will show automatically. To learn about download completion, subscribe to ad events (see Ad Events Handling section).
  4. Activity lifecycle events handling

    destroy() methods should be called depending on the activity lifecycle events.
    Example:

    @Override
    protected void onPause() {
        super.onPause();
        adAdapter.onActivityPaused();
    }
    @Override
    protected void onResume() {
        super.onResume();
        adAdapter.onActivityResumed();
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        adAdapter.destroy();
    }
  5. Congratulations! Compile and Run your project . You can now customize your stream ads to match the look and feel of your app.

Mediation

If you want you can enable the mediation feature of Avocarrot and receive ads from 3rd party providers. You can follow the bellow steps to start mediating demand partners through Avocarrot.
If you’re already integrated with a demand buyer,  It is not mandatory to remove all SDKs, but we would recommend it in order to ensure a seamless and coherent integration with Avocarrot.

Add the following dependencies:

dependencies {
  ...
  // Base
  compile 'com.avocarrot.sdk:mediation-sdk-nativead:4.7.1'
  // Admob
  compile 'com.avocarrot.sdk:mediation-admob-nativead:4.7.1'
  // Applovin
  compile 'com.avocarrot.sdk:mediation-applovin-nativead:4.7.1'
  // Facebook
  compile 'com.avocarrot.sdk:mediation-facebook-nativead:4.7.1'
  // inLoco
  compile 'com.avocarrot.sdk:mediation-inlocomedia-nativead:4.7.1'
  // Mopub
  compile 'com.avocarrot.sdk:mediation-mopub-nativead:4.7.1'
  compile 'com.google.android.gms:play-services-ads:11.4.2'
 }

Include Mediation Local .aar Libraries

dependencies {
    ...
    // Base
    compile(name: 'core', version:'4.7.1', ext: 'aar')
    compile(name: 'mediation-sdk', version:'4.7.1', ext: 'aar')
    compile(name: 'mediation-sdk-native-assets', version:'4.7.1', ext: 'aar')
    compile(name: 'mediation-sdk-nativead', version:'4.7.1', ext: 'aar')
    // Admob
    compile(name: 'mediation-admob', version:'4.7.1', ext: 'aar')
    compile(name: 'mediation-admob-nativead', version:'4.7.1', ext: 'aar')
    // Applovin
    compile(name: 'mediation-applovin', version:'4.7.1', ext: 'aar')
    compile(name: 'mediation-applovin-nativead', version:'4.7.1', ext: 'aar')
    // Facebook
    compile(name: 'mediation-facebook', version:'4.7.1', ext: 'aar')
    compile(name: 'mediation-facebook-nativead', version:'4.7.1', ext: 'aar')
    // inLoco
    compile(name: 'mediation-inlocomedia', version:'4.7.1', ext: 'aar')
    compile(name: 'mediation-inlocomedia-nativead', version:'4.7.1', ext: 'aar')
    // Mopub
    compile(name: 'mediation-mopub', version:'4.7.1', ext: 'aar')
    compile(name: 'mediation-mopub-nativead', version:'4.7.1', ext: 'aar')
    compile 'com.google.android.gms:play-services-ads:11.4.2'
}

Advanced Customization

Go Live!

  1. Remove sandbox If you have received a sample ad then simply disable the Sandbox mode by including the following instruction in your code:
    Avocarrot.setTestMode(false);
    You should disable Sandbox mode ONLY when you are done with the integration and you are ready to publish your app. It is against Avocarrot's policies to use live ads during development, and doing so could get your Avocarrot account banned.
  2. Test your implementation on real devices with real ads before rolling it out to production. Please make sure that your test device has a sim-card and 'Ads Personalization' setting is turned on.
  3. Check whether Google Play Services are installed within your application.
  4. Publish your app. You are now ready to upload your app and start making money! If you have submitted your app in the Google Play/ Apple Store and you can see live ads, then you have nothing to worry about. Just wait until the impressions threshold has been reached and the app will be shown as live in your dashboard as well.
  5. Update payment details. Login to your account and update your payment settings.



Was this article useful?