@rediads/react-native-ads-gam 0.0.0-stage → 0.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/LICENSE +201 -0
- package/README.md +182 -2
- package/android/build.gradle +24 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/rediads/reactnative/gam/RediadsGAMBannerSlot.kt +99 -0
- package/android/src/main/java/com/rediads/reactnative/gam/RediadsGAMModule.kt +306 -0
- package/android/src/main/java/com/rediads/reactnative/gam/RediadsGAMRenderedModule.kt +233 -0
- package/app.plugin.js +2 -0
- package/build/RediadsGAM.d.ts +46 -0
- package/build/RediadsGAM.js +66 -0
- package/build/RediadsGAMBanner.d.ts +26 -0
- package/build/RediadsGAMBanner.js +40 -0
- package/build/RediadsGAMBannerBiddingOnly.d.ts +23 -0
- package/build/RediadsGAMBannerBiddingOnly.js +39 -0
- package/build/RediadsGAMBiddingOnlyFullScreenAd.d.ts +59 -0
- package/build/RediadsGAMBiddingOnlyFullScreenAd.js +120 -0
- package/build/RediadsGAMFullScreenAd.d.ts +70 -0
- package/build/RediadsGAMFullScreenAd.js +132 -0
- package/build/index.d.ts +6 -0
- package/build/index.js +7 -0
- package/build/native.d.ts +45 -0
- package/build/native.js +18 -0
- package/build/renderedNative.d.ts +34 -0
- package/build/renderedNative.js +15 -0
- package/build/types.d.ts +77 -0
- package/build/types.js +1 -0
- package/expo-module.config.json +18 -0
- package/ios/RediadsAdsGAM.podspec +32 -0
- package/ios/RediadsGAMModule.swift +341 -0
- package/ios/RediadsGAMRenderedModule.swift +195 -0
- package/package.json +56 -4
- package/plugin/withRediadsGAM.js +141 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { RediadsAds } from '@rediads/react-native-ads';
|
|
3
|
+
import { requireNativeView } from 'expo';
|
|
4
|
+
import { useEffect, useState } from 'react';
|
|
5
|
+
import { View } from 'react-native';
|
|
6
|
+
import { renderedNative, toRenderedEvent } from './renderedNative';
|
|
7
|
+
const NativeBanner = renderedNative
|
|
8
|
+
? requireNativeView('RediadsGAMRendered')
|
|
9
|
+
: null;
|
|
10
|
+
const SIZES = {
|
|
11
|
+
'320x50': { width: 320, height: 50 },
|
|
12
|
+
'300x250': { width: 300, height: 250 },
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* A GAM banner, SDK-rendered: GAM decides which ad wins; when a Rediads line item wins (it targets
|
|
16
|
+
* `rediads_render = sdk` with Prebid's app-event creative), the Rediads SDK draws our ad itself, with
|
|
17
|
+
* Rediads trackers, MRAID and video. Otherwise GAM's ad shows. It loads when it mounts (after
|
|
18
|
+
* `RediadsAds.start` has finished, if a start is under way) and refreshes itself while on screen.
|
|
19
|
+
* Changing a prop other than `onAdEvent` and `style` replaces it with a new banner.
|
|
20
|
+
*
|
|
21
|
+
* Renders nothing where the native module isn't built in (Expo Go, web).
|
|
22
|
+
*/
|
|
23
|
+
export function RediadsGAMBanner({ placement, adUnitId, size = '300x250', format = 'display', refreshInterval = 0, onAdEvent, style, ...rest }) {
|
|
24
|
+
const [canLoad, setCanLoad] = useState(() => RediadsAds.isStarted);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (canLoad)
|
|
27
|
+
return;
|
|
28
|
+
let mounted = true;
|
|
29
|
+
RediadsAds.whenStarted().then(() => mounted && setCanLoad(true));
|
|
30
|
+
return () => {
|
|
31
|
+
mounted = false;
|
|
32
|
+
};
|
|
33
|
+
}, [canLoad]);
|
|
34
|
+
if (!NativeBanner)
|
|
35
|
+
return null;
|
|
36
|
+
const sizeStyle = SIZES[size];
|
|
37
|
+
if (!canLoad)
|
|
38
|
+
return _jsx(View, { style: [sizeStyle, style], ...rest });
|
|
39
|
+
return (_jsx(NativeBanner, { placement: placement, adUnitId: adUnitId, size: size, format: format, refreshInterval: refreshInterval, onAdEvent: onAdEvent ? (event) => onAdEvent(toRenderedEvent(event.nativeEvent)) : undefined, style: [sizeStyle, style], ...rest }, `${placement}|${adUnitId}|${size}|${format}|${refreshInterval}`));
|
|
40
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type ViewProps } from 'react-native';
|
|
2
|
+
import type { RediadsAdFormat, RediadsGAMBannerSize, RediadsGAMBiddingOnlyEvent } from './types';
|
|
3
|
+
export interface RediadsGAMBannerBiddingOnlyProps extends ViewProps {
|
|
4
|
+
/** The slot name, sent to Rediads as gpid: the slot in Rediads analytics. Matching the GAM ad unit's name is recommended. */
|
|
5
|
+
placement: string;
|
|
6
|
+
/** The GAM ad unit path, "/NETWORK_CODE/ad_unit". */
|
|
7
|
+
adUnitId: string;
|
|
8
|
+
/** Defaults to 300x250. The component takes this size unless `style` says otherwise. */
|
|
9
|
+
size?: RediadsGAMBannerSize;
|
|
10
|
+
/** What Rediads bids with: display (default), video (300x250) or displayAndVideo. */
|
|
11
|
+
format?: RediadsAdFormat;
|
|
12
|
+
/** Every event of this banner: bid, loaded, failed, impression, clicked... */
|
|
13
|
+
onAdEvent?: (event: RediadsGAMBiddingOnlyEvent) => void;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A GAM banner with a Rediads bid in its request (bidding only: GAM renders whichever ad wins). It loads once when it mounts (after
|
|
17
|
+
* `RediadsAds.start` has finished, if a start is under way). Refreshing is up to the app: give the
|
|
18
|
+
* component a new `key` to load a new banner with a new bid. Changing a prop other than `onAdEvent`
|
|
19
|
+
* and `style` does the same.
|
|
20
|
+
*
|
|
21
|
+
* Renders nothing where the native module isn't built in (Expo Go, web).
|
|
22
|
+
*/
|
|
23
|
+
export declare function RediadsGAMBannerBiddingOnly({ placement, adUnitId, size, format, onAdEvent, style, ...rest }: RediadsGAMBannerBiddingOnlyProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { RediadsAds } from '@rediads/react-native-ads';
|
|
3
|
+
import { requireNativeView } from 'expo';
|
|
4
|
+
import { useEffect, useState } from 'react';
|
|
5
|
+
import { View } from 'react-native';
|
|
6
|
+
import { native, toEvent } from './native';
|
|
7
|
+
const NativeBanner = native
|
|
8
|
+
? requireNativeView('RediadsGAM')
|
|
9
|
+
: null;
|
|
10
|
+
const SIZES = {
|
|
11
|
+
'320x50': { width: 320, height: 50 },
|
|
12
|
+
'300x250': { width: 300, height: 250 },
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* A GAM banner with a Rediads bid in its request (bidding only: GAM renders whichever ad wins). It loads once when it mounts (after
|
|
16
|
+
* `RediadsAds.start` has finished, if a start is under way). Refreshing is up to the app: give the
|
|
17
|
+
* component a new `key` to load a new banner with a new bid. Changing a prop other than `onAdEvent`
|
|
18
|
+
* and `style` does the same.
|
|
19
|
+
*
|
|
20
|
+
* Renders nothing where the native module isn't built in (Expo Go, web).
|
|
21
|
+
*/
|
|
22
|
+
export function RediadsGAMBannerBiddingOnly({ placement, adUnitId, size = '300x250', format = 'display', onAdEvent, style, ...rest }) {
|
|
23
|
+
const [canLoad, setCanLoad] = useState(() => RediadsAds.isStarted);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (canLoad)
|
|
26
|
+
return;
|
|
27
|
+
let mounted = true;
|
|
28
|
+
RediadsAds.whenStarted().then(() => mounted && setCanLoad(true));
|
|
29
|
+
return () => {
|
|
30
|
+
mounted = false;
|
|
31
|
+
};
|
|
32
|
+
}, [canLoad]);
|
|
33
|
+
if (!NativeBanner)
|
|
34
|
+
return null;
|
|
35
|
+
const sizeStyle = SIZES[size];
|
|
36
|
+
if (!canLoad)
|
|
37
|
+
return _jsx(View, { style: [sizeStyle, style], ...rest });
|
|
38
|
+
return (_jsx(NativeBanner, { placement: placement, adUnitId: adUnitId, size: size, format: format, onAdEvent: onAdEvent ? (event) => onAdEvent(toEvent(event.nativeEvent)) : undefined, style: [sizeStyle, style], ...rest }, `${placement}|${adUnitId}|${size}|${format}`));
|
|
39
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { RediadsAdFormat, RediadsGAMBiddingOnlyEvent, RediadsGAMBiddingOnlyListener } from './types';
|
|
2
|
+
/** What GAM interstitials and rewarded ads share. */
|
|
3
|
+
declare abstract class GAMBiddingOnlyFullScreenAd {
|
|
4
|
+
/** The slot name, sent to Rediads as gpid: the slot in Rediads analytics. */
|
|
5
|
+
readonly placement: string;
|
|
6
|
+
/** The GAM ad unit path, "/NETWORK_CODE/ad_unit". */
|
|
7
|
+
readonly adUnitId: string;
|
|
8
|
+
readonly format: RediadsAdFormat;
|
|
9
|
+
private readonly id;
|
|
10
|
+
private readonly listeners;
|
|
11
|
+
private loaded;
|
|
12
|
+
private destroyed;
|
|
13
|
+
protected constructor(placement: string, adUnitId: string, format: RediadsAdFormat);
|
|
14
|
+
/** Every event of this ad: bid, loaded, presented, impression, dismissed, rewarded, failed... */
|
|
15
|
+
addListener(listener: RediadsGAMBiddingOnlyListener): {
|
|
16
|
+
remove(): void;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Fetches a Rediads bid, then loads GAM's ad with its keys (GAM loads with or without a bid).
|
|
20
|
+
* Resolves with null when an ad is ready to show, or GAM's reason it has none. Loading again after a
|
|
21
|
+
* show gets the next ad, with a new bid; the same object can be reused.
|
|
22
|
+
*/
|
|
23
|
+
load(): Promise<string | null>;
|
|
24
|
+
/** True once loaded and not shown yet. */
|
|
25
|
+
isReady(): Promise<boolean>;
|
|
26
|
+
/** Shows the ad full screen. If it isn't ready, a `failed` event says why. */
|
|
27
|
+
show(): Promise<void>;
|
|
28
|
+
/** Frees the native ad. The object can't be used again. */
|
|
29
|
+
destroy(): void;
|
|
30
|
+
/** @internal */
|
|
31
|
+
emit(event: RediadsGAMBiddingOnlyEvent): void;
|
|
32
|
+
protected abstract loadNative(id: number): Promise<string | null>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A GAM interstitial with a Rediads bid in its request (bidding only: GAM renders whichever ad wins). Load it ahead of time, show it at a break:
|
|
36
|
+
*
|
|
37
|
+
* ```ts
|
|
38
|
+
* const ad = new RediadsGAMInterstitialBiddingOnly('level_end', '/NETWORK_CODE/level_end');
|
|
39
|
+
* if ((await ad.load()) === null) await ad.show();
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* The GAM ad unit needs an interstitial size (320x480), and the Rediads line items a 320x480 creative.
|
|
43
|
+
*/
|
|
44
|
+
export declare class RediadsGAMInterstitialBiddingOnly extends GAMBiddingOnlyFullScreenAd {
|
|
45
|
+
/** `format`: what Rediads bids with: display (default), video or displayAndVideo. */
|
|
46
|
+
constructor(placement: string, adUnitId: string, options?: {
|
|
47
|
+
format?: RediadsAdFormat;
|
|
48
|
+
});
|
|
49
|
+
protected loadNative(id: number): Promise<string | null>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* A GAM rewarded ad with a Rediads (video) bid in its request. The reward is the GAM ad unit's,
|
|
53
|
+
* reported in a `rewarded` event whichever ad wins. The GAM ad unit must be a rewarded ad unit.
|
|
54
|
+
*/
|
|
55
|
+
export declare class RediadsGAMRewardedBiddingOnly extends GAMBiddingOnlyFullScreenAd {
|
|
56
|
+
constructor(placement: string, adUnitId: string);
|
|
57
|
+
protected loadNative(id: number): Promise<string | null>;
|
|
58
|
+
}
|
|
59
|
+
export type { GAMBiddingOnlyFullScreenAd };
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { RediadsAds } from '@rediads/react-native-ads';
|
|
2
|
+
import { NOT_AVAILABLE, native, toEvent } from './native';
|
|
3
|
+
let nextId = 1;
|
|
4
|
+
/** Ads that have been loaded and not destroyed, by ID, so native events reach them. */
|
|
5
|
+
const live = new Map();
|
|
6
|
+
let nativeSubscription = null;
|
|
7
|
+
function listenToNative() {
|
|
8
|
+
if (nativeSubscription || !native)
|
|
9
|
+
return;
|
|
10
|
+
nativeSubscription = native.addListener('onGAMEvent', (event) => {
|
|
11
|
+
if (event.adId != null)
|
|
12
|
+
live.get(event.adId)?.emit(toEvent(event));
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
/** What GAM interstitials and rewarded ads share. */
|
|
16
|
+
class GAMBiddingOnlyFullScreenAd {
|
|
17
|
+
/** The slot name, sent to Rediads as gpid: the slot in Rediads analytics. */
|
|
18
|
+
placement;
|
|
19
|
+
/** The GAM ad unit path, "/NETWORK_CODE/ad_unit". */
|
|
20
|
+
adUnitId;
|
|
21
|
+
format;
|
|
22
|
+
id = nextId++;
|
|
23
|
+
listeners = new Set();
|
|
24
|
+
loaded = false;
|
|
25
|
+
destroyed = false;
|
|
26
|
+
constructor(placement, adUnitId, format) {
|
|
27
|
+
this.placement = placement;
|
|
28
|
+
this.adUnitId = adUnitId;
|
|
29
|
+
this.format = format;
|
|
30
|
+
}
|
|
31
|
+
/** Every event of this ad: bid, loaded, presented, impression, dismissed, rewarded, failed... */
|
|
32
|
+
addListener(listener) {
|
|
33
|
+
this.listeners.add(listener);
|
|
34
|
+
return { remove: () => this.listeners.delete(listener) };
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Fetches a Rediads bid, then loads GAM's ad with its keys (GAM loads with or without a bid).
|
|
38
|
+
* Resolves with null when an ad is ready to show, or GAM's reason it has none. Loading again after a
|
|
39
|
+
* show gets the next ad, with a new bid; the same object can be reused.
|
|
40
|
+
*/
|
|
41
|
+
async load() {
|
|
42
|
+
if (this.destroyed)
|
|
43
|
+
return 'This ad was destroyed.';
|
|
44
|
+
const nativeModule = native;
|
|
45
|
+
if (!nativeModule)
|
|
46
|
+
return NOT_AVAILABLE;
|
|
47
|
+
listenToNative();
|
|
48
|
+
live.set(this.id, this);
|
|
49
|
+
this.loaded = true;
|
|
50
|
+
await RediadsAds.whenStarted();
|
|
51
|
+
try {
|
|
52
|
+
return await this.loadNative(this.id);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
return String(error);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** True once loaded and not shown yet. */
|
|
59
|
+
async isReady() {
|
|
60
|
+
if (this.destroyed || !this.loaded || !native)
|
|
61
|
+
return false;
|
|
62
|
+
return native.isReady(this.id);
|
|
63
|
+
}
|
|
64
|
+
/** Shows the ad full screen. If it isn't ready, a `failed` event says why. */
|
|
65
|
+
async show() {
|
|
66
|
+
if (this.destroyed)
|
|
67
|
+
return;
|
|
68
|
+
if (!this.loaded || !native) {
|
|
69
|
+
this.emit({ type: 'failed', placement: this.placement, error: 'The ad was not loaded.' });
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
await native.show(this.id);
|
|
73
|
+
}
|
|
74
|
+
/** Frees the native ad. The object can't be used again. */
|
|
75
|
+
destroy() {
|
|
76
|
+
if (this.destroyed)
|
|
77
|
+
return;
|
|
78
|
+
this.destroyed = true;
|
|
79
|
+
live.delete(this.id);
|
|
80
|
+
this.listeners.clear();
|
|
81
|
+
if (this.loaded)
|
|
82
|
+
native?.destroy(this.id).catch(() => { });
|
|
83
|
+
}
|
|
84
|
+
/** @internal */
|
|
85
|
+
emit(event) {
|
|
86
|
+
for (const listener of [...this.listeners])
|
|
87
|
+
listener(event);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* A GAM interstitial with a Rediads bid in its request (bidding only: GAM renders whichever ad wins). Load it ahead of time, show it at a break:
|
|
92
|
+
*
|
|
93
|
+
* ```ts
|
|
94
|
+
* const ad = new RediadsGAMInterstitialBiddingOnly('level_end', '/NETWORK_CODE/level_end');
|
|
95
|
+
* if ((await ad.load()) === null) await ad.show();
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* The GAM ad unit needs an interstitial size (320x480), and the Rediads line items a 320x480 creative.
|
|
99
|
+
*/
|
|
100
|
+
export class RediadsGAMInterstitialBiddingOnly extends GAMBiddingOnlyFullScreenAd {
|
|
101
|
+
/** `format`: what Rediads bids with: display (default), video or displayAndVideo. */
|
|
102
|
+
constructor(placement, adUnitId, options = {}) {
|
|
103
|
+
super(placement, adUnitId, options.format ?? 'display');
|
|
104
|
+
}
|
|
105
|
+
loadNative(id) {
|
|
106
|
+
return native.loadInterstitial(id, this.placement, this.adUnitId, this.format);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* A GAM rewarded ad with a Rediads (video) bid in its request. The reward is the GAM ad unit's,
|
|
111
|
+
* reported in a `rewarded` event whichever ad wins. The GAM ad unit must be a rewarded ad unit.
|
|
112
|
+
*/
|
|
113
|
+
export class RediadsGAMRewardedBiddingOnly extends GAMBiddingOnlyFullScreenAd {
|
|
114
|
+
constructor(placement, adUnitId) {
|
|
115
|
+
super(placement, adUnitId, 'video');
|
|
116
|
+
}
|
|
117
|
+
loadNative(id) {
|
|
118
|
+
return native.loadRewarded(id, this.placement, this.adUnitId);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { type RediadsReward } from '@rediads/react-native-ads';
|
|
2
|
+
import type { RediadsAdFormat, RediadsGAMEvent, RediadsGAMListener, RediadsGAMRenderer } from './types';
|
|
3
|
+
/** What SDK-rendered GAM interstitials and rewarded ads share. */
|
|
4
|
+
declare abstract class GAMFullScreenAd {
|
|
5
|
+
/** The slot name, sent to Rediads as gpid: the slot in Rediads analytics. */
|
|
6
|
+
readonly placement: string;
|
|
7
|
+
/** The GAM ad unit path, "/NETWORK_CODE/ad_unit". */
|
|
8
|
+
readonly adUnitId: string;
|
|
9
|
+
readonly format: RediadsAdFormat;
|
|
10
|
+
private readonly id;
|
|
11
|
+
private readonly listeners;
|
|
12
|
+
private loaded;
|
|
13
|
+
private destroyed;
|
|
14
|
+
protected constructor(placement: string, adUnitId: string, format: RediadsAdFormat);
|
|
15
|
+
/** Every event of this ad: loaded (with `renderer`), presented, displayed, dismissed, failed... */
|
|
16
|
+
addListener(listener: RediadsGAMListener): {
|
|
17
|
+
remove(): void;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Runs the Rediads auction, then GAM's (GAM is asked even without a Rediads bid). Resolves with null
|
|
21
|
+
* when an ad is ready to show, whoever won, or the reason there is none. Loading again after a show
|
|
22
|
+
* gets the next ad; the same object can be reused.
|
|
23
|
+
*/
|
|
24
|
+
load(): Promise<string | null>;
|
|
25
|
+
/** True once loaded and not shown yet. */
|
|
26
|
+
isReady(): Promise<boolean>;
|
|
27
|
+
/** Who will show the loaded ad: `rediads` (our line item won) or `gam`; null before a load. */
|
|
28
|
+
renderer(): Promise<RediadsGAMRenderer | null>;
|
|
29
|
+
/** Shows the ad full screen, whoever won. If it isn't ready, a `failed` event says why. */
|
|
30
|
+
show(): Promise<void>;
|
|
31
|
+
/** Frees the native ad. The object can't be used again. */
|
|
32
|
+
destroy(): void;
|
|
33
|
+
/** @internal */
|
|
34
|
+
emit(event: RediadsGAMEvent): void;
|
|
35
|
+
protected abstract loadNative(id: number): Promise<string | null>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A GAM interstitial, SDK-rendered: GAM decides; when a Rediads line item wins, the Rediads SDK shows
|
|
39
|
+
* our ad (with Rediads trackers), otherwise Google shows GAM's. `show` presents whichever won.
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* const ad = new RediadsGAMInterstitial('level_end', '/NETWORK_CODE/level_end');
|
|
43
|
+
* if ((await ad.load()) === null) await ad.show();
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare class RediadsGAMInterstitial extends GAMFullScreenAd {
|
|
47
|
+
/** `format`: what Rediads bids with: display (default), video or displayAndVideo. */
|
|
48
|
+
constructor(placement: string, adUnitId: string, options?: {
|
|
49
|
+
format?: RediadsAdFormat;
|
|
50
|
+
});
|
|
51
|
+
protected loadNative(id: number): Promise<string | null>;
|
|
52
|
+
}
|
|
53
|
+
export interface RediadsGAMRewardedOptions {
|
|
54
|
+
/** Defaults to display. */
|
|
55
|
+
format?: RediadsAdFormat;
|
|
56
|
+
/** Seconds a Rediads display ad stays on screen before the reward; the SDK's default when left out. */
|
|
57
|
+
displaySeconds?: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A GAM rewarded ad, SDK-rendered. The `rewarded` event hands back **your** `reward`, once, whichever
|
|
61
|
+
* ad won: a Rediads ad grants it by the Rediads rules, GAM's when Google reports it. The GAM ad unit
|
|
62
|
+
* must be a rewarded ad unit whose Rediads line items use Prebid's rewarded app-event VAST.
|
|
63
|
+
*/
|
|
64
|
+
export declare class RediadsGAMRewarded extends GAMFullScreenAd {
|
|
65
|
+
readonly reward: RediadsReward;
|
|
66
|
+
readonly displaySeconds: number;
|
|
67
|
+
constructor(placement: string, adUnitId: string, reward: RediadsReward, options?: RediadsGAMRewardedOptions);
|
|
68
|
+
protected loadNative(id: number): Promise<string | null>;
|
|
69
|
+
}
|
|
70
|
+
export type { GAMFullScreenAd };
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { RediadsAds } from '@rediads/react-native-ads';
|
|
2
|
+
import { NOT_AVAILABLE } from './native';
|
|
3
|
+
import { renderedNative, toRenderedEvent } from './renderedNative';
|
|
4
|
+
let nextId = 1;
|
|
5
|
+
/** Ads that have been loaded and not destroyed, by ID, so native events reach them. */
|
|
6
|
+
const live = new Map();
|
|
7
|
+
let nativeSubscription = null;
|
|
8
|
+
function listenToNative() {
|
|
9
|
+
if (nativeSubscription || !renderedNative)
|
|
10
|
+
return;
|
|
11
|
+
nativeSubscription = renderedNative.addListener('onRenderedEvent', (event) => {
|
|
12
|
+
if (event.adId != null)
|
|
13
|
+
live.get(event.adId)?.emit(toRenderedEvent(event));
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/** What SDK-rendered GAM interstitials and rewarded ads share. */
|
|
17
|
+
class GAMFullScreenAd {
|
|
18
|
+
/** The slot name, sent to Rediads as gpid: the slot in Rediads analytics. */
|
|
19
|
+
placement;
|
|
20
|
+
/** The GAM ad unit path, "/NETWORK_CODE/ad_unit". */
|
|
21
|
+
adUnitId;
|
|
22
|
+
format;
|
|
23
|
+
id = nextId++;
|
|
24
|
+
listeners = new Set();
|
|
25
|
+
loaded = false;
|
|
26
|
+
destroyed = false;
|
|
27
|
+
constructor(placement, adUnitId, format) {
|
|
28
|
+
this.placement = placement;
|
|
29
|
+
this.adUnitId = adUnitId;
|
|
30
|
+
this.format = format;
|
|
31
|
+
}
|
|
32
|
+
/** Every event of this ad: loaded (with `renderer`), presented, displayed, dismissed, failed... */
|
|
33
|
+
addListener(listener) {
|
|
34
|
+
this.listeners.add(listener);
|
|
35
|
+
return { remove: () => this.listeners.delete(listener) };
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Runs the Rediads auction, then GAM's (GAM is asked even without a Rediads bid). Resolves with null
|
|
39
|
+
* when an ad is ready to show, whoever won, or the reason there is none. Loading again after a show
|
|
40
|
+
* gets the next ad; the same object can be reused.
|
|
41
|
+
*/
|
|
42
|
+
async load() {
|
|
43
|
+
if (this.destroyed)
|
|
44
|
+
return 'This ad was destroyed.';
|
|
45
|
+
const nativeModule = renderedNative;
|
|
46
|
+
if (!nativeModule)
|
|
47
|
+
return NOT_AVAILABLE;
|
|
48
|
+
listenToNative();
|
|
49
|
+
live.set(this.id, this);
|
|
50
|
+
this.loaded = true;
|
|
51
|
+
await RediadsAds.whenStarted();
|
|
52
|
+
try {
|
|
53
|
+
return await this.loadNative(this.id);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
return String(error);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** True once loaded and not shown yet. */
|
|
60
|
+
async isReady() {
|
|
61
|
+
if (this.destroyed || !this.loaded || !renderedNative)
|
|
62
|
+
return false;
|
|
63
|
+
return renderedNative.isReady(this.id);
|
|
64
|
+
}
|
|
65
|
+
/** Who will show the loaded ad: `rediads` (our line item won) or `gam`; null before a load. */
|
|
66
|
+
async renderer() {
|
|
67
|
+
if (this.destroyed || !this.loaded || !renderedNative)
|
|
68
|
+
return null;
|
|
69
|
+
const value = await renderedNative.renderer(this.id);
|
|
70
|
+
return value === 'rediads' || value === 'gam' ? value : null;
|
|
71
|
+
}
|
|
72
|
+
/** Shows the ad full screen, whoever won. If it isn't ready, a `failed` event says why. */
|
|
73
|
+
async show() {
|
|
74
|
+
if (this.destroyed)
|
|
75
|
+
return;
|
|
76
|
+
if (!this.loaded || !renderedNative) {
|
|
77
|
+
this.emit({ type: 'failed', placement: this.placement, error: 'The ad was not loaded.' });
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
await renderedNative.show(this.id);
|
|
81
|
+
}
|
|
82
|
+
/** Frees the native ad. The object can't be used again. */
|
|
83
|
+
destroy() {
|
|
84
|
+
if (this.destroyed)
|
|
85
|
+
return;
|
|
86
|
+
this.destroyed = true;
|
|
87
|
+
live.delete(this.id);
|
|
88
|
+
this.listeners.clear();
|
|
89
|
+
if (this.loaded)
|
|
90
|
+
renderedNative?.destroy(this.id).catch(() => { });
|
|
91
|
+
}
|
|
92
|
+
/** @internal */
|
|
93
|
+
emit(event) {
|
|
94
|
+
for (const listener of [...this.listeners])
|
|
95
|
+
listener(event);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* A GAM interstitial, SDK-rendered: GAM decides; when a Rediads line item wins, the Rediads SDK shows
|
|
100
|
+
* our ad (with Rediads trackers), otherwise Google shows GAM's. `show` presents whichever won.
|
|
101
|
+
*
|
|
102
|
+
* ```ts
|
|
103
|
+
* const ad = new RediadsGAMInterstitial('level_end', '/NETWORK_CODE/level_end');
|
|
104
|
+
* if ((await ad.load()) === null) await ad.show();
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export class RediadsGAMInterstitial extends GAMFullScreenAd {
|
|
108
|
+
/** `format`: what Rediads bids with: display (default), video or displayAndVideo. */
|
|
109
|
+
constructor(placement, adUnitId, options = {}) {
|
|
110
|
+
super(placement, adUnitId, options.format ?? 'display');
|
|
111
|
+
}
|
|
112
|
+
loadNative(id) {
|
|
113
|
+
return renderedNative.loadInterstitial(id, this.placement, this.adUnitId, this.format);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* A GAM rewarded ad, SDK-rendered. The `rewarded` event hands back **your** `reward`, once, whichever
|
|
118
|
+
* ad won: a Rediads ad grants it by the Rediads rules, GAM's when Google reports it. The GAM ad unit
|
|
119
|
+
* must be a rewarded ad unit whose Rediads line items use Prebid's rewarded app-event VAST.
|
|
120
|
+
*/
|
|
121
|
+
export class RediadsGAMRewarded extends GAMFullScreenAd {
|
|
122
|
+
reward;
|
|
123
|
+
displaySeconds;
|
|
124
|
+
constructor(placement, adUnitId, reward, options = {}) {
|
|
125
|
+
super(placement, adUnitId, options.format ?? 'display');
|
|
126
|
+
this.reward = { type: reward.type, amount: Math.trunc(reward.amount) };
|
|
127
|
+
this.displaySeconds = Math.max(0, Math.trunc(options.displaySeconds ?? 0));
|
|
128
|
+
}
|
|
129
|
+
loadNative(id) {
|
|
130
|
+
return renderedNative.loadRewarded(id, this.placement, this.adUnitId, this.reward.type, this.reward.amount, this.format, this.displaySeconds);
|
|
131
|
+
}
|
|
132
|
+
}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { RediadsGAM, type RediadsGAMStartOptions } from './RediadsGAM';
|
|
2
|
+
export { RediadsGAMBanner, type RediadsGAMBannerProps } from './RediadsGAMBanner';
|
|
3
|
+
export { RediadsGAMInterstitial, RediadsGAMRewarded, type GAMFullScreenAd, type RediadsGAMRewardedOptions, } from './RediadsGAMFullScreenAd';
|
|
4
|
+
export { RediadsGAMBannerBiddingOnly, type RediadsGAMBannerBiddingOnlyProps, } from './RediadsGAMBannerBiddingOnly';
|
|
5
|
+
export { RediadsGAMInterstitialBiddingOnly, RediadsGAMRewardedBiddingOnly, type GAMBiddingOnlyFullScreenAd, } from './RediadsGAMBiddingOnlyFullScreenAd';
|
|
6
|
+
export type * from './types';
|
package/build/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { RediadsGAM } from './RediadsGAM';
|
|
2
|
+
// SDK-rendered: GAM decides, the Rediads SDK draws a Rediads win.
|
|
3
|
+
export { RediadsGAMBanner } from './RediadsGAMBanner';
|
|
4
|
+
export { RediadsGAMInterstitial, RediadsGAMRewarded, } from './RediadsGAMFullScreenAd';
|
|
5
|
+
// Bidding only: Rediads adds its keys to the GAM request, GAM draws whichever ad wins.
|
|
6
|
+
export { RediadsGAMBannerBiddingOnly, } from './RediadsGAMBannerBiddingOnly';
|
|
7
|
+
export { RediadsGAMInterstitialBiddingOnly, RediadsGAMRewardedBiddingOnly, } from './RediadsGAMBiddingOnlyFullScreenAd';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { NativeModule } from 'expo';
|
|
2
|
+
import type { RediadsAdFormat, RediadsGAMBiddingOnlyEvent, RediadsGAMBiddingOnlyEventType, RediadsGAMTargeting } from './types';
|
|
3
|
+
/** An event of an interstitial or rewarded ad, or of a banner, as the native code sends it. */
|
|
4
|
+
export interface NativeGAMEvent {
|
|
5
|
+
/** Interstitials and rewarded ads only. */
|
|
6
|
+
adId?: number;
|
|
7
|
+
type: RediadsGAMBiddingOnlyEventType;
|
|
8
|
+
placement: string;
|
|
9
|
+
error?: string | null;
|
|
10
|
+
targeting?: RediadsGAMTargeting | null;
|
|
11
|
+
lineItemId?: string | null;
|
|
12
|
+
creativeId?: string | null;
|
|
13
|
+
rewardType?: string | null;
|
|
14
|
+
rewardAmount?: number | null;
|
|
15
|
+
}
|
|
16
|
+
type NativeEvents = {
|
|
17
|
+
onGAMEvent: (event: NativeGAMEvent) => void;
|
|
18
|
+
};
|
|
19
|
+
/** ios/RediadsGAMModule.swift and android/.../RediadsGAMModule.kt. */
|
|
20
|
+
declare class RediadsGAMNativeModule extends NativeModule<NativeEvents> {
|
|
21
|
+
/** Google Mobile Ads SDK version. */
|
|
22
|
+
readonly googleSdkVersion: string;
|
|
23
|
+
/** Starts Google's SDK; resolves when it is ready. */
|
|
24
|
+
start(testDeviceIds: string[]): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Fetches a Rediads bid. `type`: banner, interstitial or rewarded; `size`: banners only.
|
|
27
|
+
* Resolves with the targeting keys and the reason there are none.
|
|
28
|
+
*/
|
|
29
|
+
fetchTargeting(type: string, placement: string, size: string, format: RediadsAdFormat): Promise<{
|
|
30
|
+
targeting: RediadsGAMTargeting;
|
|
31
|
+
error: string | null;
|
|
32
|
+
}>;
|
|
33
|
+
/** Creates a new ad under `adId` (replacing an earlier one) and loads it. */
|
|
34
|
+
loadInterstitial(adId: number, placement: string, adUnitId: string, format: RediadsAdFormat): Promise<string | null>;
|
|
35
|
+
loadRewarded(adId: number, placement: string, adUnitId: string): Promise<string | null>;
|
|
36
|
+
isReady(adId: number): Promise<boolean>;
|
|
37
|
+
show(adId: number): Promise<void>;
|
|
38
|
+
destroy(adId: number): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
/** Null in Expo Go, on web, and in builds made before this package was added. */
|
|
41
|
+
export declare const native: RediadsGAMNativeModule | null;
|
|
42
|
+
export declare const NOT_AVAILABLE = "The Rediads GAM native module is not in this build (Expo Go, web, or an old build).";
|
|
43
|
+
/** The public event from a native one. */
|
|
44
|
+
export declare function toEvent(event: NativeGAMEvent): RediadsGAMBiddingOnlyEvent;
|
|
45
|
+
export {};
|
package/build/native.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { requireOptionalNativeModule } from 'expo';
|
|
2
|
+
/** Null in Expo Go, on web, and in builds made before this package was added. */
|
|
3
|
+
export const native = requireOptionalNativeModule('RediadsGAM');
|
|
4
|
+
export const NOT_AVAILABLE = 'The Rediads GAM native module is not in this build (Expo Go, web, or an old build).';
|
|
5
|
+
/** The public event from a native one. */
|
|
6
|
+
export function toEvent(event) {
|
|
7
|
+
return {
|
|
8
|
+
type: event.type,
|
|
9
|
+
placement: event.placement,
|
|
10
|
+
...(event.error ? { error: event.error } : {}),
|
|
11
|
+
...(event.targeting ? { targeting: event.targeting } : {}),
|
|
12
|
+
...(event.lineItemId ? { lineItemId: event.lineItemId } : {}),
|
|
13
|
+
...(event.creativeId ? { creativeId: event.creativeId } : {}),
|
|
14
|
+
...(event.type === 'rewarded'
|
|
15
|
+
? { reward: { type: event.rewardType ?? '', amount: event.rewardAmount ?? 0 } }
|
|
16
|
+
: {}),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { RediadsAdEventType, RediadsAdFormat } from '@rediads/react-native-ads';
|
|
2
|
+
import { NativeModule } from 'expo';
|
|
3
|
+
import type { RediadsGAMEvent, RediadsGAMRenderer } from './types';
|
|
4
|
+
/** An event of an SDK-rendered GAM ad, as the native code sends it. */
|
|
5
|
+
export interface NativeRenderedEvent {
|
|
6
|
+
/** Interstitials and rewarded ads only. */
|
|
7
|
+
adId?: number;
|
|
8
|
+
type: RediadsAdEventType;
|
|
9
|
+
placement: string;
|
|
10
|
+
error?: string | null;
|
|
11
|
+
/** `none` before a load or after a failed one. */
|
|
12
|
+
renderer?: RediadsGAMRenderer | 'none' | null;
|
|
13
|
+
rewardType?: string | null;
|
|
14
|
+
rewardAmount?: number | null;
|
|
15
|
+
}
|
|
16
|
+
type NativeEvents = {
|
|
17
|
+
onRenderedEvent: (event: NativeRenderedEvent) => void;
|
|
18
|
+
};
|
|
19
|
+
/** ios/RediadsGAMRenderedModule.swift and android/.../RediadsGAMRenderedModule.kt. */
|
|
20
|
+
declare class RediadsGAMRenderedNativeModule extends NativeModule<NativeEvents> {
|
|
21
|
+
/** Creates a new ad under `adId` (replacing an earlier one) and loads it. */
|
|
22
|
+
loadInterstitial(adId: number, placement: string, adUnitId: string, format: RediadsAdFormat): Promise<string | null>;
|
|
23
|
+
loadRewarded(adId: number, placement: string, adUnitId: string, rewardType: string, rewardAmount: number, format: RediadsAdFormat, displaySeconds: number): Promise<string | null>;
|
|
24
|
+
isReady(adId: number): Promise<boolean>;
|
|
25
|
+
/** Who will show the loaded ad: rediads, gam or none. */
|
|
26
|
+
renderer(adId: number): Promise<RediadsGAMRenderer | 'none'>;
|
|
27
|
+
show(adId: number): Promise<void>;
|
|
28
|
+
destroy(adId: number): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
/** Null in Expo Go, on web, and in builds made before this package was added. */
|
|
31
|
+
export declare const renderedNative: RediadsGAMRenderedNativeModule | null;
|
|
32
|
+
/** The public event from a native one. */
|
|
33
|
+
export declare function toRenderedEvent(event: NativeRenderedEvent): RediadsGAMEvent;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { requireOptionalNativeModule } from 'expo';
|
|
2
|
+
/** Null in Expo Go, on web, and in builds made before this package was added. */
|
|
3
|
+
export const renderedNative = requireOptionalNativeModule('RediadsGAMRendered');
|
|
4
|
+
/** The public event from a native one. */
|
|
5
|
+
export function toRenderedEvent(event) {
|
|
6
|
+
return {
|
|
7
|
+
type: event.type,
|
|
8
|
+
placement: event.placement,
|
|
9
|
+
...(event.error ? { error: event.error } : {}),
|
|
10
|
+
...(event.renderer && event.renderer !== 'none' ? { renderer: event.renderer } : {}),
|
|
11
|
+
...(event.type === 'rewarded'
|
|
12
|
+
? { reward: { type: event.rewardType ?? '', amount: event.rewardAmount ?? 0 } }
|
|
13
|
+
: {}),
|
|
14
|
+
};
|
|
15
|
+
}
|