Get Started with Avocarrot

Overview

Examples

Android

Overview

- Avocarrot Exchange SDK

Setup Exchange SDK

Stream

Native Assets

Exchange Troubleshooting

- Avocarrot Mediation SDK

Setup Mediation

Stream Ads Mediation

Native ads Mediation

Native Assets Mediation

Banner Mediation

Interstitial Mediation

Video Mediation

Supported Networks & Ad Types

Mediation Troubleshooting

iOS

Overview

- Avocarrot Exchange SDK

Setup SDK

Stream

Native Assets

Exchange Troubleshooting

- Avocarrot Mediation

Getting Started With Mediation

Stream Ads Mediation

Native Ads Mediation

Banner Ads Mediation

Interstitial Ads Mediation

Video Ads Mediation

Supported Networks & Ad Types

Mediation Troubleshooting

API Documentation

Reporting API

Help

FAQ

Updates

SDK Change Log

Android Change Log

iOS Change Log

Stream Ads Mediation

Updated 2 days ago ​by Derek Lim

Overview

This tutorial helps you setup stream ads mediation.

Stream Ads is an ad unit that encapsulates native ads into a scroll collection.

Prerequisites

You need an Avocarrot account to complete the tutorial. Create an account
You need to setup the Mediation SDK. Setup Mediation SDK

Setup Stream Ads

  1. Configure In-Feed Viewer
    All SDK method calls should be done from the main thread (Main thread, UI thread).
    ID of advertising space for testing (like for native ad): "e5cc8e6d-d674-402a-aeca-eda7856bd7af"


    The ID above is meant for testing purpose only, please replace it with the Ad unit Id of your placement on dashboard.

    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)
      .setEventCallback(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();
    
    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). 

                      

    Activity lifecycle events handling

    onPause()onResume() and onDestroy() 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();
    }
  2. Congratulations! Compile and Run your project . You can now customize your stream ads to match the look and feel of your app.

Advanced Customization

Customize Native Template 

With a native template, you can customize the following elements:

  1. Title
    • Text font (DEFAULT, DEFAULT_BOLD, MONOSPACE, SANS_SERIF, SERIF)
    • Text size
    • Text color
    • Max Ems (25 by default)
  2. Icon
    • Dimensions(width, height)
    • Margins (left, right)
  3. Star rating
    • Star size (SMALL, MEDIUM, LARGE)
  4. Attribution label
    • Default text
    • Text font (DEFAULT, DEFAULT_BOLD, MONOSPACE, SANS_SERIF, SERIF)
    • Text size
    • Text color
  5. Cover image
    • Background color
    • Background resource
    • Margins (left, right, bottom, top)
    • Alignment (undefine, top, bottom, left, right, center, center_vertical, center_horizontal)
  6. Description
    • Text font (DEFAULT, DEFAULT_BOLD, MONOSPACE, SANS_SERIF, SERIF)
    • Text size
    • Text color
    • Margins (left, right)
    • Max Ems (100 by default)
  7. Call To Action button
    • Default text
    • Text font (DEFAULT, DEFAULT_BOLD, MONOSPACE, SANS_SERIF, SERIF)
    • Text size
    • Text color
    • Max Ems (25 by default)
    • Background color
    • Background resource
    • Margins (left, right)

In order to customize these elements, you will need to build an attributes object and provide the following in the creation of the NativeAd:

NativeAdView.Attributes adViewAttributes = new NativeAdView.Attributes(this)
    .setTitle(new NativeAdView.Attributes.Setter<nativeadview.attributes.title>() {
        @Override
            public NativeAdView.Attributes.Title set(@NonNull NativeAdView.Attributes.Title builder) {
                return builder
                        .setTypeface(Typeface.MONOSPACE)
                        .setTextColor(Color.RED)
                        .setMaxLengthEms(20);
            }
    })
    .setStarRating(new NativeAdView.Attributes.Setter<nativeadview.attributes.starrating>() {
        @Override
        public NativeAdView.Attributes.StarRating set(@NonNull NativeAdView.Attributes.StarRating builder) {
            return builder.setStarRatingStyle(NativeAdView.Attributes.StarRating.Style.MEDIUM);
        }
    })
    .setAdAttribution(new NativeAdView.Attributes.Setter<nativeadview.attributes.adattribution>() {
        @Override
        public NativeAdView.Attributes.AdAttribution set(@NonNull final NativeAdView.Attributes.AdAttribution adAttribution) {
            return adAttribution.setDefaultText(R.string.sponsored);
        }
    })
NativeAd nativeAd = NativeAdPool.load(context, YOUR_NATIVE_AD_UNIT_ID, ListNativeAdView.BUILDER, adViewAttributes, nativeAdListener);</nativeadview.attributes.adattribution></nativeadview.attributes.starrating></nativeadview.attributes.title>


Also, you can set the style of your NativeAdView layout by using following attributes:

Attribute NameFormatDescription
Title  
ampiriTitleTextFontDEFAULT, DEFAULT_BOLD, MONOSPACE, SANS_SERIF, SERIFFont of the Title text
ampiriTitleTextSizereference,dimensionSize of the Title text
ampiriTitleTextColorreference,colorColor of the Title text
ampiriTitleTextMaxLengthEmsintegerMaximum Ems of the Title text
Icon  
ampiriIconWidthreference,dimensionIcon view width
ampiriIconHeightreference,dimensionIcon view height
ampiriIconMarginLeftreference,dimensionIcon view left margin
ampiriIconMarginRightreference,dimensionIcon view right margin
Star Rating  
ampiriStarRatingSizeSMALL, MEDIUM, LARGESize of the rating bar stars. SMALL – 10dp for height and width, MEDIUM – 16dp, LARGE – 22dp
Ad Attribution  
ampiriAdAttributionTextFontDEFAULT, DEFAULT_BOLD, MONOSPACE, SANS_SERIF, SERIFFont of the Attribution label text
ampiriAdAttributionTextSizereference,dimensionSize of the Ad Attribution text
ampiriAdAttributionTextColorreference,colorColor of the Ad Attribution text
ampiriAdAttributionDefaultTextreference,stringDefault Ad Attribution text
Cover Image  
ampiriCoverImageBackgroundColorreference,colorCover Image background color
ampiriCoverImageBackgroundResourcereferenceCover Image background resource
ampiriCoverImageMarginLeftreference,dimensionCover Image left margin
ampiriCoverImageMarginRightreference,dimensionCover Image right margin
ampiriCoverImageMarginTopreference,dimensionCover Image top margin
ampiriCoverImageMarginBottomreference,dimensionCover Image bottom margin
ampiriCoverImageAlignmentundefine, top, bottom, left, right, center, center_vertical, center_horizontalCover Image alignment within the NativeAd view
Description  
ampiriDescriptionTextFontDEFAULT, DEFAULT_BOLD, MONOSPACE, SANS_SERIF, SERIFFont of the Description text
ampiriDescriptionTextSizereference,dimensionSize of the Description text
ampiriDescriptionTextColorreference,colorColor of the Description text
ampiriTitleTextMaxLengthEmsintegerMaximum Ems of the Description text
ampiriDescriptionMarginLeftreference,dimensionDescription view left margin
ampiriDescriptionMarginRightreference,dimensionDescription view right margin
Call To Action  
ampiriCallToActionBackgroundColorreference,colorColor of the Call To Action button
ampiriCallToActionTextFontDEFAULT, DEFAULT_BOLD, MONOSPACE, SANS_SERIF, SERIFFont of the Description text
ampiriCallToActionTextSizereference,dimensionSize of the Call To Action button text
ampiriCallToActionTextColorreference,colorColor of the Call To Action button text
ampiriCallToActionMarginLeftreference,dimensionCall To Action button view left margin
ampiriCallToActionMarginRightreference,dimensionCall To Action button view right margin
ampiriCallToActionMarginTopreference,dimensionCall To Action button view top margin
ampiriCallToActionMarginBottomreference,dimensionCall To Action button view bottom margin
ampiriCallToActionDefaultTextreference,stringDefault Call To Action text


You can set this attributes in your custom NativeAdView layout

<com.ampiri.sdk.banner.NativeAdView android:id="@+id/native_ad"
    app:ampiriTitleTextFont="MONOSPACE"
    app:ampiriIconWidth="42dp"
    app:ampiriIconHeight="42dp"
    app:ampiriCallToActionTextColor="@android:color/lighter_gray"
 ...>

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:
    AvocarrotSDK.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 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?