Aller au contenu principal
Version: 5.x.x

Native Ads

Overview

BlueStack supports native ads, that allow you to retrieve the metadata of ad campaigns and present the ads yourself, within the context of your app, using your own art style. You are fully responsible for rendering the ad views using the information we supply. Native ads however offer methods to help you register impressions and clicks on your custom view.

Create a Native Ad

Step 1. Import the SDK

#import <BlueStackSDK/BlueStackSDK.h>

Step 2. Initialize the factory

To create a nativeAd you have to init an object with type MNGAdsSDKFactory and set the nativeDelegate.

nativeAdsFactory = [[MNGAdsSDKFactory alloc]init];
nativeAdsFactory.nativeDelegate = self;

You also have to set placementId (minimum one time)

nativeAdsFactory.placementId = @"/YOUR_APP_ID/PLACEMENT_ID";

Load a Native Ad

Using MNGPreference you can set the preferred ad choices position , although you need to keep in mind that in some cases it might not position it where mentioned since some of the adnetworks wont take this parameter into consideration , so preferably set the preferred position here as well in the didLoad once the request succeeds.

Native Ad AdChoice:

Finally to execute the request you have to call loadNativeWithPreferences:. By default it will load with Cover Image.

MNGPreference *preferences = MNGPreference *preferences = [[MNGPreference alloc]init];
[nativeAdsFactory loadNativeWithPreferences:preferences];

Native Ad AdChoice Without Cover Image

if you like to execute the request without cover Image you can set the option withCover to NO :

MNGPreference *preferences = MNGPreference *preferences = [[MNGPreference alloc]init];
[nativeAdsFactory loadNativeWithPreferences:preferences withCover:NO];

Ad Events

Register for Native Ad Events

To register for Native Ad events, set the MNGAdsAdapterNativeDelegate delegate.

nativeAdFactory.nativeDelegate = self;

Implement Native Ad Events

adsAdapter:nativeObjectDidLoad: will be called by the SDK when your nativeObject is ready. now you can create your own view.

-(void)adsAdapter:(MNGAdsAdapter *)adsAdapter nativeObjectDidLoad:(MNGNAtiveObject *)nativeObject{
NSLog(@"adsAdapterNativeObjectDidLoad:");
self.titleLabel.text = nativeObject.title;
self.contextLabel.text = nativeObject.socialContext;
self.bodyLabel.text = nativeObject.body;
//possibility to customize the badge title
[nativeObject updateBadgeTitle:@"Publicité"];
badgeView = nativeObject.badgeView;
[_nativeObject registerViewForInteraction:self.nativeView withMediaView:self.backgroundImage withIconImageView:self.iconImage withViewController:[APP_DELEGATE drawerViewController] withClickableView:self.callToActionButton];
...
}

adsAdapter:nativeObjectDidFail: will be called when all ads servers fail. it will return the error of last called ads server.

-(void)adsAdapter:(MNGAdsAdapter *)adsAdapter nativeObjectDidFailWithError:(NSError *)error withCover:(BOOL)cover {

}

Native Ad Assets

Once a native ad is loaded, you may retrieve its metadata with the following methods:

Ad Title

  • 50 maximum character length string of ad headline
  • Provide enough space to display the entire length of the Ad Title
  • asset name : nativeObject.title

Ad Text

  • 150 maximum character length string of ad text
  • Provide enough space to display the entire length of the Ad Text
  • asset name : nativeObject.body

CTA Text

  • Text for a button
  • 12 characters maximum
  • asset name : nativeObject.callToAction
  • Badge view (an icon)
  • change according ad network
  • must be inserted on top right
  • asset name : nativeObject.adChoiceBadgeView

Distinguishable Ad

  • “Ad” (can be localized)
  • Badge that says “AD” and is at least 15x15px (can be localized)
  • change according ad network
  • must be inserted on top left
  • asset name : nativeObject.badgeView
// Get the app name
title=nativeObject.title;

// Get the app description (tagline)
body=nativeObject.body;

// Get the "Ad" badge view. You must show this view on your ad view to denote an ad
if(nativeObject.badgeView){
badge=nativeObject.badgeView;
...
}

// Get the "AdChoice" badge view. You must show this view on your ad view to denote an ad
if(nativeObject.adChoiceBadgeView){
adChoiceBadge=nativeObject.adChoiceBadgeView;
...
}

// Get the localized text to print on the call to action button, such as "DOWNLOAD , LEARN MORE ..."
callToAction=nativeObject.callToAction;

[_nativeObject registerViewForInteraction:...];

Caching Native Ad

Ad metadata that you receive can be cached and re-used for up to 3 hours. If you plan to use the metadata after this time period, make a call to load a new ad.

Assets download

we provide method to download assets.

registerViewForInteraction parameters

  • self.nativeView. : containerView of native Ad
  • withMediaView : coverImageView
  • withIconImageView : iconImageView
  • withViewController : parent ViewController of nativeAd
  • withClickableView : the button of nativeAd

Native Ad Without Cover Image

[_nativeObject registerViewForInteraction:self.nativeView withMediaView:nil withIconImageView:self.iconImage withViewController:[APP_DELEGATE drawerViewController] withClickableView:self.callToActionButton];

Native Ad With Cover Image

[_nativeObject registerViewForInteraction:self.nativeView withMediaView:self.backgroundImage withIconImageView:self.iconImage withViewController:[APP_DELEGATE drawerViewController] withClickableView:self.callToActionButton];

Customizable Badge

Badge in the nativeAd is customizable now using the following method:

 [_nativeObject updateBadgeTitle:@"newBadgeTitle"];

note that the new method returns a BOOL indicating if the update was successful or not.

Click - registerViewForInteraction

It's HIGHLY recommended to only register ONE and ONLY one view for interaction , because some of the AdNetworks only accept one view and if you try to assign more than one then probably none of the views you assign will be responsive.