Skip to main content

Placement Events

info

Media, Banner and Interstitial share one typed event vocabulary. Feed has its own callbacks, because it speaks the bridge protocol rather than a native placement's event stream. Both are covered here.

Media, Banner and Interstitial​

The callbacks​

CallbackSignaturePurpose
onReadyvoid Function()An ad is loaded and will display
onFailedvoid Function(TeadsAdError)The request or render failed
onClickedvoid Function(TeadsAdClick)A paid ad was clicked
onClickedOrganicvoid Function(TeadsAdClick)Organic content was clicked
onEventvoid Function(TeadsAdEvent, Map<String, dynamic>?)Catch-all for every event
onClosedvoid Function()Interstitial only — dismissed

Every callback is optional. Implement only what you need.

For MediaPlacement and BannerPlacement these are constructor arguments; for InterstitialPlacement they are assignable fields, because it is not a widget:

// Widget placements
MediaPlacement(
config: config,
onReady: () => debugPrint('ready'),
onFailed: (error) => debugPrint(error.reason),
);

// Interstitial
final interstitial = await InterstitialPlacement.create(config: config);
interstitial.onReady = () => debugPrint('ready');
interstitial.onClosed = () => debugPrint('dismissed');

TeadsAdError​

class TeadsAdError {
final String reason;
}
onFailed: (TeadsAdError error) {
debugPrint('Ad failed: ${error.reason}');
analytics.track('ad_error', {'reason': error.reason});
}

A failure is not exceptional — no-fill is a normal outcome. Leave your layout in a sensible state rather than showing an error to the user.

TeadsAdClick​

class TeadsAdClick {
final String? url;
}

url is null for a plain click on platforms and placements that do not report a click-through URL, so always null-check it.

Do not open the URL yourself

The SDK opens the click-through. Opening click.url as well makes the browser open twice. Use these callbacks for analytics only.

The exception is FeedPlacement.onOrganicClick, which exists precisely so you can handle navigation — see below.

TeadsAdEvent​

The catch-all onEvent receives every event, including those with a dedicated callback:

onEvent: (TeadsAdEvent event, Map<String, dynamic>? data) {
switch (event) {
case TeadsAdEvent.viewed:
analytics.track('ad_viewable');
case TeadsAdEvent.complete:
analytics.track('ad_video_complete');
default:
break;
}
}

Full enum:

ValueFires when
readyAn ad is available to display. Feed on Android also emits it when the page reports a fill, with isFillEvent: true in its data
renderedThe creative has been rendered
viewedThe ad met the viewability threshold. Feed emits it for the page's viewability event
failedThe request or render failed
clickedA paid ad was clicked
clickedOrganicOrganic content was clicked
playVideo playback started or resumed
pauseVideo playback paused
loadedThe ad finished loading. Feed on iOS emits it when the page reports a fill
completeVideo playback reached the end
startPlayAudioAudio started (the user unmuted)
stopPlayAudioAudio stopped
heightUpdatedThe placement's height changed. Payload: height, in logical pixels
willPresentInterstitial — about to present
presentedInterstitial — presented fullscreen
willDismissInterstitial — about to dismiss
dismissedInterstitial — dismissed; the ad is spent
Not every placement emits every event

Do not assume the whole enum applies. MediaPlacement never emits loaded or rendered; the fullscreen events come only from Interstitial. Unknown native event names are tolerated rather than throwing, so a future native event will not crash your app — but it will not appear in the enum either.

The widgets resize themselves on heightUpdated, so you do not need to react to it. Use it when your own layout depends on the placement's height.

Feed​

Feed's callbacks differ in shape and purpose:

CallbackSignaturePurpose
onEventvoid Function(TeadsAdEvent event, Map<String, dynamic>? data)Lifecycle, telemetry, height changes and clicks, sharing the typed TeadsAdEvent vocabulary
onUnsupportedvoid Function(TeadsAdError error)A bridge feature the plugin does not implement
onOrganicClickvoid Function(Uri organicUrl)An organic recommendation was tapped
onFullScreenChangevoid Function(bool fullScreen)The page wants to enter or leave fullscreen

onOrganicClick​

Organic recommendations point at your content, so the SDK hands you the URL instead of opening a browser over your app:

FeedPlacement(
config: feedConfig,
onOrganicClick: (Uri organicUrl) {
Navigator.of(context).push(
MaterialPageRoute(builder: (_) => ArticleScreen(url: organicUrl.toString())),
);
},
)

Leave it null and the article opens in an in-app browser view instead. Either way the click is registered, and that does not depend on this callback. On Android the report is started before the callback runs but is not awaited. On iOS the callback runs, and clickedOrganic is emitted, only after the click's tracking report succeeds. If the report fails, neither happens and nothing opens.

onFullScreenChange​

The placement can only grow its own slot, so your app must fold its chrome away. It scrolls its card to the top of the viewport itself, so do not scroll your list from this callback. See the Feed guide for a complete example.

Never remove widgets from the tree while fullscreen

Collapse siblings with Visibility(maintainState: true) or a zero height. Removing one re-parents the WebView and it stops painting.

onUnsupported​

This is the only route for Feed parity gaps

onUnsupported reports a bridge feature the plugin does not implement. A build that does not wire it up sees a missing feature as silence. Wire it up in any build you intend to debug.

Page events that neither native SDK forwards, error messages the page reports about itself, and the Google ads card messages no longer reach onUnsupported. Both native SDKs drop them, and the plugin logs them at debug level. Set TeadsLog.level = LogLevel.debug to see them.

FeedPlacement(
config: feedConfig,
onUnsupported: (TeadsAdError error) {
debugPrint('Feed unsupported: ${error.reason}');
analytics.track('feed_unsupported', {'reason': error.reason});
},
)

onEvent​

Shares the typed TeadsAdEvent vocabulary, mapped from the bridge page's events as each native Feed maps them:

Page eventAndroidiOS
fillready, with isFillEvent: true in its dataloaded
readyreadyready
renderedrenderedrendered
viewabilityviewedviewed
no-fillfailed, with reason: 'notFilled' plus the page's own fieldsfailed, with reason: 'notFilled', errorCode: 3 plus the page's own fields
errorfailed, with the page's message as reasonnot emitted
  • ready fires twice per ad on Android, once for the fill and once for the page's own ready, as on native Android. Use isFillEvent to tell them apart. On iOS it fires once.
  • reason was 'no-fill' before 1.2.0. Match 'notFilled' now.
  • TeadsAdEvent.viewability is deprecated. Listen for viewed. viewability is still emitted right after each viewed until it is removed.

Feed holds events back until the ad's outcome is known. Nothing but clicks arrives before the page reports a fill or a no-fill, or after a no-fill. The last height the page reported before the fill is delivered right after it.

It also emits, as the native Feed does:

EventPayloadFires when
heightUpdatedheightThe feed's height in your layout changed. height is the page's height plus contentBottomPadding, capped at maxHeight. Read it as num
clickedurlA sponsored recommendation or a display ad was tapped. The SDK opens it
clickedOrganicurlAn organic recommendation was tapped. On Android it fires whether or not onOrganicClick is set. On iOS it fires only after the click's tracking report succeeds

Details that differ by platform or that you may trip over:

  • heightUpdated on Android fires for every height the page reports, repeats included, and height is a whole number there unless your padding or cap is fractional. The slot itself is not held back: it can grow before the fill with no heightUpdated, and the latest height arrives right after the fill. Don't size your layout from this event before the fill. On iOS it fires only when the height changes. Changing contentBottomPadding or maxHeight on a rebuild emits it too, once the page has reported a height. It is not emitted while a card is fullscreen.
  • clicked is emitted when the plugin asks to open the URL, not when the browser finishes loading. Repeated clicks within one second count as one, and on iOS so does a second tap while an organic click is still being reported.
FeedPlacement(
config: feedConfig,
onEvent: (TeadsAdEvent event, Map<String, dynamic>? data) {
switch (event) {
case TeadsAdEvent.heightUpdated:
debugPrint('Feed height: ${data?['height']}');
case TeadsAdEvent.clicked:
analytics.track('feed_paid_click', {'url': data?['url']});
default:
debugPrint('Feed event: ${event.identifier} — $data');
}
},
)

Complete Example​

class _ArticleScreenState extends State<ArticleScreen> {
bool _fullScreen = false;


Widget build(BuildContext context) {
return Scaffold(
// Black behind the card: on Android the hidden navigation bar leaves a
// strip the card does not cover.
backgroundColor: _fullScreen ? Colors.black : null,
// Zero height rather than null: removing the AppBar changes the
// Scaffold's layout and risks re-parenting the body.
appBar: PreferredSize(
preferredSize: Size.fromHeight(_fullScreen ? 0 : kToolbarHeight),
child: _fullScreen
? const SizedBox.shrink()
: AppBar(title: const Text('Article')),
),
body: ListView(
physics: _fullScreen ? const NeverScrollableScrollPhysics() : null,
children: [
Visibility(
visible: !_fullScreen,
maintainState: true,
child: Column(
children: [
const Text('Article content…'),
MediaPlacement(
config: MediaPlacementConfig(
pid: 84242,
articleUrl: widget.articleUrl,
),
onReady: () => analytics.track('media_ready'),
onFailed: (error) =>
analytics.track('media_failed', {'reason': error.reason}),
onClicked: (click) =>
analytics.track('media_clicked', {'url': click.url}),
onEvent: (event, data) {
if (event == TeadsAdEvent.viewed) {
analytics.track('media_viewable');
}
},
),
],
),
),
FeedPlacement(
config: FeedPlacementConfig(
widgetId: 'MB_1',
installationKey: 'NANOWDGT01',
articleUrl: widget.articleUrl,
),
onOrganicClick: (url) => Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => ArticleScreen(articleUrl: url.toString()),
),
),
onUnsupported: (error) => debugPrint('Feed: ${error.reason}'),
onFullScreenChange: (fullScreen) =>
setState(() => _fullScreen = fullScreen),
),
],
),
);
}
}

Best Practices​

Keep callbacks cheap​

They run on the platform-channel response path. Heavy synchronous work there shows up as jank while an ad is loading. Queue it instead.

Guard setState​

An event can arrive after the widget is unmounted:

onReady: () {
if (!mounted) return;
setState(() => _adReady = true);
}

Do not re-create callbacks needlessly​

Building a new closure on every rebuild is harmless for correctness but makes the placement's config identity churn. Prefer instance methods over inline closures in a frequently-rebuilt widget.

Treat failure as normal​

No-fill is an expected outcome, not an error state to surface to users. Collapse the slot gracefully.

Troubleshooting​

Events not firing​

  • Confirm TeadsSdk.configure() completed without throwing
  • Confirm the callback is actually passed to the constructor
  • Confirm the widget is mounted and on screen
  • Raise the log level: TeadsLog.level = LogLevel.debug

Clicks not working​

  • Check for an overlay — even a transparent one — over the placement
  • Check that no ancestor IgnorePointer or AbsorbPointer is swallowing the gesture
  • Test on a real device

Feed fullscreen breaks the layout​

You are almost certainly removing widgets from the tree rather than collapsing them.

Next Steps​


tip

Pro tip: wire onFailed and — for Feed — onUnsupported up from the start. They are the difference between a diagnosable integration and a silent one.