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 (for a VOD mid-roll, when the content reaches the break position). This is where the app calls play. For an interstitial or inline break, the app also pauses its content here. For a VOD break, the app pauses nothing here: a pre-roll arrives while the app still holds the content before its first start, and for a mid-roll the SDK pauses the content itself.

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 inline breaks, this is where the app resumes its content. For VOD, the first completed is where the app starts the content it has been holding — the SDK sends it even when there is no pre-roll, the ad response is empty or the request fails. After a VOD mid-roll, the SDK resumes the content itself.

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 an 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.

error is sent when an ad fails to play. When content playback stops and the SDK cannot recover it, error is sent with a message starting with playback unrecoverable (not reported on iOS with playerType: 'bitmovin'). On Android it is also sent for an internal SDK error. A VOD ad request that fails, times out or returns no ads ends with completed, not error.

What to do on error depends on the kind of session:

  • Linear TV / FAST, for every error including playback unrecoverable and an internal SDK error: end the ad session with await stop(nativeId), then start the channel over — a new changeChannelUrl() with exactly the same parameters as the first start, prerollAdTagUrl included, and the new proxy URL it returns handled the same way as the first time. The channel has not changed, so the pre-roll is skipped; see Recovering from an Error.
  • VOD, by where the content is. Never stop, seek or re-source the content here. completed may also arrive for the failed break, in either order.
    • Not started yet (pre-roll): start the held content, exactly as on completed.
    • Started and not ended (mid-roll): the SDK has normally brought the content back already; resume it as a safety net — videoRef.current?.resume() (Bitmovin: player.play()), harmless if it is already playing.
    • Ended (post-roll): nothing to resume — playback is over.
    • playback unrecoverable: the content itself stopped. Reload it or show an error.
  • Inline: resume your content and call stop(nativeId), as on completed.

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
4: Not Initialized (the ad request was not sent because the SDK had not finished initializing, e.g. right after initialization)