Preroll Ads
Preroll ads are video ads that play before your content video. The package creates the player for you and shows it on top of the Unity view. The ad auto-plays.
Each ad format uses a Zone ID to identify the ad placement. Zone IDs are configured in the Empower dashboard.
Load the preroll when your video screen opens, and destroy it when the screen closes.
Loading a Preroll Ad
EmpowerAds.LoadPrerollAd(
"YOUR_PREROLL_ZONE_ID",
"https://example.com/your-content-video.mp4");
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
zoneId | string | Yes | none | The zone ID for the preroll placement |
contentUrl | string | Yes | none | URL of the content video that plays after the ad |
muted | bool | No | false | Whether playback starts muted |
The player is a full-width 16:9 strip, centered on the screen on Android and at the top of the screen on iOS.
Unity UI under the player does not receive touches until you call DestroyPreroll. Keep your controls outside that area.
On iOS the content video does not play after the ad yet. The player shows the ad only.
Listening to Preroll Events
The events are optional. Use them only if you need to track ad states for analytics or UI updates.
OnPrerollEvent delivers the event name, the zone ID and an error message:
| Event name | Raised when |
|---|---|
onAdReady | Ad loaded and about to auto-play |
onAdStarted | Ad playback started |
onAdCompleted | Ad finished |
onAdSkipped | User skipped the ad |
onAdFailed | Ad failed. The error argument holds the message |
onAdClicked | User clicked the ad |
If you need to react to preroll events:
void OnEnable()
{
EmpowerAds.OnPrerollEvent += HandlePrerollEvent;
}
void OnDisable()
{
EmpowerAds.OnPrerollEvent -= HandlePrerollEvent;
}
private void HandlePrerollEvent(string eventName, string zoneId, string error)
{
if (zoneId != "YOUR_PREROLL_ZONE_ID") return;
switch (eventName)
{
case "onAdStarted":
break;
case "onAdCompleted":
break;
case "onAdFailed":
break;
}
}
The event names differ on iOS: started, completed, skipped and failed. Ready and clicked arrive as the Ready and Clicked statuses on OnPrerollStatusChanged.
OnPrerollStatusChanged reports the ad status in the same way as the other formats: Initializing, Ready, Shown, CompletePlaying, Skipped and Failed.
Lifecycle Management
EmpowerAds.PausePreroll("YOUR_PREROLL_ZONE_ID");
EmpowerAds.ResumePreroll("YOUR_PREROLL_ZONE_ID");
// Remove the player when the video screen closes
EmpowerAds.DestroyPreroll("YOUR_PREROLL_ZONE_ID");
EmpowerPrerollAd Component (Optional)
If you prefer the Inspector, attach the EmpowerPrerollAd component to a GameObject and set its Zone Id and Content Url. It loads the preroll in Start, pauses it while the GameObject is disabled and destroys it with the GameObject.