Native ads allow for the seamless integration of ad content into the native views of your application, ensuring that ads maintain the style and quality consistent with the rest of your app. The RTB-Stack SDK makes it easy to integrate and manage native ads in Unity.
Follow these steps to load and display native ads in your application:
First, import the SDK into your Unity class:
using Plugins.RtbStackSDK;
To load a native ad, call the following method:
RtbStackSDK.LoadNative("ENDPOINT_REQUEST_URL", "TAG_ID", RTBStackSDK.Position.BOTTOM, RTBStackSDK.NativeTemplate.SMALL);
Details:
The available positions for native ads are:
TOP
CENTER
BOTTOM
The available templates for native ads are:
SMALL
MEDIUM
By default, the background color for native ads is white (#FFFFFF).
You can also specify a custom background color for the native ad by passing a hex code as the last parameter:
RtbStackSDK.LoadNative("ENDPOINT_REQUEST_URL", "TAG_ID", RTBStackSDK.Position.BOTTOM, RTBStackSDK.NativeTemplate.SMALL, "#000000");
Subscribe to native ad events to track loading, errors, and clicks:
RtbStackSDK.onNativeAdLoadedEvent += onNativeAdLoaded;
RtbStackSDK.onNativeAdFailedToLoadEvent += onNativeAdFailedToLoad;
RtbStackSDK.onNativeAdClickedEvent += onNativeAdClicked;
void onNativeAdLoaded() {
// Handle native ad loaded
}
void onNativeAdFailedToLoad(string error) {
// Handle native ad load failure
}
void onNativeAdClicked(string url) {
// Handle native ad click
}
When the native ad is no longer needed, destroy it to free up resources:
RtbStackSDK.DestroyNative("TAG_ID");
The RTB-Stack SDK allows you to configure the click action for native ads. Use the following method to set the click action:
RtbStackSDK.SetNativeClickThroughAction("TAG_ID", RtbStackSDK.ClickThroughAction.OPEN_DEVICE_BROWSER);
The available click actions are:
OPEN_SDK_BROWSER
OPEN_DEVICE_BROWSER
RETURN_URL
The RTB-Stack SDK offers two types of native templates: Small and Medium. These templates are designed to fit seamlessly within different parts of your application.