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
- Objective C
- Swift
#import <BlueStackSDK/BlueStackSDK.h>
import BlueStackSDK
Step 2. Initialize the factory
To create a nativeAd you have to init an object with type MNGAdsSDKFactory and set the nativeDelegate.
- Objective C
- Swift
nativeAdsFactory = [[MNGAdsSDKFactory alloc]init];
nativeAdsFactory.nativeDelegate = self;
nativeAdFactory = MNGAdsSDKFactory()
nativeAdFactory.nativeDelegate = self
You also have to set placementId (minimum one time)
- Objective C
- Swift
nativeAdsFactory.placementId = @"/YOUR_APP_ID/PLACEMENT_ID";
nativeAdFactory.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.
- Objective C
- Swift
MNGPreference *preferences = MNGPreference *preferences = [[MNGPreference alloc]init];
[nativeAdsFactory loadNativeWithPreferences:preferences];
let preferences = MNGPreference()
nativeAdFactory.loadNative(withPreferences: 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 :
- Objective C
- Swift
MNGPreference *preferences = MNGPreference *preferences = [[MNGPreference alloc]init];
[nativeAdsFactory loadNativeWithPreferences:preferences withCover:NO];
let preferences = MNGPreference()
nativeAdFactory.loadNative(withPreferences: preferences,withCover:false)
Ad Events
Register for Native Ad Events
To register for Native Ad events, set the MNGAdsAdapterNativeDelegate
delegate.
- Objective C
- Swift
nativeAdFactory.nativeDelegate = self;
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.
- Objective C
- Swift
-(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];
...
}
func adsAdapter(_ adsAdapter: MNGAdsAdapter!, nativeObjectDidLoad nativeObject: MNGNAtiveObject!) {
nativeView.layer.borderWidth = 1
nativeView.layer.borderColor = UIColor.lightGray.cgColor
titleLabel.text = nativeObject.title
socialContextLabel.text = nativeObject.socialContext
descriptionLabel.text = nativeObject.body
if self.badgeView != nil {
self.badgeView?.removeFromSuperview()
}
self.nativeObject = nativeObject
badgeView = self.nativeObject?.badgeView
if (badgeView != nil) {
var frame = badgeView?.frame
frame?.origin.y = 3
frame?.origin.x = 3
badgeView?.frame = frame!
self.nativeView.addSubview(badgeView!)
}
if adChoiceBadgeView != nil {
adChoiceBadgeView?.removeFromSuperview()
}
adChoiceBadgeView = self.nativeObject?.adChoiceBadgeView
if adChoiceBadgeView != nil {
var frame = adChoiceBadgeView?.frame
let widthFrame = frame!.size.width - 3
frame?.origin.y = 3
frame?.origin.x = self.nativeView.frame.size.width - widthFrame
adChoiceBadgeView?.frame = frame!
self.nativeView.addSubview(adChoiceBadgeView!)
}
// download images
self.backgroundImage.image = nil
self.iconImage.image = nil
self.iconImage.layer.cornerRadius = 16
self.iconImage.clipsToBounds = true
self.callToActionButton.setTitle(self.nativeObject?.callToAction, for: UIControl.State())
if self.nativeObject?.displayType == MNGDisplayType.appInstall {
self.callToActionButton.setImage(#imageLiteral(resourceName: "download"), for: UIControl.State())
}else if self.nativeObject?.displayType == .content {
self.callToActionButton.setImage(#imageLiteral(resourceName: "arrow"), for: UIControl.State())
}
self.callToActionButton.titleLabel?.textAlignment = .center
self.nativeObject?.registerView(forInteraction: self.nativeView, withMediaView: self.backgroundImage, withIconImageView: self.iconImage, with: self, withClickableView: self.callToActionButton)
self.nativeView.isHidden = false
}
adsAdapter:nativeObjectDidFail:
will be called when all ads servers fail. it will return the error of last called ads server.
- Objective C
- Swift
-(void)adsAdapter:(MNGAdsAdapter *)adsAdapter nativeObjectDidFailWithError:(NSError *)error withCover:(BOOL)cover {
}
func adsAdapter(_ adsAdapter: MNGAdsAdapter!, nativeObjectDidFailWithError error: Error!, withCover cover: Bool){
}
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
Sponsored Marker
- 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
- Objective C
- Swift
// 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:...];
// 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;
self.nativeObject?.registerView(forInteraction: self.nativeView, withMediaView: self.backgroundImage, withIconImageView: self.iconImage, with: self, withClickableView: self.callToActionButton)
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
- Objective C
- Swift
[_nativeObject registerViewForInteraction:self.nativeView withMediaView:nil withIconImageView:self.iconImage withViewController:[APP_DELEGATE drawerViewController] withClickableView:self.callToActionButton];
self.nativeObject?.registerView(forInteraction: self.nativeView, withMediaView: nil, withIconImageView: self.iconImage, with: self, withClickableView: self.callToActionButton)
Native Ad With Cover Image
- Objective C
- Swift
[_nativeObject registerViewForInteraction:self.nativeView withMediaView:self.backgroundImage withIconImageView:self.iconImage withViewController:[APP_DELEGATE drawerViewController] withClickableView:self.callToActionButton];
self.nativeObject?.registerView(forInteraction: self.nativeView, withMediaView: self.backgroundImage, withIconImageView: self.iconImage, with: self, withClickableView: self.callToActionButton)
Customizable Badge
Badge in the nativeAd is customizable now using the following method:
- Objective C
- Swift
[_nativeObject updateBadgeTitle:@"newBadgeTitle"];
self.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.