Native Ads
BlueStack native ads allow you to retrieve the metadata of ad campaigns and present the ads yourself, within the context of your app/game, using your own art style. So, it matches the visual design of the app they live within. You are fully responsible for rendering the ad views using the information we supply.
Native video ads and native mediation are not supported at present.
Overview
Native ads are created using the GameObjects
. You get a native ad object when a native ad loads.
It contains the assets that you need to construct the ad and display.
Before You Start. Make sure that you have correctly integrated the [BlueStack Unity SDK]
into your application.
Check the Examples provided within the SDK for a quick start and better understanding.
1. Requesting a native ad
Native ads are loaded through the NativeAdLoader
class.
Register NativeAdLoader ad events
To be notified when a native ad either successfully loads or fails to load, add delegates to the AdLoader class for the events listed below.
OnNativeAdLoaded
is invoked when a native ad is successfully loaded.
It has a delegate to access the ad that is loaded.
OnAdFailedToLoad
is invoked when a native ad fails to load.
private void RequestNativeAd()
{
string NativeAdUnitId = "/YOUR_APP_ID/PLACEMENT_ID";
NativeAdLoader nativeAdLoader = new NativeAdLoader(NativeAdUnitId);
nativeAdLoader.OnNativeAdLoaded += this.HandleNativeAdLoaded;
nativeAdLoader.OnNativeAdFailedToLoad += this.HandleNativeNativeAdFailedToLoad;
nativeAdLoader.Load();
}
Handle ad events
Handle OnAdFailedToLoad event
The OnAdFailedToLoad
event is of type EventHandle<BlueStackError>
. Provides you the reason for an ad load failure.
private void HandleNativeAdFailedToLoad(object sender, BlueStackError args)
{
Debug.Log("BlueStack NativeAd failed to load: " + "errorCode: " + args.ErrorCode + " message: " +
args.Message);
}
Handle OnNativeAdLoaded event
The OnNativeAdLoaded
event is of type EventHandler<NativeAdEventArgs>
.
The NativeAd
object can be retrieved from NativeAdEventArgs.
private NativeAd nativeAd;
private void HandleNativeAdLoaded(object sender, NativeAdEventArgs args)
{
this.nativeAd = args.nativeAd;
}
2. Retrieve native ad assets
Once the ad has loaded, you can access the ad assets.
Text assets are returned as string
objects and Graphical assets are returned as Texture2D
objects.
Currently, BlueStack Native Ad provides methods to retrieve following assets:
Ad Title
- 50 maximum character length string of ad headline
- Provide enough space to display the entire length of the Ad Title
- method name : GetTitleText()
Ad Text
- 150 maximum character length string of ad text
- Provide enough space to display the entire length of the Ad Text
- method name : GetBodyText()
CallToAction(CTA) Text
- Text for a button
- 12 characters maximum
- Clickable object
- method name : GetCallToActionText()
Badge Text
- “Ad” text (can be localized)
- Badge that says “AD” and should be at least 15x15px (can be localized)
- change according ad network
- must be inserted on top left
- method name : GetBadgeText()
Icon Image
- Icon for the Ad (usually app icon)
- A Texture2D object
- method name : GetIconTexture()
Cover Image
- Main image for the Ad (usually a banner)
- A Texture2D object
- method name : GetCoverImageTexture()
void Update() {
...
string titleText = this.nativeAd.GetTitleText();
string bodyText = this.nativeAd.GetBodyText();
Texture2D imageTexture = this.nativeAd.GetCoverImageTexture();
...
}
Ad assets should only be accessed from the main thread, like, Update()
, Start()
methods of a Unity script.
3. Construct native ad
Construct the Ad using the assets retrieved from the Native Ad object.
Here is the list of Methods available to retrieved Native Ad assets,
Methods | Return Type | Definition |
---|---|---|
GetTitleText | string | Get the title of the ad. |
GetBodyText | string | Get the body text of the ad. |
GetCallToActionText | string | Get the text for the button of the ad (Example : "Download"). |
GetBadgeText | string | Get the text for the badge of the ad (Example : "AD"). |
GetIconTexture | Texture2D | Get the icon image for the ad (usually app icon). |
GetCoverImageTexture | Texture2D | Get the cover image for the ad (usually a banner). |
Following is an example of how to retrieved ad asset and assign it,
Texture2D iconTexture = this.nativeAd.GetIconTexture();
if (iconTexture != null)
{
appIcon.GetComponent<RawImage>().texture = iconTexture;
}
4. Register ad GameObjects
You must register the GameObject for the ad asset to be displayed in your Unity app. If registration is successful, the method used to register the GameObject returns a bool. If registration of an ad asset is unsuccessful, impressions and clicks on the corresponding native ad won't be recognized.
Here is the list of Methods to register Native Ad object,
Methods | Definition |
---|---|
RegisterTitleTextGameObject | Register the title text GameObject. |
RegisterBodyTextGameObject | Register the body text GameObject. |
RegisterCallToActionTextGameObject | Register the CallToAction text GameObject. |
RegisterBadgeTextGameObject | Register the badge text GameObject. |
RegisterIconImageGameObject | Register the icon image GameObject. |
RegisterCoverImageGameObject | Register the cover image GameObject. |
Following is an example of how to register ad object,
if (!this.nativeAd.RegisterIconImageGameObject(appIcon))
{
Debug.Log("RegisterIconImageGameObject Unsuccessful");
}
The registered GameObject
must have a Collider
component that represents the size and shape of the GameObject
.
Native ads will not operate correctly,
if any GameObject
registered to ad asset is missing Collider
component or configured incorrectly.
- The registered
GameObject
must have aCollider
component that represents the size and shape of theGameObject
. It deterdetermines the interactable area of the Native Ad object. Native ads will not operate correctly, if anyGameObject
registered to ad asset is missingCollider
component or configured incorrectly. - If using UI Canvas, make sure the canvas containing the Native ad is at the top, to make the impression and click to work.