@rediads/react-native-ads-gam
v0.1.0
Published
Rediads bids in Google Ad Manager for React Native apps: SDK-rendered (GAM decides, the Rediads SDK draws a Rediads win) or bidding only (the hb_ keys for your GAM requests, GAM draws).
Maintainers
Readme
@rediads/react-native-ads-gam
Rediads bids in Google Ad Manager (GAM) for React Native apps on iOS and Android (Expo, or bare with
Expo modules support). Before each GAM request the package runs the Rediads auction and adds the bid's
keys to the request (hb_pb price bucket, hb_bidder, hb_cache_id, ...). GAM runs its own auction
and decides. Two modes, per slot:
| | SDK-rendered (RediadsGAMBanner, RediadsGAMInterstitial, RediadsGAMRewarded) | Bidding only (RediadsGAM.fetchTargeting, RediadsGAM*BiddingOnly) |
|---|---|---|
| Who draws a Rediads win | The Rediads SDK, with Rediads trackers, MRAID and video | GAM: the Prebid Universal Creative loads the bid from the Rediads cache |
| Rediads impression and viewability | Yes | Not yet |
| GAM creative for Rediads line items | Prebid's "app event" creative, line items targeting rediads_render = sdk | Universal Creative (SafeFrame off), line items excluding rediads_render = sdk |
| Banner refresh | Automatic (refreshInterval) | Load again (a new key) |
| Loads GAM through react-native-google-mobile-ads | No (the SDK loads GAM; both can be in one app) | Yes, through fetchTargeting |
Every request from the SDK-rendered classes carries rediads_render=sdk.
import { RediadsAds } from '@rediads/react-native-ads';
import { RediadsGAM, RediadsGAMBanner, RediadsGAMInterstitial } from '@rediads/react-native-ads-gam';
await RediadsAds.start({ accountId: 'YOUR_ACCOUNT_ID' });
await RediadsGAM.start();
<RediadsGAMBanner placement="home_mrec" adUnitId="/NETWORK_CODE/home_mrec" size="300x250" />;
const ad = new RediadsGAMInterstitial('level_end', '/NETWORK_CODE/level_end');
if ((await ad.load()) === null) await ad.show();
// Bidding only, keys for another GAM library
const { targeting } = await RediadsGAM.fetchTargeting({ type: 'banner', placement: 'home_mrec' });Requirements
@rediads/react-native-adsof the same version (it starts the Rediads SDK).- Expo SDK 58 or later (React Native 0.88): an Expo app, or a bare React Native app with Expo modules.
- iOS 16.4 or later, and a development build (not Expo Go).
- Supported: Android 10+ (builds with minSdk 24; ads stay off below Android 10). Below Android 10,
start, every load and every banner answer with the error "Android 10 or newer is needed (this device runs API N); the Rediads SDK stays off." (the Android SDK'sUNSUPPORTED_OS), without a request; in the AdMob and GAM packages it comes as thebidevent's error and Google's ad still loads. Nothing to fix in the app. - Google's Mobile Ads SDK: the app's own version is used and never raised. iOS 12.0.0 or later, Android (play-services-ads) 23.0.0 or later. See Google's Mobile Ads SDK.
Install
Expo apps
npm install @rediads/react-native-ads @rediads/react-native-ads-gamIn app.json:
"plugins": [
"@rediads/react-native-ads",
["@rediads/react-native-ads-gam", {
"iosAppId": "ca-app-pub-XXXX~YYYY",
"androidAppId": "ca-app-pub-XXXX~ZZZZ"
}]
]Then a development build: npx expo prebuild --clean, then npx expo run:ios and
npx expo run:android, or eas build --profile development.
- The app IDs (Ad Manager → Inventory → Apps, or AdMob) are optional: without them the plugin marks
the app as an Ad Manager app (
GADIsAdManagerApp,com.google.android.gms.ads.AD_MANAGER_APP), which Google's SDK accepts instead of an ID. If another plugin sets the app ID (react-native-google-mobile-ads,@rediads/react-native-ads-admob), give the same ID here. - Like
@rediads/react-native-ads, the plugin adds Rediads' pod list to the Podfile sources (once). On Android the SDK comes from Maven Central; for Google's SDK see Google's Mobile Ads SDK.
Bare React Native apps
- Set up
@rediads/react-native-adsfirst (Expo modules, the two Podfilesourcelines; see its README). npm install @rediads/react-native-ads-gam- iOS: in
Info.plist,GADApplicationIdentifier= your app ID, orGADIsAdManagerApp= YES; and Google's SKAdNetwork IDcstr6suwn9.skadnetworkinSKAdNetworkItems. Thencd ios && pod install. - Android: in
AndroidManifest.xml, inside<application>, either<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-XXXX~ZZZZ"/>or<meta-data android:name="com.google.android.gms.ads.AD_MANAGER_APP" android:value="true"/>.
What gets installed
The JavaScript API (compiled, with types), the native bridge as Swift and Kotlin source, and the
Rediads SDK's GAM part as binaries: on iOS the pod RediadsGAM 0.1.4 (with RediadsGAMEventHandlers),
on Android com.rediads:rediads-gam:0.1.1 (with its event handlers). Google's Mobile Ads SDK is the
app's own: see below.
Google's Mobile Ads SDK
A publisher keeps its own version of Google's Mobile Ads SDK; the Rediads packages never raise it.
- iOS: the pods ask for
Google-Mobile-Ads-SDK12.0.0 or later. CocoaPods uses the version the app (or react-native-google-mobile-ads) pins; with nothing pinned it takes the newest. - Android: the Rediads SDK (0.1.1) doesn't bring play-services-ads; it works with 23.0.0 or later.
The version the app (or react-native-google-mobile-ads) asks for is used, even an older one. Only when
nothing in the app asks for play-services-ads does this package add one: 25.5.0, as a Gradle "prefer"
(the weakest kind, so any other declaration wins). To prefer another version, or to add nothing
(
"none", when the app brings play-services-ads some other way), set the config plugin'sandroidGoogleMobileAdsVersionoption ("25.5.0","24.6.0","none"), or in a bare app the Gradle propertyrediadsGoogleMobileAdsVersioninandroid/gradle.properties. - Below 23.0.0 on Android the Rediads SDK logs an error and gets no Rediads bids; Google's ads still load.
With react-native-google-mobile-ads
An app can keep react-native-google-mobile-ads for its other ads, consent and initialization: both packages use the one copy of Google's Mobile Ads SDK.
- Versions: react-native-google-mobile-ads 17.1 or later (the versions for React Native 0.88). It pins Google's SDK exactly (17.4.0: iOS 13.10.0, Android 25.5.0), and that pin is what the app gets on both platforms: the Rediads pods take Google's SDK 12.0.0 or later, and on Android this package's own play-services-ads is only a "prefer", which the pin overrides. A react-native-google-mobile-ads release that moves to Google's SDK 14 needs a Rediads release that supports it.
- App IDs: give them once, in either plugin. An ID given only to react-native-google-mobile-ads's
plugin is used by this one too; two different IDs stop
expo prebuildwith an error. With react-native-google-mobile-ads in the app the IDs are required: its library manifest declares the app ID item, so the Ad Manager flag alone isn't enough. - Android: keep react-native-google-mobile-ads on Google's classic SDK (its
androidSdkoption"classic", the default). Its"nextgen"option replaces play-services-ads, which the Rediads SDK is built on; the Android build then stops with an error that says so. - Starting Google's SDK:
mobileAds().initialize()orRediadsGAM.start(), or both. - Test devices:
RediadsGAM.start({ testDeviceIds })replaces the list set withmobileAds().setRequestConfiguration(); set it in one place. - Consent:
AdsConsent(Google's UMP) stores the standard IAB consent strings, which the Rediads SDK reads. Gather consent before the first ad loads. - Bare React Native apps: set each app ID once. On Android, react-native-google-mobile-ads's
library manifest declares the app ID item from its
app.jsonkey; if the app'sAndroidManifest.xmldeclares it too, addtools:replace="android:value"to that item.
SDK-rendered
import { RediadsAds } from '@rediads/react-native-ads';
import { RediadsGAM, RediadsGAMBanner, RediadsGAMInterstitial, RediadsGAMRewarded } from '@rediads/react-native-ads-gam';
await RediadsAds.start({ accountId: 'YOUR_ACCOUNT_ID' });
await RediadsGAM.start(); // Google's SDK; skip if another library starts it
// Refreshes itself every 60 s (refreshInterval: 15 to 120), each time with a new auction
<RediadsGAMBanner placement="home_mrec" adUnitId="/NETWORK_CODE/home_mrec" size="300x250"
format="video" onAdEvent={(e) => e.type === 'loaded' && console.log('drawn by', e.renderer)} />
const interstitial = new RediadsGAMInterstitial('level_end', '/NETWORK_CODE/level_end');
if ((await interstitial.load()) === null) await interstitial.show(); // shows whichever ad won
const rewarded = new RediadsGAMRewarded('extra_life', '/NETWORK_CODE/extra_life',
{ type: 'lives', amount: 1 }, { format: 'video' });
rewarded.addListener((e) => { if (e.type === 'rewarded') grantLives(e.reward!.amount); }); // your reward- Events are those of
@rediads/react-native-ads(loaded,displayed,failed,clicked,presented,dismissed,leftApplication,rewarded), whichever ad won.loadedcarriesrenderer:rediadswhen a Rediads line item won and the Rediads SDK draws the ad,gamwhen GAM's demand won and Google's view shows it. Full-screen ads also haverenderer(). - Rewarded hands back your reward once, whoever won: a Rediads ad by the Rediads rules (video at
completion, display after
displaySeconds), GAM's when Google reports it. The GAM ad unit must be a rewarded ad unit whose Rediads line items use Prebid's rewarded app-event VAST.
Bidding only
Only the keys, for apps that already load GAM ads with react-native-google-mobile-ads (or another library). Its request options take custom targeting, so the keys go straight in:
import { RediadsGAM } from '@rediads/react-native-ads-gam'; import { GAMBannerAd, BannerAdSize } from 'react-native-google-mobile-ads'; const { targeting, error } = await RediadsGAM.fetchTargeting({ type: 'banner', placement: 'home_mrec', size: '300x250' }); <GAMBannerAd unitId="/NETWORK_CODE/home_mrec" sizes={[BannerAdSize.MEDIUM_RECTANGLE]} requestOptions={{ customTargeting: targeting }} /> // Interstitial / rewarded: { type: 'interstitial', placement, format } / { type: 'rewarded', placement }Load GAM whatever the result (
targetingis empty without a bid), and fetch again for each request: a bid serves once.GAM ads loaded by this package, with the SDK's bidding-only classes:
import { RediadsGAMBannerBiddingOnly, RediadsGAMInterstitialBiddingOnly, RediadsGAMRewardedBiddingOnly, } from '@rediads/react-native-ads-gam'; // Loads once; a new `key` loads a new banner with a new bid <RediadsGAMBannerBiddingOnly key={refreshCount} placement="home_mrec" adUnitId="/NETWORK_CODE/home_mrec" size="300x250" onAdEvent={(e) => console.log(e)} /> const interstitial = new RediadsGAMInterstitialBiddingOnly('level_end', '/NETWORK_CODE/level_end', { format: 'video' }); if ((await interstitial.load()) === null) await interstitial.show(); const rewarded = new RediadsGAMRewardedBiddingOnly('extra_life', '/NETWORK_CODE/extra_life'); // video bids rewarded.addListener((e) => { if (e.type === 'rewarded') grantReward(); }); // the GAM ad unit's rewardEvents:
bid(withtargeting, the keys added, orerror),loaded(with GAM'slineItemIdandcreativeId),failed,impression,clicked,presented,dismissed,rewarded(withreward).
API
| | |
|---|---|
| RediadsGAM.start({ testDeviceIds }) | Starts Google's SDK |
| RediadsGAM.fetchTargeting({ type, placement, size, format }) | Bidding only: { targeting, error }; type banner, interstitial or rewarded |
| RediadsGAM.isAvailable, .googleSdkVersion, .PACKAGE_VERSION | |
| <RediadsGAMBanner placement adUnitId size format refreshInterval onAdEvent /> | SDK-rendered; 320x50 or 300x250 |
| new RediadsGAMInterstitial(placement, adUnitId, { format }) | SDK-rendered: load(), isReady(), renderer(), show(), addListener(), destroy() |
| new RediadsGAMRewarded(placement, adUnitId, reward, { format, displaySeconds }) | The same |
| <RediadsGAMBannerBiddingOnly placement adUnitId size format onAdEvent /> | Bidding only; loads once |
| new RediadsGAMInterstitialBiddingOnly(placement, adUnitId, { format }) | Bidding only: load(), isReady(), show(), addListener(), destroy() |
| new RediadsGAMRewardedBiddingOnly(placement, adUnitId) | The same; video bids |
Config plugin options
iosAppId and androidAppId (optional, see above), and, for SDK development only, iosSdkPath: a
local iOS SDK checkout (the same as @rediads/react-native-ads's), from which the RediadsGAM and
RediadsGAMEventHandlers pods are then taken by path.
License
Apache-2.0
