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 months ago ​by Chris

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 adapter

ID of advertising space for testing (like for native ad): "7f900c7d-7ce3-4190-8e93-310053e70ca2"

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

Stream adapter is a smart technology to add native ads as items in your feeds based on UITableView or UICollectionView. Settings for stream adapter are returned from the server side and you can change it as you wish.

For the easiest integration you could use our customizable templates: ListFeedGrid and GridIcon based on AVONativeAdsTemplateType enum:

#import <AvocarrotNativeView/AvocarrotNativeView.h>
...
- (AVOTableViewStreamAdapter *_Nonnull)createStreamAdapterForTableView:(UITableView *_Nonnull)tableView
                                       parentViewController:(UIViewController *_Nonnull)viewController
                                       adUnitId:(NSString *_Nonnull)adUnitId
                                       templateType:(AVONativeAdsTemplateType)templateType
                                       templateCustomization:(void (^ _Nullable)(AVOTemplateCustomizationObject *_Nonnull templateCustomizationObject))templateCustomization;
- (AVOCollectionViewStreamAdapter *_Nonnull)createStreamAdapterForCollectionView:(UICollectionView *_Nonnull)collectionView
                                            parentViewController:(UIViewController *_Nonnull)viewController
                                            adUnitId:(NSString *_Nonnull)adUnitId
                                            templateType:(AVONativeAdsTemplateType)templateType
                                            delegate:(id <AVOCollectionViewStreamAdapterDelegate> _Nullable)delegate
                                            templateCustomization:(void (^ _Nullable)(AVOTemplateCustomizationObject *_Nonnull templateCustomizationObject))templateCustomization;   
import AvocarrotNativeView
...
func createStreamAdapter(for tableView: UITableView,
                         parentViewController viewController: UIViewController,
                         adUnitId: String,
                         templateType: AVONativeAdsTemplateType,
                         templateCustomization: ((AVOTemplateCustomizationObject) -> ())?) -> AVOTableViewStreamAdapter
func createStreamAdapter(for tableView: UITableView,
                         parentViewController viewController: UIViewController,
                         adUnitId: String,
                         adViewClassForRendering adViewClass: AnyClass) -> AVOTableViewStreamAdapter

List of available template customizations is here

If you want to use your own representation of a native ad, use these methods:

#import <AvocarrotNativeView/AvocarrotNativeView.h>
...
- (AVOTableViewStreamAdapter *_Nonnull)createStreamAdapterForTableView:(UITableView *_Nonnull)tableView
                                       parentViewController:(UIViewController *_Nonnull)viewController
                                       adUnitId:(NSString *_Nonnull)adUnitId
                                       adViewClassForRendering:(Class _Nonnull)adViewClass;
- (AVOCollectionViewStreamAdapter *_Nonnull)createStreamAdapterForCollectionView:(UICollectionView *_Nonnull)collectionView
                                            parentViewController:(UIViewController *_Nonnull)viewController
                                            adUnitId:(NSString *_Nonnull)adUnitId
                                            useDefaultGridMode:(BOOL)gridMode
                                            delegate:(id <AVOCollectionViewStreamAdapterDelegate> _Nullable)delegate
                                            adViewClassForRendering:(Class _Nonnull)adViewClass;            
import AvocarrotNativeView
...
func createStreamAdapter(for collectionView: UICollectionView,
                         parentViewController viewController: UIViewController,
                         adUnitId: String,
                         templateType: AVONativeAdsTemplateType,
                         delegate: AVOCollectionViewStreamAdapterDelegate?,
                         templateCustomization: ((AVOTemplateCustomizationObject) -> ())?) -> AVOCollectionViewStreamAdapter
func createStreamAdapter(for collectionView: UICollectionView,
                         parentViewController viewController: UIViewController,
                         adUnitId: String,
                         useDefaultGridMode gridMode: Bool,
                         delegate: AVOCollectionViewStreamAdapterDelegate?,
                         adViewClassForRendering adViewClass: AnyClass) -> AVOCollectionViewStreamAdapter

These methods work the same way as Native Ads. You have to use the instructions of this type of ad to set adViewClass field in methods, but you need to implement AVOCollectionViewStreamAdapterDelegate protocol or set estimatedItemSize property of your UICollectionViewFlowLayout.

For UITableView you have to do nothing in UITableViewDelegate and UITableViewDataSource methods to add ads in your feed, native ads will be added automatically.

For UICollectionView you have to write some code in UICollectionViewDelegate and UICollectionViewDataSource methods to add ads in your feed if you use custom collection view layout only, for UICollectionViewFlowLayout native ads will be added automatically:

#import <AvocarrotNativeView/AvocarrotNativeView.h>
...
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
    cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.adapter shouldDisplayAdAtIndexPath:indexPath]) {
        YourAdContainerCollectionViewCell *cell = [collectionView
            dequeueReusableCellWithReuseIdentifier:NSStringFromClass([YourAdContainerCollectionViewCell class])
                forIndexPath:indexPath];
        cell.layer.zPosition = 1000;
        return [self.adapter renderedAdCellAtIndexPath:indexPath inCell:cell];
        } else {
            //your feed cell
    }
    }
}
import AvocarrotNativeView
...
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    if (adapter?.shouldDisplayAd(at: indexPath) == true) {
        let cell: AVOAdContainerCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "AVOAdContainerCollectionViewCell", for: indexPath) as! AVOAdContainerCollectionViewCell
        cell.layer.zPosition = 100
        return (adapter?.renderedAdCell(at: indexPath, in: cell))!
    } else {
        //your feed cell
    }
}
Note for custom collection view layout: if you want to know the original index path of a cell in your feed without ads use this method (it may be important to load data from your data array):
- (NSIndexPath * _Nullable)originalIndexPath:(NSIndexPath * _Nonnull)indexPath;

If you want to use methods of UITableView and UICollectionView which work with NSIndexPath please use UITableView (AVOStreamAdapter) and UICollectionView (AVOStreamAdapter) categories (declared in AVOTableViewStreamAdapter.h and AVOCollectionViewStreamAdapter.h). There categories contain methods with avo_ prefix which return original indexPaths.

To process stream adapter events, you should implement blocks or subscribe to notifications. The following is available:

MethodDescriptionNSNotificationCenter key
- (instancetype _Nonnull)onAdsDidLoad:(nullable void (^)(void))blockCalled after ads for stream adapter have been loaded. After this event you can reload your UITableView/UICollectionView or could wait - ads will be added automatically during scrolling.kAVONotification_StreamAdapterAdsDidLoad
- (instancetype _Nonnull)onAdsFailed:(nullable void (^)(void))blockCalled after ads for stream adapter failed to load.kAVONotification_StreamAdapterAdsFailed
Note: Currently stream adapter doesn’t support dynamic modification of data source (insert, move, delete of items). This support will be added soon.
Note: Don’t forget to retain stream adapter by using your local variable

Native templates customization

To customize our templates use AVOTemplateCustomizationObject instance which is returned in each native request method.
List of available customizations:

Property of the AVOTemplateCustomizationObjectDescription
avoBackgroundColorColor of the ad cells
avoTitleFontFont of the title label in the ad cells
avoTitleColorText color of the title label in the ad cells
avoTitleLeftOffsetLeft offset for the title label in the ad cells
avoTitleRightOffsetRight offset for the title label in the ad cells
avoTitleTextStyleText style for the title label in the ad cells (could be uppercase, lowercase, capitalize and default)
avoDescriptionTextFontFont of the description label in the ad cells
avoDescriptionTextColorText color of the description label in the ad cells
avoDescriptionTextLeftOffsetLeft offset for the description label in the ad cells
avoDescriptionTextRightOffsetRight offset for the description label in the ad cells
avoCoverMediaLeftOffsetLeft offset for the ad main media view
avoCoverMediaRightOffsetRight offset for the ad main media view
avoCoverMediaTopOffsetTop offset for the ad main media view
avoCoverMediaBottomOffsetBottom offset for the ad main media view
avoCoverMediaCornerRadiusCorner radius of the ad main media layer
avoCoverMediaAutoPlayEnabledEnabling of video autoplay for main media view
avoCTAFontCall to action label font
avoCTAColorCall to action view background color
avoCTATextColorCall to action label text color
avoCTABorderColorCall to action layer border color
avoCTACornerRadiusCall to action layer corner radius
avoCTABorderWidthCall to action layer border width
avoCTARightOffsetRight offset for ad call to action view
avoCTABottomOffsetBottom offset for ad call to action view
avoCTATextStyleText style for the call to action label in the ad cells (could be uppercase, lowercase, capitalize and default)
avoSponsoredFontSponsored label font
avoSponsoredColorSponsored label text color
avoSponsoredTextStyleText style for the sponsored label in the ad cells (could be uppercase, lowercase, capitalize and default)
avoIconLeftOffsetLeft offset for ad app icon view
avoIconTopOffsetTop offset for ad app icon view
avoIconHeightHeight for ad app icon view
avoIconWidthWidth for ad app icon view
avoIconCornerRadiusCorner radius of ad app icon layer
avoIconContentModeContent mode of ad app icon view
avoMediaContentRatioContent ratio for the ad main media view (grid template)
avoTextContentRatioContent ratio for the ad description (grid template)
avoGridIconTemplateTitleIconBottomOffestBottom offset for the title label (grid icon template)
avoGridIconTemplateIconCTATopOffsetTop offset for the call to action label (grid icon template)

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