@react-native-firebase/analytics 23.7.0 → 23.8.0

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.
Files changed (132) hide show
  1. package/dist/commonjs/index.js +38 -0
  2. package/dist/commonjs/index.js.map +1 -0
  3. package/dist/commonjs/modular.js +613 -0
  4. package/dist/commonjs/modular.js.map +1 -0
  5. package/dist/commonjs/namespaced.js +441 -0
  6. package/dist/commonjs/namespaced.js.map +1 -0
  7. package/dist/commonjs/package.json +1 -0
  8. package/dist/commonjs/struct.js +54 -0
  9. package/dist/commonjs/struct.js.map +1 -0
  10. package/dist/commonjs/structs.js +214 -0
  11. package/dist/commonjs/structs.js.map +1 -0
  12. package/dist/commonjs/types/analytics.js +79 -0
  13. package/dist/commonjs/types/analytics.js.map +1 -0
  14. package/dist/commonjs/types/web.js +2 -0
  15. package/dist/commonjs/types/web.js.map +1 -0
  16. package/dist/commonjs/version.js +9 -0
  17. package/dist/commonjs/version.js.map +1 -0
  18. package/dist/commonjs/web/RNFBAnalyticsModule.android.js +9 -0
  19. package/dist/commonjs/web/RNFBAnalyticsModule.android.js.map +1 -0
  20. package/dist/commonjs/web/RNFBAnalyticsModule.ios.js +9 -0
  21. package/dist/commonjs/web/RNFBAnalyticsModule.ios.js.map +1 -0
  22. package/dist/commonjs/web/RNFBAnalyticsModule.js +119 -0
  23. package/dist/commonjs/web/RNFBAnalyticsModule.js.map +1 -0
  24. package/dist/commonjs/web/api.js +294 -0
  25. package/dist/commonjs/web/api.js.map +1 -0
  26. package/{ios/RNFBAnalytics/RNFBAnalyticsModule.h → dist/module/index.js} +10 -6
  27. package/dist/module/index.js.map +1 -0
  28. package/{lib/modular/index.js → dist/module/modular.js} +43 -161
  29. package/dist/module/modular.js.map +1 -0
  30. package/dist/module/namespaced.js +438 -0
  31. package/dist/module/namespaced.js.map +1 -0
  32. package/dist/module/package.json +1 -0
  33. package/{lib → dist/module}/struct.js +12 -14
  34. package/dist/module/struct.js.map +1 -0
  35. package/dist/module/structs.js +210 -0
  36. package/dist/module/structs.js.map +1 -0
  37. package/dist/module/types/analytics.js +75 -0
  38. package/dist/module/types/analytics.js.map +1 -0
  39. package/dist/module/types/web.js +2 -0
  40. package/dist/module/types/web.js.map +1 -0
  41. package/dist/module/version.js +5 -0
  42. package/dist/module/version.js.map +1 -0
  43. package/dist/module/web/RNFBAnalyticsModule.android.js +6 -0
  44. package/dist/module/web/RNFBAnalyticsModule.android.js.map +1 -0
  45. package/dist/module/web/RNFBAnalyticsModule.ios.js +6 -0
  46. package/dist/module/web/RNFBAnalyticsModule.ios.js.map +1 -0
  47. package/{lib → dist/module}/web/RNFBAnalyticsModule.js +17 -21
  48. package/dist/module/web/RNFBAnalyticsModule.js.map +1 -0
  49. package/{lib → dist/module}/web/api.js +34 -77
  50. package/dist/module/web/api.js.map +1 -0
  51. package/dist/typescript/commonjs/lib/index.d.ts +5 -0
  52. package/dist/typescript/commonjs/lib/index.d.ts.map +1 -0
  53. package/dist/typescript/commonjs/lib/modular.d.ts +476 -0
  54. package/dist/typescript/commonjs/lib/modular.d.ts.map +1 -0
  55. package/dist/typescript/commonjs/lib/namespaced.d.ts +12 -0
  56. package/dist/typescript/commonjs/lib/namespaced.d.ts.map +1 -0
  57. package/dist/typescript/commonjs/lib/struct.d.ts +3 -0
  58. package/dist/typescript/commonjs/lib/struct.d.ts.map +1 -0
  59. package/dist/typescript/commonjs/lib/structs.d.ts +1155 -0
  60. package/dist/typescript/commonjs/lib/structs.d.ts.map +1 -0
  61. package/dist/typescript/commonjs/lib/types/analytics.d.ts +944 -0
  62. package/dist/typescript/commonjs/lib/types/analytics.d.ts.map +1 -0
  63. package/dist/typescript/commonjs/lib/types/web.d.ts +36 -0
  64. package/dist/typescript/commonjs/lib/types/web.d.ts.map +1 -0
  65. package/dist/typescript/commonjs/lib/version.d.ts +2 -0
  66. package/dist/typescript/commonjs/lib/version.d.ts.map +1 -0
  67. package/dist/typescript/commonjs/lib/web/RNFBAnalyticsModule.android.d.ts +3 -0
  68. package/dist/typescript/commonjs/lib/web/RNFBAnalyticsModule.android.d.ts.map +1 -0
  69. package/dist/typescript/commonjs/lib/web/RNFBAnalyticsModule.d.ts +9 -0
  70. package/dist/typescript/commonjs/lib/web/RNFBAnalyticsModule.d.ts.map +1 -0
  71. package/dist/typescript/commonjs/lib/web/RNFBAnalyticsModule.ios.d.ts +3 -0
  72. package/dist/typescript/commonjs/lib/web/RNFBAnalyticsModule.ios.d.ts.map +1 -0
  73. package/dist/typescript/commonjs/lib/web/api.d.ts +37 -0
  74. package/dist/typescript/commonjs/lib/web/api.d.ts.map +1 -0
  75. package/dist/typescript/commonjs/package.json +1 -0
  76. package/dist/typescript/module/lib/index.d.ts +5 -0
  77. package/dist/typescript/module/lib/index.d.ts.map +1 -0
  78. package/dist/typescript/module/lib/modular.d.ts +476 -0
  79. package/dist/typescript/module/lib/modular.d.ts.map +1 -0
  80. package/dist/typescript/module/lib/namespaced.d.ts +12 -0
  81. package/dist/typescript/module/lib/namespaced.d.ts.map +1 -0
  82. package/dist/typescript/module/lib/struct.d.ts +3 -0
  83. package/dist/typescript/module/lib/struct.d.ts.map +1 -0
  84. package/dist/typescript/module/lib/structs.d.ts +1155 -0
  85. package/dist/typescript/module/lib/structs.d.ts.map +1 -0
  86. package/dist/typescript/module/lib/types/analytics.d.ts +944 -0
  87. package/dist/typescript/module/lib/types/analytics.d.ts.map +1 -0
  88. package/dist/typescript/module/lib/types/web.d.ts +36 -0
  89. package/dist/typescript/module/lib/types/web.d.ts.map +1 -0
  90. package/dist/typescript/module/lib/version.d.ts +2 -0
  91. package/dist/typescript/module/lib/version.d.ts.map +1 -0
  92. package/dist/typescript/module/lib/web/RNFBAnalyticsModule.android.d.ts +3 -0
  93. package/dist/typescript/module/lib/web/RNFBAnalyticsModule.android.d.ts.map +1 -0
  94. package/dist/typescript/module/lib/web/RNFBAnalyticsModule.d.ts +9 -0
  95. package/dist/typescript/module/lib/web/RNFBAnalyticsModule.d.ts.map +1 -0
  96. package/dist/typescript/module/lib/web/RNFBAnalyticsModule.ios.d.ts +3 -0
  97. package/dist/typescript/module/lib/web/RNFBAnalyticsModule.ios.d.ts.map +1 -0
  98. package/dist/typescript/module/lib/web/api.d.ts +37 -0
  99. package/dist/typescript/module/lib/web/api.d.ts.map +1 -0
  100. package/dist/typescript/module/package.json +1 -0
  101. package/lib/index.ts +73 -0
  102. package/lib/modular.ts +1026 -0
  103. package/lib/{index.js → namespaced.ts} +145 -72
  104. package/lib/struct.ts +61 -0
  105. package/lib/{structs.js → structs.ts} +3 -3
  106. package/lib/types/analytics.ts +1078 -0
  107. package/lib/types/web.ts +56 -0
  108. package/lib/version.ts +2 -0
  109. package/lib/web/RNFBAnalyticsModule.android.ts +3 -0
  110. package/lib/web/RNFBAnalyticsModule.ios.ts +3 -0
  111. package/lib/web/RNFBAnalyticsModule.ts +135 -0
  112. package/lib/web/api.ts +366 -0
  113. package/package.json +61 -7
  114. package/CHANGELOG.md +0 -1085
  115. package/RNFBAnalytics.podspec +0 -71
  116. package/android/.editorconfig +0 -10
  117. package/android/build.gradle +0 -177
  118. package/android/lint.xml +0 -5
  119. package/android/settings.gradle +0 -1
  120. package/android/src/main/AndroidManifest.xml +0 -21
  121. package/android/src/main/java/io/invertase/firebase/analytics/UniversalFirebaseAnalyticsModule.java +0 -141
  122. package/android/src/reactnative/AndroidManifest.xml +0 -2
  123. package/android/src/reactnative/java/io/invertase/firebase/analytics/ReactNativeFirebaseAnalyticsModule.java +0 -213
  124. package/android/src/reactnative/java/io/invertase/firebase/analytics/ReactNativeFirebaseAnalyticsPackage.java +0 -41
  125. package/ios/RNFBAnalytics/RNFBAnalyticsModule.m +0 -268
  126. package/ios/RNFBAnalytics.xcodeproj/project.pbxproj +0 -349
  127. package/ios/RNFBAnalytics.xcodeproj/xcshareddata/IDETemplateMacros.plist +0 -24
  128. package/lib/index.d.ts +0 -1903
  129. package/lib/modular/index.d.ts +0 -1267
  130. package/lib/version.js +0 -2
  131. package/lib/web/RNFBAnalyticsModule.android.js +0 -2
  132. package/lib/web/RNFBAnalyticsModule.ios.js +0 -2
@@ -14,7 +14,6 @@
14
14
  * limitations under the License.
15
15
  *
16
16
  */
17
-
18
17
  import {
19
18
  isAlphaNumericUnderscore,
20
19
  isE164PhoneNumber,
@@ -27,20 +26,62 @@ import {
27
26
  isUndefined,
28
27
  } from '@react-native-firebase/app/lib/common';
29
28
 
29
+ import type { ReactNativeFirebase } from '@react-native-firebase/app';
30
+
30
31
  import {
31
32
  createModuleNamespace,
32
33
  FirebaseModule,
33
34
  getFirebaseRoot,
34
35
  } from '@react-native-firebase/app/lib/internal';
36
+
37
+ // Internal types are now available through module declarations in app package
35
38
  import { setReactNativeModule } from '@react-native-firebase/app/lib/internal/nativeModule';
36
39
  import { isBoolean } from '@react-native-firebase/app/lib/common';
37
40
 
38
41
  import { validateStruct, validateCompound } from './struct';
39
- import fallBackModule from './web/RNFBAnalyticsModule';
40
- import version from './version';
42
+ import { RNFBAnalyticsModule } from './web/RNFBAnalyticsModule';
43
+ import { version } from './version';
41
44
  import * as structs from './structs';
42
-
43
- const ReservedEventNames = [
45
+ import {
46
+ type Statics,
47
+ type AnalyticsCallOptions,
48
+ type ConsentSettings,
49
+ type AddPaymentInfoEventParameters,
50
+ type ScreenViewParameters,
51
+ type AddShippingInfoParameters,
52
+ type AddToCartEventParameters,
53
+ type AddToWishlistEventParameters,
54
+ type BeginCheckoutEventParameters,
55
+ type CampaignDetailsEventParameters,
56
+ type EarnVirtualCurrencyEventParameters,
57
+ type GenerateLeadEventParameters,
58
+ type JoinGroupEventParameters,
59
+ type LevelEndEventParameters,
60
+ type LevelStartEventParameters,
61
+ type LevelUpEventParameters,
62
+ type LoginEventParameters,
63
+ type PostScoreEventParameters,
64
+ type SelectContentEventParameters,
65
+ type PurchaseEventParameters,
66
+ type RefundEventParameters,
67
+ type RemoveFromCartEventParameters,
68
+ type SearchEventParameters,
69
+ type SelectItemEventParameters,
70
+ type SetCheckoutOptionEventParameters,
71
+ type SelectPromotionEventParameters,
72
+ type ShareEventParameters,
73
+ type SignUpEventParameters,
74
+ type SpendVirtualCurrencyEventParameters,
75
+ type UnlockAchievementEventParameters,
76
+ type ViewCartEventParameters,
77
+ type ViewItemEventParameters,
78
+ type ViewItemListEventParameters,
79
+ type ViewPromotionEventParameters,
80
+ type ViewSearchResultsParameters,
81
+ type Analytics,
82
+ } from './types/analytics';
83
+
84
+ const ReservedEventNames: readonly string[] = [
44
85
  'ad_activeview',
45
86
  'ad_click',
46
87
  'ad_exposure',
@@ -73,16 +114,20 @@ const ReservedEventNames = [
73
114
  'session_start',
74
115
  'session_start_with_rollout',
75
116
  'user_engagement',
76
- ];
117
+ ] as const;
77
118
 
78
- const statics = {};
119
+ const statics: Partial<Statics> = {};
79
120
 
80
121
  const namespace = 'analytics';
81
122
 
82
123
  const nativeModuleName = 'RNFBAnalyticsModule';
83
124
 
84
125
  class FirebaseAnalyticsModule extends FirebaseModule {
85
- logEvent(name, params = {}, options = {}) {
126
+ logEvent(
127
+ name: string,
128
+ params: { [key: string]: any } = {},
129
+ options: AnalyticsCallOptions = { global: false },
130
+ ): Promise<void> {
86
131
  if (!isString(name)) {
87
132
  throw new Error("firebase.analytics().logEvent(*) 'name' expected a string value.");
88
133
  }
@@ -92,7 +137,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
92
137
  }
93
138
 
94
139
  // check name is not a reserved event name
95
- if (isOneOf(name, ReservedEventNames)) {
140
+ if (isOneOf(name, ReservedEventNames as any[])) {
96
141
  throw new Error(
97
142
  `firebase.analytics().logEvent(*) 'name' the event name '${name}' is reserved and can not be used.`,
98
143
  );
@@ -120,7 +165,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
120
165
  return this.native.logEvent(name, params);
121
166
  }
122
167
 
123
- setAnalyticsCollectionEnabled(enabled) {
168
+ setAnalyticsCollectionEnabled(enabled: boolean): Promise<void> {
124
169
  if (!isBoolean(enabled)) {
125
170
  throw new Error(
126
171
  "firebase.analytics().setAnalyticsCollectionEnabled(*) 'enabled' expected a boolean value.",
@@ -130,7 +175,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
130
175
  return this.native.setAnalyticsCollectionEnabled(enabled);
131
176
  }
132
177
 
133
- setSessionTimeoutDuration(milliseconds = 1800000) {
178
+ setSessionTimeoutDuration(milliseconds: number = 1800000): Promise<void> {
134
179
  if (!isNumber(milliseconds)) {
135
180
  throw new Error(
136
181
  "firebase.analytics().setSessionTimeoutDuration(*) 'milliseconds' expected a number value.",
@@ -146,15 +191,15 @@ class FirebaseAnalyticsModule extends FirebaseModule {
146
191
  return this.native.setSessionTimeoutDuration(milliseconds);
147
192
  }
148
193
 
149
- getAppInstanceId() {
194
+ getAppInstanceId(): Promise<string | null> {
150
195
  return this.native.getAppInstanceId();
151
196
  }
152
197
 
153
- getSessionId() {
198
+ getSessionId(): Promise<number | null> {
154
199
  return this.native.getSessionId();
155
200
  }
156
201
 
157
- setUserId(id) {
202
+ setUserId(id: string | null): Promise<void> {
158
203
  if (!isNull(id) && !isString(id)) {
159
204
  throw new Error("firebase.analytics().setUserId(*) 'id' expected a string value.");
160
205
  }
@@ -162,7 +207,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
162
207
  return this.native.setUserId(id);
163
208
  }
164
209
 
165
- setUserProperty(name, value) {
210
+ setUserProperty(name: string, value: string | null): Promise<void> {
166
211
  if (!isString(name)) {
167
212
  throw new Error("firebase.analytics().setUserProperty(*) 'name' expected a string value.");
168
213
  }
@@ -176,7 +221,10 @@ class FirebaseAnalyticsModule extends FirebaseModule {
176
221
  return this.native.setUserProperty(name, value);
177
222
  }
178
223
 
179
- setUserProperties(properties, options = {}) {
224
+ setUserProperties(
225
+ properties: { [key: string]: string | null },
226
+ options: AnalyticsCallOptions = { global: false },
227
+ ): Promise<void> {
180
228
  if (!isObject(properties)) {
181
229
  throw new Error(
182
230
  "firebase.analytics().setUserProperties(*) 'properties' expected an object of key/value pairs.",
@@ -197,7 +245,9 @@ class FirebaseAnalyticsModule extends FirebaseModule {
197
245
 
198
246
  const entries = Object.entries(properties);
199
247
  for (let i = 0; i < entries.length; i++) {
200
- const [key, value] = entries[i];
248
+ const entry = entries[i];
249
+ if (!entry) continue;
250
+ const [key, value] = entry;
201
251
  if (!isNull(value) && !isString(value)) {
202
252
  throw new Error(
203
253
  `firebase.analytics().setUserProperties(*) 'properties' value for parameter '${key}' is invalid, expected a string.`,
@@ -208,11 +258,11 @@ class FirebaseAnalyticsModule extends FirebaseModule {
208
258
  return this.native.setUserProperties(properties);
209
259
  }
210
260
 
211
- resetAnalyticsData() {
261
+ resetAnalyticsData(): Promise<void> {
212
262
  return this.native.resetAnalyticsData();
213
263
  }
214
264
 
215
- setConsent(consentSettings) {
265
+ setConsent(consentSettings: ConsentSettings): Promise<void> {
216
266
  if (!isObject(consentSettings)) {
217
267
  throw new Error(
218
268
  'firebase.analytics().setConsent(*): The supplied arg must be an object of key/values.',
@@ -221,7 +271,9 @@ class FirebaseAnalyticsModule extends FirebaseModule {
221
271
 
222
272
  const entries = Object.entries(consentSettings);
223
273
  for (let i = 0; i < entries.length; i++) {
224
- const [key, value] = entries[i];
274
+ const entry = entries[i];
275
+ if (!entry) continue;
276
+ const [key, value] = entry;
225
277
  if (!isBoolean(value)) {
226
278
  throw new Error(
227
279
  `firebase.analytics().setConsent(*) 'consentSettings' value for parameter '${key}' is invalid, expected a boolean.`,
@@ -235,7 +287,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
235
287
  /** -------------------
236
288
  * EVENTS
237
289
  * -------------------- */
238
- logAddPaymentInfo(object = {}) {
290
+ logAddPaymentInfo(object: AddPaymentInfoEventParameters): Promise<void> {
239
291
  if (!isObject(object)) {
240
292
  throw new Error(
241
293
  'firebase.analytics().logAddPaymentInfo(*): The supplied arg must be an object of key/values.',
@@ -250,7 +302,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
250
302
  );
251
303
  }
252
304
 
253
- logScreenView(object) {
305
+ logScreenView(object: ScreenViewParameters): Promise<void> {
254
306
  if (!isObject(object)) {
255
307
  throw new Error(
256
308
  'firebase.analytics().logScreenView(*): The supplied arg must be an object of key/values.',
@@ -263,7 +315,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
263
315
  );
264
316
  }
265
317
 
266
- logAddShippingInfo(object = {}) {
318
+ logAddShippingInfo(object: AddShippingInfoParameters = {}): Promise<void> {
267
319
  if (!isObject(object)) {
268
320
  throw new Error(
269
321
  'firebase.analytics().logAddShippingInfo(*): The supplied arg must be an object of key/values.',
@@ -282,7 +334,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
282
334
  );
283
335
  }
284
336
 
285
- logAddToCart(object = {}) {
337
+ logAddToCart(object: AddToCartEventParameters = {}): Promise<void> {
286
338
  if (!isObject(object)) {
287
339
  throw new Error(
288
340
  'firebase.analytics().logAddToCart(*): The supplied arg must be an object of key/values.',
@@ -297,7 +349,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
297
349
  );
298
350
  }
299
351
 
300
- logAddToWishlist(object = {}) {
352
+ logAddToWishlist(object: AddToWishlistEventParameters = {}): Promise<void> {
301
353
  if (!isObject(object)) {
302
354
  throw new Error(
303
355
  'firebase.analytics().logAddToWishlist(*): The supplied arg must be an object of key/values.',
@@ -312,11 +364,11 @@ class FirebaseAnalyticsModule extends FirebaseModule {
312
364
  );
313
365
  }
314
366
 
315
- logAppOpen() {
367
+ logAppOpen(): Promise<void> {
316
368
  return this.logEvent('app_open');
317
369
  }
318
370
 
319
- logBeginCheckout(object = {}) {
371
+ logBeginCheckout(object: BeginCheckoutEventParameters = {}): Promise<void> {
320
372
  if (!isObject(object)) {
321
373
  throw new Error(
322
374
  'firebase.analytics().logBeginCheckout(*): The supplied arg must be an object of key/values.',
@@ -331,7 +383,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
331
383
  );
332
384
  }
333
385
 
334
- logCampaignDetails(object) {
386
+ logCampaignDetails(object: CampaignDetailsEventParameters): Promise<void> {
335
387
  if (!isObject(object)) {
336
388
  throw new Error(
337
389
  'firebase.analytics().logCampaignDetails(*): The supplied arg must be an object of key/values.',
@@ -348,7 +400,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
348
400
  );
349
401
  }
350
402
 
351
- logEarnVirtualCurrency(object) {
403
+ logEarnVirtualCurrency(object: EarnVirtualCurrencyEventParameters): Promise<void> {
352
404
  if (!isObject(object)) {
353
405
  throw new Error(
354
406
  'firebase.analytics().logEarnVirtualCurrency(*): The supplied arg must be an object of key/values.',
@@ -365,7 +417,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
365
417
  );
366
418
  }
367
419
 
368
- logGenerateLead(object = {}) {
420
+ logGenerateLead(object: GenerateLeadEventParameters = {}): Promise<void> {
369
421
  if (!isObject(object)) {
370
422
  throw new Error(
371
423
  'firebase.analytics().logGenerateLead(*): The supplied arg must be an object of key/values.',
@@ -380,7 +432,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
380
432
  );
381
433
  }
382
434
 
383
- logJoinGroup(object) {
435
+ logJoinGroup(object: JoinGroupEventParameters): Promise<void> {
384
436
  if (!isObject(object)) {
385
437
  throw new Error(
386
438
  'firebase.analytics().logJoinGroup(*): The supplied arg must be an object of key/values.',
@@ -393,7 +445,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
393
445
  );
394
446
  }
395
447
 
396
- logLevelEnd(object) {
448
+ logLevelEnd(object: LevelEndEventParameters): Promise<void> {
397
449
  if (!isObject(object)) {
398
450
  throw new Error(
399
451
  'firebase.analytics().logLevelEnd(*): The supplied arg must be an object of key/values.',
@@ -406,7 +458,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
406
458
  );
407
459
  }
408
460
 
409
- logLevelStart(object) {
461
+ logLevelStart(object: LevelStartEventParameters): Promise<void> {
410
462
  if (!isObject(object)) {
411
463
  throw new Error(
412
464
  'firebase.analytics().logLevelStart(*): The supplied arg must be an object of key/values.',
@@ -419,7 +471,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
419
471
  );
420
472
  }
421
473
 
422
- logLevelUp(object) {
474
+ logLevelUp(object: LevelUpEventParameters): Promise<void> {
423
475
  if (!isObject(object)) {
424
476
  throw new Error(
425
477
  'firebase.analytics().logLevelUp(*): The supplied arg must be an object of key/values.',
@@ -432,7 +484,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
432
484
  );
433
485
  }
434
486
 
435
- logLogin(object) {
487
+ logLogin(object: LoginEventParameters): Promise<void> {
436
488
  if (!isObject(object)) {
437
489
  throw new Error(
438
490
  'firebase.analytics().logLogin(*): The supplied arg must be an object of key/values.',
@@ -445,7 +497,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
445
497
  );
446
498
  }
447
499
 
448
- logPostScore(object) {
500
+ logPostScore(object: PostScoreEventParameters): Promise<void> {
449
501
  if (!isObject(object)) {
450
502
  throw new Error(
451
503
  'firebase.analytics().logPostScore(*): The supplied arg must be an object of key/values.',
@@ -458,7 +510,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
458
510
  );
459
511
  }
460
512
 
461
- logSelectContent(object) {
513
+ logSelectContent(object: SelectContentEventParameters): Promise<void> {
462
514
  if (!isObject(object)) {
463
515
  throw new Error(
464
516
  'firebase.analytics().logSelectContent(*): The supplied arg must be an object of key/values.',
@@ -471,7 +523,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
471
523
  );
472
524
  }
473
525
 
474
- logPurchase(object = {}) {
526
+ logPurchase(object: PurchaseEventParameters = {}): Promise<void> {
475
527
  if (!isObject(object)) {
476
528
  throw new Error(
477
529
  'firebase.analytics().logPurchase(*): The supplied arg must be an object of key/values.',
@@ -486,7 +538,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
486
538
  );
487
539
  }
488
540
 
489
- logRefund(object = {}) {
541
+ logRefund(object: RefundEventParameters = {}): Promise<void> {
490
542
  if (!isObject(object)) {
491
543
  throw new Error(
492
544
  'firebase.analytics().logRefund(*): The supplied arg must be an object of key/values.',
@@ -501,7 +553,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
501
553
  );
502
554
  }
503
555
 
504
- logRemoveFromCart(object = {}) {
556
+ logRemoveFromCart(object: RemoveFromCartEventParameters = {}): Promise<void> {
505
557
  if (!isObject(object)) {
506
558
  throw new Error(
507
559
  'firebase.analytics().logRemoveFromCart(*): The supplied arg must be an object of key/values.',
@@ -516,7 +568,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
516
568
  );
517
569
  }
518
570
 
519
- logSearch(object) {
571
+ logSearch(object: SearchEventParameters): Promise<void> {
520
572
  if (!isObject(object)) {
521
573
  throw new Error(
522
574
  'firebase.analytics().logSearch(*): The supplied arg must be an object of key/values.',
@@ -529,7 +581,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
529
581
  );
530
582
  }
531
583
 
532
- logSelectItem(object = {}) {
584
+ logSelectItem(object: SelectItemEventParameters): Promise<void> {
533
585
  if (!isObject(object)) {
534
586
  throw new Error(
535
587
  'firebase.analytics().logSelectItem(*): The supplied arg must be an object of key/values.',
@@ -542,7 +594,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
542
594
  );
543
595
  }
544
596
 
545
- logSetCheckoutOption(object) {
597
+ logSetCheckoutOption(object: SetCheckoutOptionEventParameters): Promise<void> {
546
598
  if (!isObject(object)) {
547
599
  throw new Error(
548
600
  'firebase.analytics().logSetCheckoutOption(*): The supplied arg must be an object of key/values.',
@@ -559,7 +611,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
559
611
  );
560
612
  }
561
613
 
562
- logSelectPromotion(object) {
614
+ logSelectPromotion(object: SelectPromotionEventParameters): Promise<void> {
563
615
  if (!isObject(object)) {
564
616
  throw new Error(
565
617
  'firebase.analytics().logSelectPromotion(*): The supplied arg must be an object of key/values.',
@@ -576,7 +628,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
576
628
  );
577
629
  }
578
630
 
579
- logShare(object) {
631
+ logShare(object: ShareEventParameters): Promise<void> {
580
632
  if (!isObject(object)) {
581
633
  throw new Error(
582
634
  'firebase.analytics().logShare(*): The supplied arg must be an object of key/values.',
@@ -589,7 +641,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
589
641
  );
590
642
  }
591
643
 
592
- logSignUp(object) {
644
+ logSignUp(object: SignUpEventParameters): Promise<void> {
593
645
  if (!isObject(object)) {
594
646
  throw new Error(
595
647
  'firebase.analytics().logSignUp(*): The supplied arg must be an object of key/values.',
@@ -602,7 +654,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
602
654
  );
603
655
  }
604
656
 
605
- logSpendVirtualCurrency(object) {
657
+ logSpendVirtualCurrency(object: SpendVirtualCurrencyEventParameters): Promise<void> {
606
658
  if (!isObject(object)) {
607
659
  throw new Error(
608
660
  'firebase.analytics().logSpendVirtualCurrency(*): The supplied arg must be an object of key/values.',
@@ -619,15 +671,15 @@ class FirebaseAnalyticsModule extends FirebaseModule {
619
671
  );
620
672
  }
621
673
 
622
- logTutorialBegin() {
674
+ logTutorialBegin(): Promise<void> {
623
675
  return this.logEvent('tutorial_begin');
624
676
  }
625
677
 
626
- logTutorialComplete() {
678
+ logTutorialComplete(): Promise<void> {
627
679
  return this.logEvent('tutorial_complete');
628
680
  }
629
681
 
630
- logUnlockAchievement(object) {
682
+ logUnlockAchievement(object: UnlockAchievementEventParameters): Promise<void> {
631
683
  if (!isObject(object)) {
632
684
  throw new Error(
633
685
  'firebase.analytics().logUnlockAchievement(*): The supplied arg must be an object of key/values.',
@@ -644,7 +696,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
644
696
  );
645
697
  }
646
698
 
647
- logViewCart(object = {}) {
699
+ logViewCart(object: ViewCartEventParameters = {}): Promise<void> {
648
700
  if (!isObject(object)) {
649
701
  throw new Error(
650
702
  'firebase.analytics().logViewCart(*): The supplied arg must be an object of key/values.',
@@ -659,7 +711,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
659
711
  );
660
712
  }
661
713
 
662
- logViewItem(object = {}) {
714
+ logViewItem(object: ViewItemEventParameters = {}): Promise<void> {
663
715
  if (!isObject(object)) {
664
716
  throw new Error(
665
717
  'firebase.analytics().logViewItem(*): The supplied arg must be an object of key/values.',
@@ -673,7 +725,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
673
725
  );
674
726
  }
675
727
 
676
- logViewItemList(object = {}) {
728
+ logViewItemList(object: ViewItemListEventParameters = {}): Promise<void> {
677
729
  if (!isObject(object)) {
678
730
  throw new Error(
679
731
  'firebase.analytics().logViewItemList(*): The supplied arg must be an object of key/values.',
@@ -686,7 +738,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
686
738
  );
687
739
  }
688
740
 
689
- logViewPromotion(object = {}) {
741
+ logViewPromotion(object: ViewPromotionEventParameters = {}): Promise<void> {
690
742
  if (!isObject(object)) {
691
743
  throw new Error(
692
744
  'firebase.analytics().logViewPromotion(*): The supplied arg must be an object of key/values.',
@@ -702,7 +754,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
702
754
  * Unsupported in "Enhanced Ecommerce reports":
703
755
  * https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Event#public-static-final-string-view_search_results
704
756
  */
705
- logViewSearchResults(object) {
757
+ logViewSearchResults(object: ViewSearchResultsParameters): Promise<void> {
706
758
  if (!isObject(object)) {
707
759
  throw new Error(
708
760
  'firebase.analytics().logViewSearchResults(*): The supplied arg must be an object of key/values.',
@@ -719,7 +771,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
719
771
  );
720
772
  }
721
773
 
722
- setDefaultEventParameters(params) {
774
+ setDefaultEventParameters(params?: { [key: string]: any }): Promise<void> {
723
775
  if (!isObject(params) && !isNull(params) && !isUndefined(params)) {
724
776
  throw new Error(
725
777
  "firebase.analytics().setDefaultEventParameters(*) 'params' expected an object value when it is defined.",
@@ -729,7 +781,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
729
781
  return this.native.setDefaultEventParameters(params);
730
782
  }
731
783
 
732
- initiateOnDeviceConversionMeasurementWithEmailAddress(emailAddress) {
784
+ initiateOnDeviceConversionMeasurementWithEmailAddress(emailAddress: string): Promise<void> {
733
785
  if (!isString(emailAddress)) {
734
786
  throw new Error(
735
787
  "firebase.analytics().initiateOnDeviceConversionMeasurementWithEmailAddress(*) 'emailAddress' expected a string value.",
@@ -737,13 +789,15 @@ class FirebaseAnalyticsModule extends FirebaseModule {
737
789
  }
738
790
 
739
791
  if (!isIOS) {
740
- return;
792
+ return Promise.resolve();
741
793
  }
742
794
 
743
795
  return this.native.initiateOnDeviceConversionMeasurementWithEmailAddress(emailAddress);
744
796
  }
745
797
 
746
- initiateOnDeviceConversionMeasurementWithHashedEmailAddress(hashedEmailAddress) {
798
+ initiateOnDeviceConversionMeasurementWithHashedEmailAddress(
799
+ hashedEmailAddress: string,
800
+ ): Promise<void> {
747
801
  if (!isString(hashedEmailAddress)) {
748
802
  throw new Error(
749
803
  "firebase.analytics().initiateOnDeviceConversionMeasurementWithHashedEmailAddress(*) 'hashedEmailAddress' expected a string value.",
@@ -751,7 +805,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
751
805
  }
752
806
 
753
807
  if (!isIOS) {
754
- return;
808
+ return Promise.resolve();
755
809
  }
756
810
 
757
811
  return this.native.initiateOnDeviceConversionMeasurementWithHashedEmailAddress(
@@ -759,7 +813,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
759
813
  );
760
814
  }
761
815
 
762
- initiateOnDeviceConversionMeasurementWithPhoneNumber(phoneNumber) {
816
+ initiateOnDeviceConversionMeasurementWithPhoneNumber(phoneNumber: string): Promise<void> {
763
817
  if (!isE164PhoneNumber(phoneNumber)) {
764
818
  throw new Error(
765
819
  "firebase.analytics().initiateOnDeviceConversionMeasurementWithPhoneNumber(*) 'phoneNumber' expected a string value in E.164 format.",
@@ -767,13 +821,15 @@ class FirebaseAnalyticsModule extends FirebaseModule {
767
821
  }
768
822
 
769
823
  if (!isIOS) {
770
- return;
824
+ return Promise.resolve();
771
825
  }
772
826
 
773
827
  return this.native.initiateOnDeviceConversionMeasurementWithPhoneNumber(phoneNumber);
774
828
  }
775
829
 
776
- initiateOnDeviceConversionMeasurementWithHashedPhoneNumber(hashedPhoneNumber) {
830
+ initiateOnDeviceConversionMeasurementWithHashedPhoneNumber(
831
+ hashedPhoneNumber: string,
832
+ ): Promise<void> {
777
833
  if (isE164PhoneNumber(hashedPhoneNumber)) {
778
834
  throw new Error(
779
835
  "firebase.analytics().initiateOnDeviceConversionMeasurementWithHashedPhoneNumber(*) 'hashedPhoneNumber' expected a sha256-hashed value of a phone number in E.164 format.",
@@ -787,7 +843,7 @@ class FirebaseAnalyticsModule extends FirebaseModule {
787
843
  }
788
844
 
789
845
  if (!isIOS) {
790
- return;
846
+ return Promise.resolve();
791
847
  }
792
848
 
793
849
  return this.native.initiateOnDeviceConversionMeasurementWithHashedPhoneNumber(
@@ -797,11 +853,16 @@ class FirebaseAnalyticsModule extends FirebaseModule {
797
853
  }
798
854
 
799
855
  // import { SDK_VERSION } from '@react-native-firebase/analytics';
800
- export const SDK_VERSION = version;
856
+ export const SDK_VERSION: string = version;
801
857
 
802
858
  // import analytics from '@react-native-firebase/analytics';
803
859
  // analytics().logEvent(...);
804
- export default createModuleNamespace({
860
+
861
+ // import analytics, { firebase } from '@react-native-firebase/analytics';
862
+ // analytics().logEvent(...);
863
+ // firebase.analytics().logEvent(...);
864
+
865
+ const analyticsNamespace = createModuleNamespace({
805
866
  statics,
806
867
  version,
807
868
  namespace,
@@ -812,12 +873,24 @@ export default createModuleNamespace({
812
873
  ModuleClass: FirebaseAnalyticsModule,
813
874
  });
814
875
 
815
- export * from './modular/index';
876
+ type AnalyticsNamespace = ReactNativeFirebase.FirebaseModuleWithStaticsAndApp<
877
+ Analytics,
878
+ Statics
879
+ > & {
880
+ analytics: ReactNativeFirebase.FirebaseModuleWithStaticsAndApp<Analytics, Statics>;
881
+ firebase: ReactNativeFirebase.Module;
882
+ app(name?: string): ReactNativeFirebase.FirebaseApp;
883
+ };
816
884
 
817
- // import analytics, { firebase } from '@react-native-firebase/analytics';
818
- // analytics().logEvent(...);
819
- // firebase.analytics().logEvent(...);
820
- export const firebase = getFirebaseRoot();
885
+ export default analyticsNamespace as unknown as AnalyticsNamespace;
821
886
 
822
887
  // Register the interop module for non-native platforms.
823
- setReactNativeModule(nativeModuleName, fallBackModule);
888
+ setReactNativeModule(nativeModuleName, RNFBAnalyticsModule as unknown as Record<string, unknown>);
889
+
890
+ export const firebase =
891
+ getFirebaseRoot() as unknown as ReactNativeFirebase.FirebaseNamespacedExport<
892
+ 'analytics',
893
+ Analytics,
894
+ Statics,
895
+ false
896
+ >;
package/lib/struct.ts ADDED
@@ -0,0 +1,61 @@
1
+ /*
2
+ * Copyright (c) 2016-present Invertase Limited & Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this library except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import { isUndefined } from '@react-native-firebase/app/lib/common/validate';
18
+ import { create, StructError } from 'superstruct';
19
+
20
+ export const validateStruct = (
21
+ value: Record<string, any> = {},
22
+ struct: any,
23
+ prefix = '',
24
+ ): Record<string, any> => {
25
+ // skip superstruct create in release for performance reasons
26
+ if (!__DEV__) {
27
+ return value;
28
+ }
29
+ try {
30
+ return create(value, struct) as Record<string, any>;
31
+ } catch (e) {
32
+ const { path, message } = e as StructError;
33
+
34
+ const key = path[0];
35
+
36
+ if (message === undefined) {
37
+ throw new Error(`${prefix} unknown property '${key}'.`);
38
+ }
39
+ (e as StructError).message = `${prefix} ${message}`;
40
+
41
+ throw e;
42
+ }
43
+ };
44
+
45
+ export const validateCompound = (
46
+ source: Record<string, any> = {},
47
+ a: string,
48
+ b: string,
49
+ prefix = '',
50
+ ): void => {
51
+ const sourceA = source[a];
52
+ const sourceB = source[b];
53
+ if (
54
+ (isUndefined(sourceA) && !isUndefined(sourceB)) ||
55
+ (!isUndefined(sourceA) && isUndefined(sourceB))
56
+ ) {
57
+ throw new Error(
58
+ `${prefix} if you supply the '${a}' parameter, you must also supply the '${b}' parameter.`,
59
+ );
60
+ }
61
+ };
@@ -187,9 +187,9 @@ export const SelectPromotion = object({
187
187
  promotion_name: string(),
188
188
  });
189
189
 
190
- export const SetCheckoutOption = object({
191
- checkout_step: number(),
192
- checkout_option: string(),
190
+ export const SetCheckoutOption = type({
191
+ checkout_step: optional(number()),
192
+ checkout_option: optional(string()),
193
193
  });
194
194
 
195
195
  export const Share = object({