trek_gma_mediation 0.1.1
trek_gma_mediation: ^0.1.1 copied to clipboard
AotterTrek ads through Google Mobile Ads mediation (AdMob and Ad Manager), with built-in native ad layouts that size themselves to each creative.
trek_gma_mediation #
AotterTrek ads in Flutter through Google Mobile Ads
mediation (AdMob and Ad Manager), on top of
google_mobile_ads.
Depending on this package brings the AotterTrek adapters into the app
(trek-admob-mediation and trek-gam-mediation on Android,
AotterTrekMediation on iOS). Requests made with google_mobile_ads are then
filled by AotterTrek through the mediation groups set up in the AdMob or Ad
Manager console. The package also registers native ad layouts that size
themselves to each creative, so the app writes no native code.
The integration guide is at aotter.gitbook.io/flutter.
Requirements #
-
Flutter 3.44 or later and
google_mobile_ads9.2.0 or later. -
iOS 15 or later.
-
Android
minSdk24. The app'sMainActivitymust extendFlutterFragmentActivity: the AotterTrek SDK depends onFragmentActivityand degrades silently without it. -
Android apps declare Aotter's Maven repository in their own Gradle configuration; repositories declared inside a plugin do not reach the app:
maven { url = uri("https://deps.aotter.net/artifactory/libs-release-local") }
Before you start #
- Create the AotterTrek apps and placements. In the AotterTrek console, create one application for Android and one for iOS: each platform has its own client ID and its own placements. Then create the placements (Native Ad, Native Multimedia Ad or Banner Ad) under each application. The steps are the same as for a native app; see the Prerequisites for Android or iOS.
- Add AotterTrek to the mediation groups. AdMob and Ad Manager also keep a separate app for each platform. In each ad unit's mediation group, add AotterTrek as a custom event with that platform's client ID and placement. The class name and parameter differ by platform; see AotterTrek's AdMob prerequisites for Android and iOS. To try the integration before your placements are ready, start with AotterTrek's test values.
- Match each placement in the app. Each ad unit maps to one AotterTrek
placement. A Native Ad placement takes
TrekNativeAdOptions.forNativeAdUnit()and a Native Multimedia Ad placementTrekNativeAdOptions.forNativeMultimediaAdUnit()(see Native ads); a Banner Ad placement takes aBannerAdof the placement's size (see Banners).
Native ads #
Load a NativeAd with the built-in factory and show it in a
TrekMediationNativeAdWidget, which takes the height the native layout needs
at the available width:
final ad = NativeAd(
adUnitId: '<your ad unit>',
factoryId: trekNativeAdFactoryId,
customOptions: TrekNativeAdOptions.forNativeMultimediaAdUnit(),
request: const AdRequest(),
listener: NativeAdListener(onAdLoaded: (_) => setState(() => loaded = true)),
)..load();
// Once loaded:
TrekMediationNativeAdWidget(ad: ad);
Match the options to the ad unit's type: forNativeMultimediaAdUnit() for
Native Multimedia Ad units, forNativeAdUnit() for Native Ad units. A Native
Ad unit in the multimedia layout renders and is measured wrongly. The
AotterTrek adapters name each ad's type, and the built-in layouts follow it,
logging a warning when it differs from the options; ads from other networks
take the options' layout.
Give the widget a width of at least 230 and let it pick its height; do not wrap it in a fixed-height box.
Until the native layout reports its height, the widget is initialHeight
tall (300 by default). Set it close to what your ads need: while a layout is
taller than that, Google's native ad validator, shown in debug builds of test
ads, reports that "not all asset views lie inside the native ad view". Large
system font sizes and wide screens make the media card taller.
Both options take Google's NativeTemplateStyle. Its templateType is
ignored; the option picks the layout. The text styles map as in Google's
Android templates, and cornerRadius applies on both platforms (Google's
templates use it on iOS only):
NativeTemplateStyle |
Applies to |
|---|---|
mainBackgroundColor |
the ad's background |
cornerRadius |
the icon and the call to action |
primaryTextStyle |
the headline |
secondaryTextStyle |
the advertiser (the sponsor label takes its text color) |
tertiaryTextStyle |
the body |
callToActionTextStyle |
the call to action |
Google's iOS templates use the secondary style for the body and the tertiary one for the advertiser, so swap those two when reusing an iOS template style.
Without a style, the headline, advertiser and body are dark gray and the ad's
background is transparent. On a dark page, set mainBackgroundColor: the green
"Ad" badge has no style of its own.
TrekNativeAdOptions.forNativeAdUnit(
style: NativeTemplateStyle(
templateType: TemplateType.small, // ignored
mainBackgroundColor: Colors.white,
cornerRadius: 8,
callToActionTextStyle: NativeTemplateTextStyle(backgroundColor: Colors.teal),
),
)
An app with its own NativeAdFactory keeps the same sizing: merge
TrekNativeAdOptions.sizeOnly() into its customOptions and call
TrekAdSizeReporter.attach(adView, customOptions) on the view it returns.
On iOS, an AotterTrek Native Multimedia Ad takes its clicks from taps on the
GADNativeAdView and does not register its callToActionView. A button there
takes the tap for itself, so the tap does not reach the ad: turn off the
button's user interaction (isUserInteractionEnabled = false) or show the
call to action in a label.
Request values #
Pass the category, URL and title of the content the ad appears in:
AdRequest(
mediationExtras: TrekMediationExtras.of(
category: 'news',
contentUrl: 'https://example.com/article/1',
contentTitle: 'Article title',
),
)
Banners #
An AotterTrek banner placement has one size: 320 × 50, 320 × 100 or 300 × 250.
Request that size with BannerAd; the creative is not scaled to another size,
so do not use adaptive sizes. Refresh follows the AdMob or Ad Manager console.
Creatives that move with the page #
Some AotterTrek creatives move as the page scrolls (a parallax effect), in
native ads and banners alike. On Android they follow scrolling by themselves.
On iOS they need telling: TrekMediationNativeAdWidget tells them whenever the
nearest Scrollable around it scrolls, and that notice reaches the AotterTrek
ads shown through AdMob or Ad Manager on the screen, banners included, but
only while such a widget is built in the same Scrollable; a lazy list drops
rows that scroll away. Call TrekMediation.notifyAdScrolled() yourself as the
page scrolls when it shows banners, or when something else moves the ads, such
as an outer Scrollable; the SDK skips ads that did not move:
NotificationListener<ScrollUpdateNotification>(
onNotification: (_) {
TrekMediation.notifyAdScrolled();
return false;
},
child: listView,
);
On iOS, an ad that is on screen before the page has scrolled shows its creative at the starting position until the page first scrolls.
Callbacks and testing #
onAdImpressionis Google Mobile Ads' callback and fires at a different time from AotterTrek's viewable impression; count impressions in AotterTrek's dashboard. On iOS,onAdClickedfires only for the first click on a native ad; a banner's fires for every click.- On a registered test device, AdMob Network answers with test ads, so an
AotterTrek custom event placed after it in the waterfall is not called. To
see AotterTrek fill, use the Ad Inspector's single ad source test
(
MobileAds.instance.openAdInspector); it stays on across restarts until turned off there.
iOS with CocoaPods #
Swift Package Manager is the default. An app that uses CocoaPods instead adds
Aotter's spec repository, where AotterTrek publishes its iOS pods, to
ios/Podfile:
source 'https://github.com/aotter/AotterTrekSpecs-iOS.git'
source 'https://cdn.cocoapods.org/'
platform :ios, '15.0'
Compatibility #
Tested with:
| Version | |
|---|---|
| Flutter | 3.47.1 (3.44 or later required) |
google_mobile_ads |
9.2.0 |
| Google Mobile Ads SDK | iOS 13.11, Android 25.5 |
| AotterTrek, Android | trek-admob-mediation 5.6.6 (with trek-ads 5.6.6) |
| AotterTrek, iOS | AotterTrekMediation 5.0.1 (with AotterTrekSDK 5.0.1) |
| iOS integration | Swift Package Manager and CocoaPods |
- AotterTrekMediation for iOS supports Google Mobile Ads SDK 12 and 13. A
google_mobile_adsrelease that requires SDK 14 cannot be resolved until AotterTrekMediation supports it. - Ad Manager has not been tested on a device. It takes AotterTrek's Ad
Manager adapter on Android (
trek-gam-mediation, which the package brings in) and the same adapter as AdMob on iOS. - Creatives that move with the page have been watched following the page on an iPhone and on an Android phone.
- Release builds on Android need no R8 (ProGuard) rules from the app: the
plugin carries those the AotterTrek SDK needs, and one for WorkManager,
which Google Mobile Ads brings in. Version 0.1.0 carried none of them:
AotterTrek did not fill in release builds made with it, and one made with
Android Gradle Plugin 9.1 stopped at start-up, as an app with
google_mobile_adsalone does. google_mobile_ads' Next-Gen SDK mode on Android (USE_NEXT_GEN_SDK=true) is not supported: the AotterTrek adapters and the built-in layouts use the regular Google Mobile Ads SDK.
Example #
example/ runs with Google's public test ad units by default; see
example/README.md to see AotterTrek fill.