Skip to main content

Ad Events

Ad events replace the FlowerAdsManagerListener interface of the native SDKs. Instead of implementing a listener object, you subscribe to a stream of AdEvent values.

Every event carries the nativeId of the <Video> it belongs to, which is what keeps several players apart.

Subscribing​

addAdEventListener​

function addAdEventListener(listener: (event: AdEvent) => void): EmitterSubscription;

Subscribes to ad events from every session. Use event.nativeId to tell them apart.

addAdEventListenerFor​

function addAdEventListenerFor(
nativeId: string,
listener: (event: AdEvent) => void,
): EmitterSubscription;

Subscribes to ad events from one session only. Events for other nativeId values are filtered out.

Both return a subscription — call remove() on it when the component unmounts:

useEffect(() => {
const subscription = addAdEventListenerFor(nativeId, event => {
// …
});
return () => subscription.remove();
}, [nativeId]);
caution

Event subscriptions are independent of release. Releasing a session does not remove listeners you added yourself.

AdEvent​

AdEvent is a discriminated union on the event field, so narrowing on it gives you the payload fields:

export type AdEvent = {nativeId: string} & (
| {event: 'adBreakPrepare'; adCount: number}
| {event: 'prepare'; adDurationMs: number}
| {event: 'play'}
| {event: 'adPlay'; adId: string; durationMs: number}
| {event: 'completed'}
| {event: 'error'; message: string | null}
| {event: 'adUserAction'; action: string; adId: string}
| {event: 'adBreakSkipped'; reason: number}
);
addAdEventListenerFor(nativeId, event => {
switch (event.event) {
case 'prepare':
console.log(`break ready, ${event.adDurationMs}ms`); // adDurationMs is in scope
break;
case 'adPlay':
console.log(`ad ${event.adId} started`); // adId is in scope
break;
}
});

Events​

adBreakPrepare​

Dispatched when the ad manifest is loaded for interstitial or VOD ads.

FieldTypeDescription
nativeIdstringThe session the event belongs to
adCountnumberNumber of ads loaded for the break

prepare​

Dispatched when the ad break is loaded for interstitial or VOD ads. This is where the app pauses its content and calls play.

FieldTypeDescription
nativeIdstringThe session the event belongs to
adDurationMsnumberTotal ad break duration in milliseconds

play​

Dispatched when ad playback starts.

FieldTypeDescription
nativeIdstringThe session the event belongs to

adPlay​

Dispatched when each individual ad unit begins playback.

FieldTypeDescription
nativeIdstringThe session the event belongs to
adIdstringAd id specified in the VAST response. An empty string when the response carried none.
durationMsnumberDuration of this ad in milliseconds

completed​

Dispatched when ad playback ends. For VOD and inline breaks, this is where the app resumes its content.

FieldTypeDescription
nativeIdstringThe session the event belongs to

error​

Dispatched when any error happens in the Flower SDK.

FieldTypeDescription
nativeIdstringThe session the event belongs to
messagestring | nullError message, when the SDK supplied one
caution

An error during a VOD or inline break leaves your content paused, because pausing it was your app's doing. Resume it from this branch as well as from completed, or the viewer is left on a frozen frame.

adUserAction​

Dispatched when the user interacts with the ad.

FieldTypeDescription
nativeIdstringThe session the event belongs to
actionstringUser action type.
learn_more: the user clicked the learn-more / click-through area.
skip: the user pressed the skip button.
adIdstringAd id the action was performed on

adBreakSkipped​

Dispatched when an ad break is skipped.

FieldTypeDescription
nativeIdstringThe session the event belongs to
reasonnumberCode describing why the break was skipped.
0: Unknown
1: No Ad
2: Timeout
3: Error