Configuration
This guide explains how to initialize and configure the Empower Mobile Ads SDK in your game.
SDK Initialization
Initialize the SDK once, at launch. Decide how consent is handled first. See Terms and Privacy Policy Flow.
Basic Initialization
using Empower.MobileAds;
EmpowerAds.Initialize(new EmpowerAdsConfig(
android: "YOUR_ANDROID_APP_AD_IDENTIFIER",
iOS: "YOUR_IOS_APP_AD_IDENTIFIER"));
Replace the two values with the app identifiers provided by Empower, and pass them by name. If you build for one platform only, pass only that one.
Advanced Initialization with Configuration
For more control over the SDK behavior, set the properties of EmpowerAdsConfig:
var config = new EmpowerAdsConfig(
android: "YOUR_ANDROID_APP_AD_IDENTIFIER",
iOS: "YOUR_IOS_APP_AD_IDENTIFIER")
{
DebugMode = true,
LogLevel = EmpowerLogLevel.All,
PrivacyMode = PrivacyMode.Automatic
};
EmpowerAds.Initialize(config);
Keep DebugMode off and LogLevel at its default in production builds.
Log Levels
| Level | Description |
|---|---|
All | Logs all messages including debug information |
Default | Logs general information and errors |
Error | Logs errors only |
Warning | Logs warnings and errors only |
None | Disables all logging |
Listening for SDK Ready State
Subscribe to OnSdkReady before you call Initialize, and load your ads from it:
using Empower.MobileAds;
using UnityEngine;
public class AdsBootstrap : MonoBehaviour
{
void Start()
{
EmpowerAds.OnSdkReady += HandleSdkReady;
EmpowerAds.OnSdkFailed += HandleSdkFailed;
EmpowerAds.Initialize(new EmpowerAdsConfig(
android: "YOUR_ANDROID_APP_AD_IDENTIFIER",
iOS: "YOUR_IOS_APP_AD_IDENTIFIER"));
}
void OnDestroy()
{
EmpowerAds.OnSdkReady -= HandleSdkReady;
EmpowerAds.OnSdkFailed -= HandleSdkFailed;
}
private void HandleSdkReady()
{
// Load your ads here.
}
private void HandleSdkFailed(string error)
{
}
}
OnSdkReady can follow OnSdkFailed. The SDK keeps retrying the configuration request and raises OnSdkReady when one succeeds, so do not treat OnSdkFailed as final.
All EmpowerAds events are static. Unsubscribe in OnDestroy or OnDisable.
Variant, Ext and Screen Tracking
These calls change the ad configuration while the game runs, to serve different ads on different screens or to different groups of players. They work on Android only for now. On iOS they do nothing.
// At start
config.Variant = "experiment_a";
config.Ext = "level=3";
// While the game runs
EmpowerAds.SetVariant("experiment_b");
EmpowerAds.SetExt("level=4");
// Both with a single request
EmpowerAds.SetScreenInfo("experiment_b", "level=4");
// Report a screen view when a scene or menu opens
EmpowerAds.TrackScreenView("main_menu");
SetVariant, SetExt and SetScreenInfo take an optional callback as their last argument. It runs once the ads of the new configuration are ready. It does not run when the call is made before Initialize, while ads are disabled or while the game is in the background, when the request fails, or when a later call replaces it.
Disabling Ads at Runtime
To stop serving ads without shutting down the SDK, for example for a user toggle, call SetAdsDisabled. The SDK stays initialized.
// Stop serving ads without shutting down the SDK
EmpowerAds.SetAdsDisabled(true);
// Resume ads later
EmpowerAds.SetAdsDisabled(false);
Shutdown
Use Shutdown when you no longer want to show ads (e.g., user bought premium):
EmpowerAds.Shutdown();