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

Native Ads Mediation

Updated 2 months ago ​by Chris

Overview  

This tutorial helps you setup native ads mediation.

A native ad is a raw representation of an ad with a wrapping UI. The UI can use pre-defined templates from SDK (ListFeedGrid and GridIcon based on AVONativeAdsTemplateType enum.) or defined in the Interface Builder (creating .xib file) or manual creation of UI controls in code by the publisher.  

Prerequisites

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

Setup Native ads

ID of advertising space for testing (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

Use this method to represent native ads by our templates:

- (void)loadNativeAdWithAdUnitId:(NSString *_Nonnull)adUnitId
            parentViewController:(UIViewController *_Nonnull)viewController
                    templateType:(AVONativeAdsTemplateType)templateType
                         success:(void (^ _Nullable)(UIView *_Nonnull adNativeViewContainer))success
                         failure:(void (^ _Nullable)(AVOError *_Nonnull error))failure
           templateCustomization:(void (^ _Nullable)(AVOTemplateCustomizationObject *_Nonnull templateCustomizationObject))templateCustomization;
func loadNativeAd(withAdUnitId adUnitId: String,
                  parentViewController viewController: UIViewController,
                  templateType: AVONativeAdsTemplateType,
                  success: ((UIView) -> ())?,
                  failure: ((AVOError) -> ())?,
                  templateCustomization: ((AVOTemplateCustomizationObject) -> ())?)

List of available template customizations is here

For example:

#import <AvocarrotNativeView/AvocarrotNativeView.h>
...
__weak typeof(self) weakSelf = self;
[AvocarrotSDK.sharedSDK loadNativeAdWithAdUnitId:@"7f900c7d-7ce3-4190-8e93-310053e70ca2"
                             parentViewController:self
                                     templateType:AVONativeAdsTemplateTypeList
                                          success:^(UIView * _Nonnull adNativeViewContainer) {
                                              [weakSelf.view addSubview:adNativeViewContainer];
                                          } failure:nil
                            templateCustomization:nil];
import AvocarrotNativeView
...
AvocarrotSDK.shared.loadNativeAd(withAdUnitId: "7f900c7d-7ce3-4190-8e93-310053e70ca2",
                                      parentViewController: self,
                                      templateType: .list,
                                      success: { [unowned self] (view) in
                                        self.view.addSubview(view)
            }, failure: nil,
               templateCustomization: nil)

The custom layout for a native ad is configured by developers with the help of the Interface Builder (creating .xib file) or manual creation of UI controls in code. Use the following methods in your UIViewController subclass:

- (void)loadNativeAdWithAdUnitId:(NSString *_Nonnull)adUnitId
        parentViewController:(UIViewController *_Nonnull)viewController
        adViewClassForRendering:(Class _Nonnull)adViewClass
        success:(void (^ _Nullable)(UIView *_Nonnull adNativeViewContainer))success
        failure:(void (^ _Nullable)(AVOError *_Nonnull error))failure;
func loadNativeAd(withAdUnitId adUnitId: String,
                      parentViewController viewController: UIViewController,
                      adViewClassForRendering adViewClass: AnyClass,
                      success: ((UIView) -> ())?,
                      failure: ((AVOError) -> ())?)

The following method performs async downloading of native ads with all linked resources and renders ad data into bound UI controls after that.

There is a common algorithm to use when implementing a native ad:

  1. Create your own subclass of AVONativeView with any name (MyNativeBannerView for example)
  2. Choose one of two options:
    • XIB option - Design the layout of MyNativeBannerView in a separate XIB file. The developer should bind the desired UI controls in this XIB and properties from <AVONativeViewInterface>, which AVONativeView adopts. The implementation of MyNativeBannerView class has to override + (NSString *)xibName method, which returns the name of the same XIB.
    • Coding option - The implementation of MyNativeBannerViewclass must be performed by the creation and placement of UI controls using <AVONativeViewInterface>, which AVONativeViewadopts.
  3. Call loadNativeAdWithAdUnitId: etc with the required parameters, where the adUnitId is your private advertising space ID and className is the name of the MyNativeBannerView class. After downloading the ad data, the SDK immediately initiates MyNativeBannerView class created in step 2. After, the SDK renders the native ad data inside the controls boundaries. Not all controls are filled this way, but only the main ones:avoTitleTextLabel, avoMainTextLabel, avoIconImageView, avoMainMediaView. When the rendering has finished, the successful completion block with this instance will be called.
  4. Show ad view container on the screen.

For example:

#import <AvocarrotNativeView/AvocarrotNativeView.h>
...
__weak typeof(self) weakSelf = self;
[AvocarrotSDK.sharedSDK loadNativeAdWithAdUnitId:@"7f900c7d-7ce3-4190-8e93-310053e70ca2"
                       parentViewController:self
                       classForRendering:NSStringFromClass([MyNativeBannerView class])
                       success:^(UIView *adNativeViewContainer) {
                           UIView *nativeView = adNativeViewContainer;
                           nativeView.frame = weakSelf.adContainerView.bounds;
                           [weakSelf.adContainerView addSubview:nativeView];
                           [nativeView registerViewControllerForInteraction:weakSelf];
                       } failure:^(NSError *error) {
}];
import AvocarrotNativeView
...
AvocarrotSDK.shared.loadNativeAd(withAdUnitId: "7f900c7d-7ce3-4190-8e93-310053e70ca2", parentViewController: self, adViewClassForRendering: classForRendering, success: {
    view in
    nativeView = view
}, failure: nil)

To process native view events, you should implement blocks. The following is available:

MethodDescription
- (instancetype _Nonnull)onImpression:(nullable void (^)(void))impressionCalled when ad impression has been counted.
- (instancetype _Nonnull)onClick:(nullable void (^)(void))clickCalled when ad click has been counted.
- (instancetype _Nonnull)onLeftApplication:(nullable void (^)(void))leftApplicationCalled when application has been left after click.


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?