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

Video

Updated 4 days ago ​by Derek Lim

Overview

This tutorial helps you setup video ads in your Android app and receive your first ad.

Prerequisites

Create a  Video ad unit for 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-video: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. Include the following:

    dependencies {
        compile(name: 'core', version:'4.7.1', ext: 'aar')
        compile(name: 'mediation-sdk', version:'4.7.1', ext: 'aar')
        compile(name: 'mediation-sdk-vast', version:'4.7.1', ext: 'aar')
        compile(name: 'mediation-sdk-interstitial', 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.
 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 Video Ads

All SDK method calls should be done from the main thread (Main thread, UI thread).
  1. Add the following code to your activity:


    VideoAd videoAd = VideoAdPool.load(this, "YOUR_VIDEO_AD_UNIT_ID", closeButtonEnabled, 
    videoAdListener);

    The Close button for video ads is supported for some networks. You can enable or disable it by changing closeButtonEnabledparameter.

    If you call reloadAd() before the video has started to show, new request processing is cancelled. Only one request will be processed.

    When the video download is completed, you can display it by calling the showAd() method.


    videoAd.showAd();
    To learn about download completion, subscribe to video banner events (see Ad Events Handling) or call method isReady().


        videoAd.isReady();

  2. Activity lifecycle events handling

    onDestroy() method should be called depending on the activity lifecycle events.

    Example:
    @Override
    protected void onDestroy() {
        super.onDestroy();
        videoAd.onActivityDestroyed();
    }
    
  3. Congratulations! Compile and Run your project. You can now further customize your Video ads.

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.

To add more demand sources and use the Avocarrot mediation service include this module on your SDK:

dependencies {
  ...
    // Base
    compile 'com.avocarrot.sdk:mediation-sdk-video:4.7.1'
    // NativeX
    compile 'com.avocarrot.sdk:mediation-nativex-video:4.7.1'
    // UnityAds
    compile 'com.avocarrot.sdk:mediation-unityads-video:4.7.1'
    // Vungle
    compile 'com.avocarrot.sdk:mediation-vungle-video:4.7.1'
    compile 'com.google.android.gms:play-services-ads:11.4.2'
 }

To add more demand sources and use the Avocarrot mediation service locally,  include this module on your SDK:

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-vast', version:'4.7.1', ext: 'aar')
    compile(name: 'mediation-sdk-video', version:'4.7.1', ext: 'aar')
    // NativeX
    compile(name: 'mediation-nativex', version:'4.7.1', ext: 'aar')
    compile(name: 'mediation-nativex-video', version:'4.7.1', ext: 'aar')
    // UnityAds
    compile(name: 'mediation-unityads', version:'4.7.1', ext: 'aar')
    compile(name: 'mediation-unityads-video', version:'4.7.1', ext: 'aar')
    // Vungle
    compile(name: 'mediation-vungle', version:'4.7.1', ext: 'aar')
    compile(name: 'mediation-vungle-video', 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. 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.
  3. Update payment details. Login to your account and update your payment settings.



Was this article useful?