react-native-purchases-admob 0.0.0-stage → 10.15.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.
@@ -0,0 +1,150 @@
1
+ import Purchases, { AdCaptureMethod, AdMediatorName, AdRevenuePrecision } from "react-native-purchases";
2
+ import { Platform } from "react-native";
3
+ export function logWarning(message) {
4
+ // tslint:disable-next-line:no-console
5
+ console.warn(`[react-native-purchases-admob] ${message}`);
6
+ }
7
+
8
+ // The data types mark this field @internal, hence the assertions below.
9
+ const captureMethod = AdCaptureMethod.reactNativeAdMobAdapter;
10
+
11
+ /**
12
+ * `react-native-google-mobile-ads` reports load failures with a string reason
13
+ * rather than the platform SDK's numeric error code, and the two SDKs number
14
+ * their codes differently. Each table inverts the library's own native mapping
15
+ * for that platform (ReactNativeGoogleMobileAdsCommon.java and
16
+ * RNGoogleMobileAdsOwnedMappers.m), so the emitted number matches what the
17
+ * native integration on the same platform reports.
18
+ */
19
+ const androidErrorCodes = {
20
+ "internal-error": 0,
21
+ "invalid-request": 1,
22
+ "network-error": 2,
23
+ "no-fill": 3,
24
+ "app-id-missing": 8,
25
+ "mediation-no-fill": 9,
26
+ "request-id-mismatch": 10,
27
+ "invalid-ad-string": 11
28
+ };
29
+ const iosErrorCodes = {
30
+ "invalid-request": 0,
31
+ "no-fill": 1,
32
+ "network-error": 2,
33
+ "server-error": 3,
34
+ timeout: 5,
35
+ "mediation-data-error": 7,
36
+ "mediation-adapter-error": 8,
37
+ "mediation-invalid-ad-size": 10,
38
+ "internal-error": 11,
39
+ "invalid-argument": 12,
40
+ "ad-already-used": 19,
41
+ "app-id-missing": 20,
42
+ "invalid-ad-string": 21
43
+ };
44
+ export function mediatorErrorCode(reason) {
45
+ if (!reason) {
46
+ return null;
47
+ }
48
+ const table = Platform.OS === "ios" ? iosErrorCodes : androidErrorCodes;
49
+ const mapped = table[reason];
50
+ if (mapped !== undefined) {
51
+ return mapped;
52
+ }
53
+ const numeric = Number(reason);
54
+ return Number.isInteger(numeric) ? numeric : null;
55
+ }
56
+ export function revenueMicrosFrom(paid) {
57
+ if (paid.valueMicros != null) {
58
+ const micros = Number(paid.valueMicros);
59
+ if (Number.isFinite(micros)) {
60
+ return Math.round(micros);
61
+ }
62
+ }
63
+ return Math.round(paid.value * 1_000_000);
64
+ }
65
+ export function precisionFrom(precision) {
66
+ switch (precision) {
67
+ case 1:
68
+ return AdRevenuePrecision.estimated;
69
+ case 2:
70
+ return AdRevenuePrecision.publisherDefined;
71
+ case 3:
72
+ return AdRevenuePrecision.exact;
73
+ default:
74
+ return AdRevenuePrecision.unknown;
75
+ }
76
+ }
77
+ function swallow(event, promise) {
78
+ promise.catch(e => logWarning(`Could not track ${event}: ${e}`));
79
+ }
80
+ export const AdMobTracker = {
81
+ trackLoaded(state) {
82
+ swallow("ad loaded", Purchases.adTracker.trackAdLoaded({
83
+ networkName: state.networkName,
84
+ mediatorName: AdMediatorName.adMob,
85
+ adFormat: state.adFormat,
86
+ placement: state.loadPlacement,
87
+ adUnitId: state.adUnitId,
88
+ impressionId: state.impressionId,
89
+ captureMethod
90
+ }));
91
+ },
92
+ trackFailedToLoad(adUnitId, adFormat, placement, reason) {
93
+ swallow("ad failed to load", Purchases.adTracker.trackAdFailedToLoad({
94
+ mediatorName: AdMediatorName.adMob,
95
+ adFormat,
96
+ placement,
97
+ adUnitId,
98
+ mediatorErrorCode: mediatorErrorCode(reason),
99
+ captureMethod
100
+ }));
101
+ },
102
+ trackDisplayed(state) {
103
+ swallow("ad displayed", Purchases.adTracker.trackAdDisplayed({
104
+ networkName: state.networkName,
105
+ mediatorName: AdMediatorName.adMob,
106
+ adFormat: state.adFormat,
107
+ placement: state.placement,
108
+ adUnitId: state.adUnitId,
109
+ impressionId: state.impressionId,
110
+ captureMethod
111
+ }));
112
+ },
113
+ trackOpened(state) {
114
+ swallow("ad opened", Purchases.adTracker.trackAdOpened({
115
+ networkName: state.networkName,
116
+ mediatorName: AdMediatorName.adMob,
117
+ adFormat: state.adFormat,
118
+ placement: state.placement,
119
+ adUnitId: state.adUnitId,
120
+ impressionId: state.impressionId,
121
+ captureMethod
122
+ }));
123
+ },
124
+ trackRewardEarnedUnverified(state) {
125
+ swallow("reward earned", Purchases.adTracker.trackAdRewardEarnedUnverified({
126
+ networkName: state.networkName,
127
+ mediatorName: AdMediatorName.adMob,
128
+ adFormat: state.adFormat,
129
+ placement: state.placement,
130
+ adUnitId: state.adUnitId,
131
+ impressionId: state.impressionId,
132
+ captureMethod
133
+ }));
134
+ },
135
+ trackRevenue(state, paid) {
136
+ swallow("ad revenue", Purchases.adTracker.trackAdRevenue({
137
+ networkName: state.networkName,
138
+ mediatorName: AdMediatorName.adMob,
139
+ adFormat: state.adFormat,
140
+ placement: state.placement,
141
+ adUnitId: state.adUnitId,
142
+ impressionId: state.impressionId,
143
+ revenueMicros: revenueMicrosFrom(paid),
144
+ currency: paid.currency,
145
+ precision: precisionFrom(paid.precision),
146
+ captureMethod
147
+ }));
148
+ }
149
+ };
150
+ //# sourceMappingURL=tracker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Purchases","AdCaptureMethod","AdMediatorName","AdRevenuePrecision","Platform","logWarning","message","console","warn","captureMethod","reactNativeAdMobAdapter","androidErrorCodes","iosErrorCodes","timeout","mediatorErrorCode","reason","table","OS","mapped","undefined","numeric","Number","isInteger","revenueMicrosFrom","paid","valueMicros","micros","isFinite","Math","round","value","precisionFrom","precision","estimated","publisherDefined","exact","unknown","swallow","event","promise","catch","e","AdMobTracker","trackLoaded","state","adTracker","trackAdLoaded","networkName","mediatorName","adMob","adFormat","placement","loadPlacement","adUnitId","impressionId","trackFailedToLoad","trackAdFailedToLoad","trackDisplayed","trackAdDisplayed","trackOpened","trackAdOpened","trackRewardEarnedUnverified","trackAdRewardEarnedUnverified","trackRevenue","trackAdRevenue","revenueMicros","currency"],"sourceRoot":"../../src","sources":["tracker.ts"],"mappings":"AAAA,OAAOA,SAAS,IACdC,eAAe,EACf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qB,EAAQ;IACvDP,OAAO,CACL,eAAe,EACfrC,SAAS,CAAC6C,SAAS,CAACiB,6BAA6B,CAAC;MAChDf,WAAW,EAAEH,KAAK,CAACG,WAAW;MAC9BC,YAAY,EAAE9C,cAAc,CAAC+C,KAAK;MAClCC,QAAQ,EAAEN,KAAK,CAACM,QAAQ;MACxBC,SAAS,EAAEP,KAAK,CAACO,SAAS;MAC1BE,QAAQ,EAAET,KAAK,CAACS,QAAQ;MACxBC,YAAY,EAAEV,KAAK,CAACU,YAAY;MAChC7C;IACF,CAAiC,CACnC,CAAC;EACH,CAAC;EAEDsD,YAAYA,CAACnB,KAAqB,EAAEpB,IAAe,EAAQ;IACzDa,OAAO,CACL,YAAY,EACZrC,SAAS,CAAC6C,SAAS,CAACmB,cAAc,CAAC;MACjCjB,WAAW,EAAEH,KAAK,CAACG,WAAW;MAC9BC,YAAY,EAAE9C,cAAc,CAAC+C,KAAK;MAClCC,QAAQ,EAAEN,KAAK,CAACM,QAAQ;MACxBC,SAAS,EAAEP,KAAK,CAACO,SAAS;MAC1BE,QAAQ,EAAET,KAAK,CAACS,QAAQ;MACxBC,YAAY,EAAEV,KAAK,CAACU,YAAY;MAChCW,aAAa,EAAE1C,iBAAiB,CAACC,IAAI,CAAC;MACtC0C,QAAQ,EAAE1C,IAAI,CAAC0C,QAAQ;MACvBlC,SAAS,EAAED,aAAa,CAACP,IAAI,CAACQ,SAAS,CAAC;MACxCvB;IACF,CAAkB,CACpB,CAAC;EACH;AACF,CAAC","ignoreList":[]}
@@ -0,0 +1,230 @@
1
+ import type { RewardVerificationResult } from "react-native-purchases";
2
+ import { AppOpenAd, InterstitialAd, NativeAd, RewardedAd, RewardedInterstitialAd } from "react-native-google-mobile-ads";
3
+ import type { AdShowOptions, BannerAdProps, RequestOptions, ResponseInfo, RewardedAdReward } from "react-native-google-mobile-ads";
4
+ export type { TrackedAdState } from "./state";
5
+ /**
6
+ * The structural shape of a `react-native-google-mobile-ads` full-screen ad
7
+ * (`InterstitialAd`, `AppOpenAd`, `RewardedAd`, `RewardedInterstitialAd`).
8
+ * Typed structurally so the adapter works across the library's per-class
9
+ * listener generics and duplicate type installations.
10
+ */
11
+ export interface TrackableAd {
12
+ readonly adUnitId: string;
13
+ readonly loaded: boolean;
14
+ readonly responseInfo: ResponseInfo | null;
15
+ load(): void;
16
+ destroy(): void;
17
+ addAdEventsListener(listener: (event: {
18
+ type: string;
19
+ payload?: unknown;
20
+ }) => void): () => void;
21
+ addAdEventListener(type: string, listener: (payload: any) => void): () => void;
22
+ show(showOptions?: AdShowOptions): Promise<void>;
23
+ }
24
+ export interface TrackingOptions {
25
+ /** Free-form label for where in your app the ad is shown. */
26
+ placement?: string | null;
27
+ /** Passed through to `createForAdRequest`. */
28
+ requestOptions?: RequestOptions;
29
+ }
30
+ export interface RewardedTrackingOptions extends TrackingOptions {
31
+ /**
32
+ * Attach a RevenueCat reward-verification token to AdMob's server-side
33
+ * verification options. The token has to exist before the ad request is
34
+ * created, so the adapter generates the impression id itself and uses it for
35
+ * every tracking event of this ad. Tokens are single-use: create a new ad
36
+ * for each verified show instead of calling `load()` again on this one.
37
+ */
38
+ enableRewardVerification?: boolean;
39
+ }
40
+ export interface ShowOptions {
41
+ /** Overrides the load-time placement for this impression's events. */
42
+ placement?: string | null;
43
+ showOptions?: AdShowOptions;
44
+ }
45
+ export type BannerAdTrackingProps = BannerAdProps & {
46
+ placement?: string | null;
47
+ };
48
+ export type RewardVerificationStartedCallback = () => void;
49
+ export type RewardVerificationCompletedCallback = (result: RewardVerificationResult) => void;
50
+ export interface ShowWithRewardVerificationOptions extends ShowOptions {
51
+ onUserEarnedReward?: (reward: RewardedAdReward) => void;
52
+ onRewardVerificationStarted?: RewardVerificationStartedCallback;
53
+ onRewardVerificationCompleted: RewardVerificationCompletedCallback;
54
+ }
55
+ /**
56
+ * Returns `BannerAd` props that report to RevenueCat, forwarding to the
57
+ * props you pass in. Spread the result into `<BannerAd {...props} />`.
58
+ * The tracking state lives for the lifetime of the calling component, so
59
+ * rerenders keep the impression id of the banner that loaded.
60
+ *
61
+ * @example
62
+ * ```tsx
63
+ * function HomeBanner() {
64
+ * const bannerProps = useTrackingBannerAdProps({
65
+ * unitId,
66
+ * size: BannerAdSize.BANNER,
67
+ * placement: "home_bottom",
68
+ * });
69
+ * return <BannerAd {...bannerProps} />;
70
+ * }
71
+ * ```
72
+ */
73
+ export declare function useTrackingBannerAdProps(props: BannerAdTrackingProps): BannerAdProps;
74
+ /**
75
+ * Entry point of the RevenueCat AdMob adapter for React Native.
76
+ *
77
+ * Create full-screen ads through `create...` instead of
78
+ * `createForAdRequest`, then `load()` and show them through
79
+ * `showAndTrack` / `showWithRewardVerification`. Banner components spread
80
+ * `useTrackingBannerAdProps(...)`; native ads go through `trackNativeAd`.
81
+ */
82
+ export declare const RevenueCatAdMob: {
83
+ /**
84
+ * Creates an interstitial ad whose loaded, displayed, opened, revenue and
85
+ * failed-to-load events are reported to RevenueCat. Use it in place of
86
+ * `InterstitialAd.createForAdRequest`, then `load()` and show it through
87
+ * `showAndTrack`.
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * const interstitial = RevenueCatAdMob.createInterstitialAd(adUnitId, {
92
+ * placement: "level_complete",
93
+ * });
94
+ * interstitial.addAdEventListener(AdEventType.LOADED, () => setReady(true));
95
+ * interstitial.load();
96
+ * // Later
97
+ * await RevenueCatAdMob.showAndTrack(interstitial);
98
+ * ```
99
+ */
100
+ createInterstitialAd(adUnitId: string, options?: TrackingOptions): InterstitialAd;
101
+ /**
102
+ * Creates an app open ad tracked by RevenueCat. Use it in place of
103
+ * `AppOpenAd.createForAdRequest`, then `load()` and show it through
104
+ * `showAndTrack`.
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * const appOpen = RevenueCatAdMob.createAppOpenAd(adUnitId, {
109
+ * placement: "cold_start",
110
+ * });
111
+ * appOpen.load();
112
+ * // When the app comes to the foreground
113
+ * await RevenueCatAdMob.showAndTrack(appOpen);
114
+ * ```
115
+ */
116
+ createAppOpenAd(adUnitId: string, options?: TrackingOptions): AppOpenAd;
117
+ /**
118
+ * Creates a rewarded ad tracked by RevenueCat. Use it in place of
119
+ * `RewardedAd.createForAdRequest`. With `enableRewardVerification` the
120
+ * adapter requests a verification token first, which is why this resolves
121
+ * asynchronously; show such ads through `showWithRewardVerification`.
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * const rewarded = await RevenueCatAdMob.createRewardedAd(adUnitId, {
126
+ * placement: "extra_life",
127
+ * enableRewardVerification: true,
128
+ * });
129
+ * rewarded.load();
130
+ * // Later
131
+ * await RevenueCatAdMob.showWithRewardVerification(rewarded, {
132
+ * onRewardVerificationCompleted: (result) => {
133
+ * if (!result.failed) grant(result.reward);
134
+ * },
135
+ * });
136
+ * ```
137
+ */
138
+ createRewardedAd(adUnitId: string, options?: RewardedTrackingOptions): Promise<RewardedAd>;
139
+ /**
140
+ * Creates a rewarded interstitial ad tracked by RevenueCat. Use it in place
141
+ * of `RewardedInterstitialAd.createForAdRequest`; otherwise identical to
142
+ * `createRewardedAd`.
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * const ad = await RevenueCatAdMob.createRewardedInterstitialAd(adUnitId, {
147
+ * placement: "chapter_end",
148
+ * });
149
+ * ad.load();
150
+ * // Later
151
+ * await RevenueCatAdMob.showAndTrack(ad);
152
+ * ```
153
+ */
154
+ createRewardedInterstitialAd(adUnitId: string, options?: RewardedTrackingOptions): Promise<RewardedInterstitialAd>;
155
+ /**
156
+ * Attaches tracking to a full-screen ad you created yourself. Call before
157
+ * `load()`. Reward verification is only available for ads created through
158
+ * `createRewardedAd` / `createRewardedInterstitialAd`.
159
+ */
160
+ trackAd(ad: TrackableAd, options?: TrackingOptions): void;
161
+ /**
162
+ * Shows a tracked full-screen ad, optionally overriding its placement.
163
+ *
164
+ * @example
165
+ * ```typescript
166
+ * await RevenueCatAdMob.showAndTrack(interstitial, {
167
+ * placement: "level_complete_retry",
168
+ * });
169
+ * ```
170
+ */
171
+ showAndTrack(ad: TrackableAd, options?: ShowOptions): Promise<void>;
172
+ /**
173
+ * Shows a rewarded ad and verifies the earned reward with RevenueCat.
174
+ * `onRewardVerificationCompleted` is called at most once per show, after
175
+ * the user earns the reward; it is not called when the ad is dismissed or
176
+ * fails before a reward. It receives a failed result when the ad was
177
+ * created without `enableRewardVerification`.
178
+ *
179
+ * @example
180
+ * ```typescript
181
+ * await RevenueCatAdMob.showWithRewardVerification(rewarded, {
182
+ * onRewardVerificationStarted: () => showSpinner(),
183
+ * onRewardVerificationCompleted: (result) => {
184
+ * if (result.failed) return showError();
185
+ * grant(result.reward);
186
+ * },
187
+ * });
188
+ * ```
189
+ */
190
+ showWithRewardVerification(ad: TrackableAd, options: ShowWithRewardVerificationOptions): Promise<void>;
191
+ /**
192
+ * Returns `BannerAd` props that report to RevenueCat, forwarding to the
193
+ * props you pass in. Spread the result into `<BannerAd {...props} />`.
194
+ * Each call starts a new tracking state, so call it once per banner
195
+ * instance (for example in a class component's constructor), never inside
196
+ * `render`. Function components should use `useTrackingBannerAdProps` instead.
197
+ *
198
+ * @example
199
+ * ```tsx
200
+ * class HomeBanner extends React.Component {
201
+ * bannerProps = RevenueCatAdMob.trackingBannerAdProps({
202
+ * unitId,
203
+ * size: BannerAdSize.BANNER,
204
+ * placement: "home_bottom",
205
+ * });
206
+ * render() {
207
+ * return <BannerAd {...this.bannerProps} />;
208
+ * }
209
+ * }
210
+ * ```
211
+ */
212
+ trackingBannerAdProps(props: BannerAdTrackingProps): BannerAdProps;
213
+ /**
214
+ * Tracks a loaded native ad. `NativeAd.createForAdRequest` resolves with a
215
+ * loaded ad, so the loaded event is reported immediately.
216
+ *
217
+ * @example
218
+ * ```typescript
219
+ * const nativeAd = await NativeAd.createForAdRequest(adUnitId);
220
+ * RevenueCatAdMob.trackNativeAd(nativeAd, { placement: "feed" });
221
+ * ```
222
+ */
223
+ trackNativeAd(ad: NativeAd, options?: {
224
+ placement?: string | null;
225
+ }): void;
226
+ /** The impression id the adapter uses for a tracked ad, once known. */
227
+ impressionIdOf(ad: object): string | null;
228
+ };
229
+ export default RevenueCatAdMob;
230
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AACvE,OAAO,EAEL,SAAS,EACT,cAAc,EACd,QAAQ,EAER,UAAU,EAEV,sBAAsB,EACvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EAEb,cAAc,EACd,YAAY,EACZ,gBAAgB,EACjB,MAAM,gCAAgC,CAAC;AAUxC,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI,CAAC;IAC3C,IAAI,IAAI,IAAI,CAAC;IACb,OAAO,IAAI,IAAI,CAAC;IAChB,mBAAmB,CACjB,QAAQ,EAAE,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,GAC7D,MAAM,IAAI,CAAC;IACd,kBAAkB,CAChB,IAAI,EAAE,MAAM,EAEZ,QAAQ,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI,GAC/B,MAAM,IAAI,CAAC;IACd,IAAI,CAAC,WAAW,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAClD;AAED,MAAM,WAAW,eAAe;IAC9B,6DAA6D;IAC7D,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,8CAA8C;IAC9C,cAAc,CAAC,E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AQ,QAAQ,IAAI,CAAC;IAKvE;;;;;;;;;;;;;;;;;OAiBG;mCAEG,WAAW,WACN,iCAAiC,GACzC,QAAQ,IAAI,CAAC;IA6DhB;;;;;;;;;;;;;;;;;;;;OAoBG;iCAC0B,qBAAqB,GAAG,aAAa;IAQlE;;;;;;;;;OASG;sBAEG,QAAQ,YACH;QAAE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GACrC,IAAI;IAoBP,uEAAuE;uBACpD,MAAM,GAAG,MAAM,GAAG,IAAI;CAG1C,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type { AdFormat, RewardedAdTrackingMetadata } from "react-native-purchases";
2
+ import type { ResponseInfo } from "react-native-google-mobile-ads";
3
+ /**
4
+ * Per-ad bookkeeping, kept in a weak side table so the adapter never changes
5
+ * the lifetime of the `react-native-google-mobile-ads` objects it tracks.
6
+ */
7
+ export declare class TrackedAdState {
8
+ readonly adFormat: AdFormat;
9
+ readonly adUnitId: string;
10
+ pinnedImpressionId: string | null;
11
+ loadPlacement: string | null;
12
+ showPlacement: string | null;
13
+ /**
14
+ * Either AdMob's response id (read once the ad loads) or, for ads created
15
+ * with reward verification, the id generated before the request so the SSV
16
+ * token and every tracking event share one impression id.
17
+ */
18
+ impressionId: string;
19
+ networkName: string | null;
20
+ clientTransactionId: string | null;
21
+ rewardVerificationDelivered: boolean;
22
+ loadedOnce: boolean;
23
+ constructor(adFormat: AdFormat, adUnitId: string, placement?: string | null, pinnedImpressionId?: string | null);
24
+ get placement(): string | null;
25
+ updateFromResponse(info: ResponseInfo | null | undefined): void;
26
+ get trackingMetadata(): RewardedAdTrackingMetadata;
27
+ }
28
+ export declare function stateFor(ad: object): TrackedAdState | undefined;
29
+ export declare function setState(ad: object, state: TrackedAdState): TrackedAdState;
30
+ export declare function generateImpressionId(): string;
31
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/state.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,QAAQ,EACR,0BAA0B,EAC3B,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAEnE;;;GAGG;AACH,qBAAa,cAAc;IAevB,QAAQ,CAAC,QAAQ,EAAE,QAAQ;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM;IAElB,kBAAkB,EAAE,MAAM,GAAG,IAAI;IAjB1C,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,aAAa,EAAE,MAAM,GAAG,IAAI,CAAQ;IACpC;;;;OAIG;IACH,YAAY,EAAE,MAAM,CAAM;IAC1B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAQ;IAClC,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC1C,2BAA2B,UAAS;IACpC,UAAU,UAAS;gBAGR,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,MAAM,EACzB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,EAClB,kBAAkB,GAAE,MAAM,GAAG,IAAW;IAQjD,IAAI,SAAS,IAAI,MAAM,GAAG,IAAI,CAE7B;IAED,kBAAkB,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI;IAU/D,IAAI,gBAAgB,IAAI,0BAA0B,CAUjD;CACF;AAID,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAE/D;AAED,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,GAAG,cAAc,CAG1E;AAYD,wBAAgB,oBAAoB,IAAI,MAAM,CAuB7C"}
@@ -0,0 +1,17 @@
1
+ import { AdRevenuePrecision } from "react-native-purchases";
2
+ import type { AdFormat } from "react-native-purchases";
3
+ import type { PaidEvent } from "react-native-google-mobile-ads";
4
+ import { TrackedAdState } from "./state";
5
+ export declare function logWarning(message: string): void;
6
+ export declare function mediatorErrorCode(reason: string | undefined): number | null;
7
+ export declare function revenueMicrosFrom(paid: PaidEvent): number;
8
+ export declare function precisionFrom(precision: number): AdRevenuePrecision;
9
+ export declare const AdMobTracker: {
10
+ trackLoaded(state: TrackedAdState): void;
11
+ trackFailedToLoad(adUnitId: string, adFormat: AdFormat, placement: string | null, reason: string | undefined): void;
12
+ trackDisplayed(state: TrackedAdState): void;
13
+ trackOpened(state: TrackedAdState): void;
14
+ trackRewardEarnedUnverified(state: TrackedAdState): void;
15
+ trackRevenue(state: TrackedAdState, paid: PaidEvent): void;
16
+ };
17
+ //# sourceMappingURL=tracker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracker.d.ts","sourceRoot":"","sources":["../../../src/tracker.ts"],"names":[],"mappings":"AAAA,OAAkB,EAGhB,kBAAkB,EACnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAGV,QAAQ,EAKT,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAGhE,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAGhD;AAwCD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAW3E;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAQzD;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,kBAAkB,CAWnE;AAMD,eAAO,MAAM,YAAY;uBACJ,cAAc,GAAG,IAAI;gCAgB5B,MAAM,YACN,QAAQ,aACP,MAAM,GAAG,IAAI,UAChB,MAAM,GAAG,SAAS,GACzB,IAAI;0BAce,cAAc,GAAG,IAAI;uBAexB,cAAc,GAAG,IAAI;uCAeL,cAAc,GAAG,IAAI;wBAepC,cAAc,QAAQ,SAAS,GAAG,IAAI;CAiB3D,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,111 @@
1
1
  {
2
2
  "name": "react-native-purchases-admob",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "title": "React Native Purchases AdMob",
4
+ "version": "10.15.1",
5
+ "description": "RevenueCat adapter for react-native-google-mobile-ads: automatic ad tracking and rewarded-ad reward verification.",
6
+ "main": "lib/commonjs/index",
7
+ "module": "lib/module/index",
8
+ "types": "lib/typescript/src/index.d.ts",
9
+ "react-native": "src/index",
10
+ "source": "src/index",
11
+ "files": [
12
+ "src",
13
+ "lib",
14
+ "!**/__tests__",
15
+ "!**/__fixtures__",
16
+ "!**/__mocks__",
17
+ "!**/.*"
18
+ ],
19
+ "scripts": {
20
+ "test": "jest",
21
+ "typecheck": "tsc --noEmit",
22
+ "tslint": "tslint -c tslint.json 'src/*.ts'",
23
+ "prepare": "bob build",
24
+ "apitest": "echo \"Running react-native-purchases-admob API type checks\" && tsc --project apitesters/tsconfig.json"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/revenuecat/react-native-purchases.git",
29
+ "baseUrl": "https://github.com/revenuecat/react-native-purchases"
30
+ },
31
+ "keywords": [
32
+ "react-native",
33
+ "admob",
34
+ "ads",
35
+ "revenuecat",
36
+ "iOS",
37
+ "Android"
38
+ ],
39
+ "author": "RevenueCat, Inc.",
40
+ "license": "MIT",
41
+ "readmeFilename": "README.md",
42
+ "devDependencies": {
43
+ "@types/jest": "^29.5.12",
44
+ "@types/react": "^18.2.44",
45
+ "@types/react-dom": "~18.2.0",
46
+ "@types/react-test-renderer": "^18.0.7",
47
+ "jest": "^29.7.0",
48
+ "jest-react-native": "^18.0.0",
49
+ "prettier": "^2.0.5",
50
+ "react": "18.2.0",
51
+ "react-native": "0.78.0",
52
+ "react-native-builder-bob": "^0.20.0",
53
+ "react-native-google-mobile-ads": "^17.0.0",
54
+ "react-test-renderer": "18.2.0",
55
+ "ts-jest": "^29.1.2",
56
+ "tslint": "^5.20.0",
57
+ "tslint-config-prettier": "^1.18.0",
58
+ "typescript": "^5.2.2"
59
+ },
60
+ "resolutions": {
61
+ "@types/react": "^18.2.44",
62
+ "@types/react-dom": "18.2.0"
63
+ },
64
+ "peerDependencies": {
65
+ "react": "*",
66
+ "react-native": ">= 0.76.0",
67
+ "react-native-google-mobile-ads": ">= 17.0.0 < 18.0.0",
68
+ "react-native-purchases": "10.15.1"
69
+ },
70
+ "packageManager": "yarn@3.6.1+sha512.de524adec81a6c3d7a26d936d439d2832e351cdfc5728f9d91f3fc85dd20b04391c038e9b4ecab11cae2b0dd9f0d55fd355af766bc5c1a7f8d25d96bb2a0b2ca",
71
+ "jest": {
72
+ "preset": "ts-jest",
73
+ "testEnvironment": "node",
74
+ "modulePathIgnorePatterns": [
75
+ "<rootDir>/lib/"
76
+ ],
77
+ "moduleFileExtensions": [
78
+ "ts",
79
+ "tsx",
80
+ "js"
81
+ ],
82
+ "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
83
+ "testPathIgnorePatterns": [
84
+ "\\.snap$",
85
+ "<rootDir>/node_modules/"
86
+ ],
87
+ "cacheDirectory": ".jest/cache",
88
+ "globals": {
89
+ "ts-jest": {
90
+ "tsconfig": "tsconfig.test.json"
91
+ }
92
+ },
93
+ "moduleNameMapper": {
94
+ "^react-native-purchases$": "<rootDir>/../dist/index"
95
+ }
96
+ },
97
+ "react-native-builder-bob": {
98
+ "source": "src",
99
+ "output": "lib",
100
+ "targets": [
101
+ "commonjs",
102
+ "module",
103
+ [
104
+ "typescript",
105
+ {
106
+ "project": "tsconfig.build.json"
107
+ }
108
+ ]
109
+ ]
110
+ }
111
+ }