react-native-applovin-max 4.1.7 → 5.0.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/src/index.js CHANGED
@@ -1,283 +1,62 @@
1
- import { NativeModules, NativeEventEmitter } from "react-native";
1
+ import { NativeModules } from "react-native";
2
2
  import AdView, { AdFormat, AdViewPosition } from "./AppLovinMAXAdView";
3
3
  import { TargetingData, AdContentRating, UserGender } from "./TargetingData";
4
4
  import NativeAdView from "./NativeAdView";
5
+ import EventListeners from "./AppLovinMAXEventListeners";
5
6
 
6
7
  const { AppLovinMAX } = NativeModules;
7
8
 
8
- const VERSION = "4.1.7";
9
-
10
- /**
11
- * This enum represents whether or not the consent dialog should be shown for this user.
12
- * The state where no such determination could be made is represented by `Unknown`.
13
- */
14
- const ConsentDialogState = {
15
- /**
16
- * The consent dialog state could not be determined. This is likely due to SDK failing to initialize.
17
- */
18
- UNKNOWN: 0,
19
-
20
- /**
21
- * This user should be shown a consent dialog.
22
- */
23
- APPLIES: 1,
24
-
25
- /**
26
- * This user should not be shown a consent dialog.
27
- */
28
- DOES_NOT_APPLY: 2,
29
- };
30
-
31
- const emitter = new NativeEventEmitter(AppLovinMAX);
32
- const subscriptions = {};
33
-
34
- const addEventListener = (event, handler) => {
35
- let subscription = emitter.addListener(event, handler);
36
- let currentSubscription = subscriptions[event];
37
- if (currentSubscription) {
38
- currentSubscription.remove();
39
- }
40
- subscriptions[event] = subscription;
41
- };
42
-
43
- const removeEventListener = (event) => {
44
- let currentSubscription = subscriptions[event];
45
- if (currentSubscription) {
46
- currentSubscription.remove();
47
- delete subscriptions[event];
48
- }
49
- };
50
-
51
- const logUninitializedAccessError = (callingMethod) => {
52
- console.warn( "ERROR: Failed to execute " + callingMethod + "() - please ensure the AppLovin MAX React Native module has been initialized by calling 'AppLovinMAX.initialize(...);'!" );
53
- }
9
+ const VERSION = "5.0.1";
54
10
 
55
11
  /*---------*/
56
12
  /* BANNERS */
57
13
  /*---------*/
58
14
 
59
- const createBanner = (adUnitId, bannerPosition) => {
60
- if (!AppLovinMAX.isInitialized()) {
61
- logUninitializedAccessError('createBanner');
62
- return;
63
- }
64
- AppLovinMAX.createBanner(adUnitId, bannerPosition);
65
- }
66
-
67
- const createBannerWithOffsets = (adUnitId, bannerPosition, xOffset, yOffset) => {
68
- if (!AppLovinMAX.isInitialized()) {
69
- logUninitializedAccessError('createBannerWithOffsets');
70
- return;
71
- }
72
- AppLovinMAX.createBannerWithOffsets(adUnitId, bannerPosition, xOffset, yOffset);
73
- }
74
-
75
- const setBannerBackgroundColor = (adUnitId, hexColorCode) => {
76
- if (!AppLovinMAX.isInitialized()) {
77
- logUninitializedAccessError('setBannerBackgroundColor');
78
- return;
79
- }
80
- AppLovinMAX.setBannerBackgroundColor(adUnitId, hexColorCode);
81
- }
82
-
83
- const setBannerPlacement = (adUnitId, placement) => {
84
- if (!AppLovinMAX.isInitialized()) {
85
- logUninitializedAccessError('setBannerPlacement');
86
- return;
87
- }
88
- AppLovinMAX.setBannerPlacement(adUnitId, placement);
89
- }
90
-
91
- const setBannerWidth = (adUnitId, width) => {
92
- if (!AppLovinMAX.isInitialized()) {
93
- logUninitializedAccessError('setBannerWidth');
94
- return;
95
- }
96
- AppLovinMAX.setBannerWidth(adUnitId, width);
97
- }
98
-
99
- const updateBannerPosition = (adUnitId, bannerPosition) => {
100
- if (!AppLovinMAX.isInitialized()) {
101
- logUninitializedAccessError('updateBannerPosition');
102
- return;
103
- }
104
- AppLovinMAX.updateBannerPosition(adUnitId, bannerPosition);
105
- }
106
-
107
- const updateBannerOffsets = (adUnitId, xOffset, yOffset) => {
108
- if (!AppLovinMAX.isInitialized()) {
109
- logUninitializedAccessError('updateBannerOffsets');
110
- return;
111
- }
112
- AppLovinMAX.updateBannerOffsets(adUnitId, xOffset, yOffset);
113
- }
114
-
115
15
  const setBannerExtraParameter = (adUnitId, key, value) => {
116
- if (!AppLovinMAX.isInitialized()) {
117
- logUninitializedAccessError('setBannerExtraParameter');
16
+ if ((value !== null) && (value !== undefined) && (typeof value !== 'string')) {
17
+ console.warn("setBannerExtraParameter() supports only string values: " + value);
118
18
  return;
119
19
  }
120
- AppLovinMAX.setBannerExtraParameter(adUnitId, key, value);
121
- }
122
-
123
- const startBannerAutoRefresh = (adUnitId) => {
124
- if (!AppLovinMAX.isInitialized()) {
125
- logUninitializedAccessError('startBannerAutoRefresh');
126
- return;
127
- }
128
- AppLovinMAX.startBannerAutoRefresh(adUnitId);
129
- }
130
20
 
131
- const stopBannerAutoRefresh = (adUnitId) => {
132
- if (!AppLovinMAX.isInitialized()) {
133
- logUninitializedAccessError('stopBannerAutoRefresh');
134
- return;
135
- }
136
- AppLovinMAX.stopBannerAutoRefresh(adUnitId);
137
- }
138
-
139
- const showBanner = (adUnitId) => {
140
- if (!AppLovinMAX.isInitialized()) {
141
- logUninitializedAccessError('showBanner');
142
- return;
143
- }
144
- AppLovinMAX.showBanner(adUnitId);
21
+ AppLovinMAX.setBannerExtraParameter(adUnitId, key, value);
145
22
  }
146
23
 
147
- const hideBanner = (adUnitId) => {
148
- if (!AppLovinMAX.isInitialized()) {
149
- logUninitializedAccessError('hideBanner');
24
+ const setBannerLocalExtraParameter = (adUnitId, key, value) => {
25
+ if ((value !== null) && (value !== undefined) && (typeof value !== 'string')) {
26
+ console.warn("setBannerLocalExtraParameter() supports only string values: " + value);
150
27
  return;
151
28
  }
152
- AppLovinMAX.hideBanner(adUnitId);
153
- }
154
29
 
155
- const destroyBanner = (adUnitId) => {
156
- if (!AppLovinMAX.isInitialized()) {
157
- logUninitializedAccessError('destroyBanner');
158
- return;
159
- }
160
- AppLovinMAX.destroyBanner(adUnitId);
30
+ AppLovinMAX.setBannerLocalExtraParameter(adUnitId, key, value);
161
31
  }
162
32
 
163
33
  /*-------*/
164
34
  /* MRECS */
165
35
  /*-------*/
166
36
 
167
- const createMRec = (adUnitId, mrecPosition) => {
168
- if (!AppLovinMAX.isInitialized()) {
169
- logUninitializedAccessError('createMRec');
170
- return;
171
- }
172
- AppLovinMAX.createMRec(adUnitId, mrecPosition);
173
- }
174
-
175
- const setMRecBackgroundColor = (adUnitId, hexColorCode) => {
176
- if (!AppLovinMAX.isInitialized()) {
177
- logUninitializedAccessError('setMRecBackgroundColor');
178
- return;
179
- }
180
- AppLovinMAX.setMRecBackgroundColor(adUnitId, hexColorCode);
181
- }
182
-
183
- const setMRecPlacement = (adUnitId, placement) => {
184
- if (!AppLovinMAX.isInitialized()) {
185
- logUninitializedAccessError('setMRecPlacement');
186
- return;
187
- }
188
- AppLovinMAX.setMRecPlacement(adUnitId, placement);
189
- }
190
-
191
- const setMRecCustomData = (adUnitId, customData) => {
192
- if (!AppLovinMAX.isInitialized()) {
193
- logUninitializedAccessError('setMRecCustomData');
194
- return;
195
- }
196
- AppLovinMAX.setMRecCustomData(adUnitId, customData);
197
- }
198
-
199
- const updateMRecPosition = (adUnitId, mrecPosition) => {
200
- if (!AppLovinMAX.isInitialized()) {
201
- logUninitializedAccessError('updateMRecPosition');
202
- return;
203
- }
204
- AppLovinMAX.updateMRecPosition(adUnitId, mrecPosition);
205
- }
206
-
207
37
  const setMRecExtraParameter = (adUnitId, key, value) => {
208
- if (!AppLovinMAX.isInitialized()) {
209
- logUninitializedAccessError('setMRecExtraParameter');
210
- return;
211
- }
212
- AppLovinMAX.setMRecExtraParameter(adUnitId, key, value);
213
- }
214
-
215
- const startMRecAutoRefresh = (adUnitId) => {
216
- if (!AppLovinMAX.isInitialized()) {
217
- logUninitializedAccessError('startMRecAutoRefresh');
218
- return;
219
- }
220
- AppLovinMAX.startMRecAutoRefresh(adUnitId);
221
- }
222
-
223
- const stopMRecAutoRefresh = (adUnitId) => {
224
- if (!AppLovinMAX.isInitialized()) {
225
- logUninitializedAccessError('stopMRecAutoRefresh');
38
+ if ((value !== null) && (value !== undefined) && (typeof value !== 'string')) {
39
+ console.warn("setMRecExtraParameter() supports only string values: " + value);
226
40
  return;
227
41
  }
228
- AppLovinMAX.stopMRecAutoRefresh(adUnitId);
229
- }
230
42
 
231
- const showMRec = (adUnitId) => {
232
- if (!AppLovinMAX.isInitialized()) {
233
- logUninitializedAccessError('showMRec');
234
- return;
235
- }
236
- AppLovinMAX.showMRec(adUnitId);
43
+ AppLovinMAX.setMRecExtraParameter(adUnitId, key, value);
237
44
  }
238
45
 
239
- const hideMRec = (adUnitId) => {
240
- if (!AppLovinMAX.isInitialized()) {
241
- logUninitializedAccessError('hideMRec');
46
+ const setMRecLocalExtraParameter = (adUnitId, key, value) => {
47
+ if ((value !== null) && (value !== undefined) && (typeof value !== 'string')) {
48
+ console.warn("setMRecLocalExtraParameter() supports only string values: " + value);
242
49
  return;
243
50
  }
244
- AppLovinMAX.hideMRec(adUnitId);
245
- }
246
51
 
247
- const destroyMRec = (adUnitId) => {
248
- if (!AppLovinMAX.isInitialized()) {
249
- logUninitializedAccessError('destroyMRec');
250
- return;
251
- }
252
- AppLovinMAX.destroyMRec(adUnitId);
52
+ AppLovinMAX.setMRecLocalExtraParameter(adUnitId, key, value);
253
53
  }
254
54
 
255
55
  /*---------------*/
256
56
  /* INTERSTITIALS */
257
57
  /*---------------*/
258
58
 
259
- const loadInterstitial = (adUnitId) => {
260
- if (!AppLovinMAX.isInitialized()) {
261
- logUninitializedAccessError('loadInterstitial');
262
- return;
263
- }
264
- AppLovinMAX.loadInterstitial(adUnitId);
265
- }
266
-
267
- const isInterstitialReady = (adUnitId) => {
268
- if (!AppLovinMAX.isInitialized()) {
269
- logUninitializedAccessError('isInterstitialReady');
270
- return false;
271
- }
272
- return AppLovinMAX.isInterstitialReady(adUnitId);
273
- }
274
-
275
59
  const showInterstitial = (adUnitId, ...args) => {
276
- if (!AppLovinMAX.isInitialized()) {
277
- logUninitializedAccessError('showInterstitial');
278
- return;
279
- }
280
-
281
60
  switch (args.length) {
282
61
  case 0:
283
62
  AppLovinMAX.showInterstitial(adUnitId, null, null);
@@ -295,39 +74,28 @@ const showInterstitial = (adUnitId, ...args) => {
295
74
  };
296
75
 
297
76
  const setInterstitialExtraParameter = (adUnitId, key, value) => {
298
- if (!AppLovinMAX.isInitialized()) {
299
- logUninitializedAccessError('setInterstitialExtraParameter');
77
+ if ((value !== null) && (value !== undefined) && (typeof value !== 'string')) {
78
+ console.warn("setInterstitialExtraParameter() supports only string values: " + value);
300
79
  return;
301
80
  }
81
+
302
82
  AppLovinMAX.setInterstitialExtraParameter(adUnitId, key, value);
303
83
  }
304
84
 
305
- /*----------*/
306
- /* REWARDED */
307
- /*----------*/
308
-
309
- const loadRewardedAd = (adUnitId) => {
310
- if (!AppLovinMAX.isInitialized()) {
311
- logUninitializedAccessError('loadRewardedAd');
85
+ const setInterstitialLocalExtraParameter = (adUnitId, key, value) => {
86
+ if ((value !== null) && (value !== undefined) && (typeof value !== 'string')) {
87
+ console.warn("setInterstitialLocalExtraParameter() supports only string values: " + value);
312
88
  return;
313
89
  }
314
- AppLovinMAX.loadRewardedAd(adUnitId);
315
- }
316
90
 
317
- const isRewardedAdReady = (adUnitId) => {
318
- if (!AppLovinMAX.isInitialized()) {
319
- logUninitializedAccessError('isRewardedAdReady');
320
- return false;
321
- }
322
- return AppLovinMAX.isRewardedAdReady(adUnitId);
91
+ AppLovinMAX.setInterstitialLocalExtraParameter(adUnitId, key, value);
323
92
  }
324
93
 
325
- const showRewardedAd = (adUnitId, ...args) => {
326
- if (!AppLovinMAX.isInitialized()) {
327
- logUninitializedAccessError('showRewardedAd');
328
- return;
329
- }
94
+ /*----------*/
95
+ /* REWARDED */
96
+ /*----------*/
330
97
 
98
+ const showRewardedAd = (adUnitId, ...args) => {
331
99
  switch (args.length) {
332
100
  case 0:
333
101
  AppLovinMAX.showRewardedAd(adUnitId, null, null);
@@ -345,39 +113,28 @@ const showRewardedAd = (adUnitId, ...args) => {
345
113
  };
346
114
 
347
115
  const setRewardedAdExtraParameter = (adUnitId, key, value) => {
348
- if (!AppLovinMAX.isInitialized()) {
349
- logUninitializedAccessError('setRewardedAdExtraParameter');
116
+ if ((value !== null) && (value !== undefined) && (typeof value !== 'string')) {
117
+ console.warn("setRewardedAdExtraParameter() supports only string values: " + value);
350
118
  return;
351
119
  }
120
+
352
121
  AppLovinMAX.setRewardedAdExtraParameter(adUnitId, key, value);
353
122
  }
354
123
 
355
- /*----------*/
356
- /* APP OPEN */
357
- /*----------*/
358
-
359
- const loadAppOpenAd = (adUnitId) => {
360
- if (!AppLovinMAX.isInitialized()) {
361
- logUninitializedAccessError('loadAppOpenAd');
124
+ const setRewardedAdLocalExtraParameter = (adUnitId, key, value) => {
125
+ if ((value !== null) && (value !== undefined) && (typeof value !== 'string')) {
126
+ console.warn("setRewardedAdLocalExtraParameter() supports only string values: " + value);
362
127
  return;
363
128
  }
364
- AppLovinMAX.loadAppOpenAd(adUnitId);
365
- }
366
129
 
367
- const isAppOpenAdReady = (adUnitId) => {
368
- if (!AppLovinMAX.isInitialized()) {
369
- logUninitializedAccessError('isAppOpenAdReady');
370
- return false;
371
- }
372
- return AppLovinMAX.isAppOpenAdReady(adUnitId);
130
+ AppLovinMAX.setRewardedAdLocalExtraParameter(adUnitId, key, value);
373
131
  }
374
132
 
375
- const showAppOpenAd = (adUnitId, ...args) => {
376
- if (!AppLovinMAX.isInitialized()) {
377
- logUninitializedAccessError('showAppOpenAd');
378
- return;
379
- }
133
+ /*----------*/
134
+ /* APP OPEN */
135
+ /*----------*/
380
136
 
137
+ const showAppOpenAd = (adUnitId, ...args) => {
381
138
  switch (args.length) {
382
139
  case 0:
383
140
  AppLovinMAX.showAppOpenAd(adUnitId, null, null);
@@ -395,87 +152,71 @@ const showAppOpenAd = (adUnitId, ...args) => {
395
152
  };
396
153
 
397
154
  const setAppOpenAdExtraParameter = (adUnitId, key, value) => {
398
- if (!AppLovinMAX.isInitialized()) {
399
- logUninitializedAccessError('setAppOpenAdExtraParameter');
155
+ if ((value !== null) && (value !== undefined) && (typeof value !== 'string')) {
156
+ console.warn("setAppOpenAdExtraParameter() supports only string values: " + value);
400
157
  return;
401
158
  }
159
+
402
160
  AppLovinMAX.setAppOpenAdExtraParameter(adUnitId, key, value);
403
161
  }
404
162
 
163
+ const setAppOpenAdLocalExtraParameter = (adUnitId, key, value) => {
164
+ if ((value !== null) && (value !== undefined) && (typeof value !== 'string')) {
165
+ console.warn("setAppOpenAdLocalExtraParameter() supports only string values: " + value);
166
+ return;
167
+ }
168
+
169
+ AppLovinMAX.setAppOpenAdLocalExtraParameter(adUnitId, key, value);
170
+ }
171
+
405
172
  export default {
406
173
  ...AppLovinMAX,
174
+ ...EventListeners,
407
175
  AdView,
408
176
  get targetingData() {
409
177
  return TargetingData;
410
178
  },
411
179
  AdContentRating,
412
180
  UserGender,
413
- ConsentDialogState,
414
181
  AdViewPosition,
415
182
  AdFormat,
416
183
  NativeAdView,
417
- addEventListener,
418
- removeEventListener,
419
- // Use callback to avoid need for attaching listeners at top level on each re-render
420
- initialize(sdkKey, callback) {
421
- AppLovinMAX.initialize(VERSION, sdkKey, callback); // Inject VERSION into native code
184
+ initialize(sdkKey) {
185
+ return AppLovinMAX.initialize(VERSION, sdkKey);
422
186
  },
423
187
 
424
188
  /*---------*/
425
189
  /* BANNERS */
426
190
  /*---------*/
427
- createBanner,
428
- createBannerWithOffsets,
429
- setBannerBackgroundColor,
430
- setBannerPlacement,
431
- setBannerWidth,
432
- updateBannerPosition,
433
- updateBannerOffsets,
434
191
  setBannerExtraParameter,
435
- startBannerAutoRefresh,
436
- stopBannerAutoRefresh,
437
- showBanner,
438
- hideBanner,
439
- destroyBanner,
192
+ setBannerLocalExtraParameter,
440
193
 
441
194
  /*-------*/
442
195
  /* MRECS */
443
196
  /*-------*/
444
- createMRec,
445
- setMRecBackgroundColor,
446
- setMRecPlacement,
447
- setMRecCustomData,
448
- updateMRecPosition,
449
197
  setMRecExtraParameter,
450
- startMRecAutoRefresh,
451
- stopMRecAutoRefresh,
452
- showMRec,
453
- hideMRec,
454
- destroyMRec,
198
+ setMRecLocalExtraParameter,
455
199
 
456
200
  /*---------------*/
457
201
  /* INTERSTITIALS */
458
202
  /*---------------*/
459
- loadInterstitial,
460
- isInterstitialReady,
461
203
  showInterstitial,
462
204
  setInterstitialExtraParameter,
205
+ setInterstitialLocalExtraParameter,
463
206
 
464
207
  /*----------*/
465
208
  /* REWARDED */
466
209
  /*----------*/
467
- loadRewardedAd,
468
- isRewardedAdReady,
469
210
  showRewardedAd,
470
211
  setRewardedAdExtraParameter,
212
+ setRewardedAdLocalExtraParameter,
471
213
 
472
214
  /*----------*/
473
215
  /* APP OPEN */
474
216
  /*----------*/
475
- loadAppOpenAd,
476
- isAppOpenAdReady,
477
217
  showAppOpenAd,
478
218
  setAppOpenAdExtraParameter,
219
+ setAppOpenAdLocalExtraParameter,
479
220
 
480
221
  /*----------------------*/
481
222
  /** AUTO-DECLARED APIs **/
@@ -484,29 +225,28 @@ export default {
484
225
  /*----------------*/
485
226
  /* INITIALIZATION */
486
227
  /*----------------*/
487
- /* isInitialized() */
488
- /* initialize(pluginVersion, sdkKey, callback) */
228
+ /* isInitialized(promise) */
229
+ /* initialize(pluginVersion, sdkKey, promise) */
489
230
 
490
231
  /*--------------*/
491
232
  /* PRIVACY APIs */
492
233
  /*--------------*/
493
- /* showConsentDialog(callback) */
494
- /* getConsentDialogState() */
234
+ /* showConsentDialog(promise) */
495
235
  /* setHasUserConsent(hasUserConsent) */
496
- /* hasUserConsent() */
236
+ /* hasUserConsent(promise) */
497
237
  /* setIsAgeRestrictedUser(isAgeRestrictedUser) */
498
- /* isAgeRestrictedUser() */
238
+ /* isAgeRestrictedUser(promise) */
499
239
  /* setDoNotSell(doNotSell) */
500
- /* isDoNotSell() */
240
+ /* isDoNotSell(promise) */
501
241
 
502
242
  /*--------------------*/
503
243
  /* GENERAL PUBLIC API */
504
244
  /*--------------------*/
505
245
  /* showMediationDebugger() */
506
- /* isTablet() */
246
+ /* isTablet(promise) */
507
247
  /* setUserId(userId) */
508
248
  /* setMuted(muted) */
509
- /* isMuted() */
249
+ /* isMuted(promise) */
510
250
  /* setVerboseLogging(verboseLoggingEnabled) */
511
251
  /* setTestDeviceAdvertisingIds(advertisingIds) */
512
252
  /* setCreativeDebuggerEnabled(enabled) */
@@ -516,6 +256,54 @@ export default {
516
256
  /* setTermsOfServiceUrl(urlString) */
517
257
  /* setLocationCollectionEnabled(locationCollectionEnabled) */
518
258
 
259
+ /*---------*/
260
+ /* BANNERS */
261
+ /*---------*/
262
+ /* createBanner */
263
+ /* createBannerWithOffsets */
264
+ /* setBannerBackgroundColor */
265
+ /* setBannerPlacement */
266
+ /* setBannerWidth */
267
+ /* updateBannerPosition */
268
+ /* updateBannerOffsets */
269
+ /* startBannerAutoRefresh */
270
+ /* stopBannerAutoRefresh */
271
+ /* showBanner */
272
+ /* hideBanner */
273
+ /* destroyBanner */
274
+
275
+ /*-------*/
276
+ /* MRECS */
277
+ /*-------*/
278
+ /* createMRec */
279
+ /* setMRecBackgroundColor */
280
+ /* setMRecPlacement */
281
+ /* setMRecCustomData */
282
+ /* updateMRecPosition */
283
+ /* startMRecAutoRefresh */
284
+ /* stopMRecAutoRefresh */
285
+ /* showMRec */
286
+ /* hideMRec */
287
+ /* destroyMRec */
288
+
289
+ /*---------------*/
290
+ /* INTERSTITIALS */
291
+ /*---------------*/
292
+ /* loadInterstitial */
293
+ /* isInterstitialReady */
294
+
295
+ /*----------*/
296
+ /* REWARDED */
297
+ /*----------*/
298
+ /* loadRewardedAd */
299
+ /* isRewardedAdReady */
300
+
301
+ /*----------*/
302
+ /* APP OPEN */
303
+ /*----------*/
304
+ /* loadAppOpenAd */
305
+ /* isAppOpenAdReady */
306
+
519
307
  /*----------------*/
520
308
  /* EVENT TRACKING */
521
309
  /*----------------*/
@@ -524,5 +312,5 @@ export default {
524
312
  /*---------*/
525
313
  /* BANNERS */
526
314
  /*---------*/
527
- /* getAdaptiveBannerHeightForWidth(width) */
315
+ /* getAdaptiveBannerHeightForWidth(width, promise) */
528
316
  };