@appmetrica/react-native-analytics 3.6.0 → 4.1.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 (89) hide show
  1. package/android/build.gradle +12 -16
  2. package/android/src/main/AndroidManifest.xml +1 -1
  3. package/android/src/main/AndroidManifestNew.xml +1 -1
  4. package/android/src/main/java/io/appmetrica/analytics/reactnative/AppMetricaModule.java +56 -49
  5. package/android/src/main/java/io/appmetrica/analytics/reactnative/AppMetricaPackage.java +26 -14
  6. package/android/src/main/java/io/appmetrica/analytics/reactnative/ReactNativeDeferredDeeplinkListener.java +1 -3
  7. package/android/src/main/java/io/appmetrica/analytics/reactnative/ReactNativeDeferredDeeplinkParametersListener.java +4 -5
  8. package/android/src/main/java/io/appmetrica/analytics/reactnative/ReactNativeStartupParamsListener.java +23 -7
  9. package/android/src/main/java/io/appmetrica/analytics/reactnative/ReporterModule.java +17 -18
  10. package/android/src/main/java/io/appmetrica/analytics/reactnative/Utils.java +19 -27
  11. package/appmetrica-react-native-analytics.podspec +2 -23
  12. package/ios/AMARNAppMetrica.h +6 -2
  13. package/ios/{AMARNAppMetrica.m → AMARNAppMetrica.mm} +65 -39
  14. package/ios/{AMARNAppMetricaUtils.m → AMARNAppMetricaUtils.mm} +10 -1
  15. package/ios/AMARNReporter.h +6 -2
  16. package/ios/{AMARNReporter.m → AMARNReporter.mm} +24 -20
  17. package/ios/AMARNStartupParamsUtils.mm +33 -0
  18. package/lib/commonjs/deferredDeeplink.js.map +1 -1
  19. package/lib/commonjs/ecommerce.js +1 -1
  20. package/lib/commonjs/ecommerce.js.map +1 -1
  21. package/lib/commonjs/error.js +1 -1
  22. package/lib/commonjs/error.js.map +1 -1
  23. package/lib/commonjs/externalAttribution.js.map +1 -1
  24. package/lib/commonjs/index.js +63 -52
  25. package/lib/commonjs/index.js.map +1 -1
  26. package/lib/commonjs/package.json +1 -0
  27. package/lib/commonjs/reporter.js +17 -25
  28. package/lib/commonjs/reporter.js.map +1 -1
  29. package/lib/commonjs/revenue.js.map +1 -1
  30. package/lib/commonjs/specs/NativeAppMetrica.js +9 -0
  31. package/lib/commonjs/specs/NativeAppMetrica.js.map +1 -0
  32. package/lib/commonjs/specs/NativeReporter.js +9 -0
  33. package/lib/commonjs/specs/NativeReporter.js.map +1 -0
  34. package/lib/commonjs/types.js +34 -0
  35. package/lib/commonjs/types.js.map +1 -0
  36. package/lib/commonjs/userProfile.js.map +1 -1
  37. package/lib/commonjs/utils.js +1 -1
  38. package/lib/commonjs/utils.js.map +1 -1
  39. package/lib/module/deferredDeeplink.js +1 -1
  40. package/lib/module/deferredDeeplink.js.map +1 -1
  41. package/lib/module/ecommerce.js +3 -1
  42. package/lib/module/ecommerce.js.map +1 -1
  43. package/lib/module/error.js +3 -1
  44. package/lib/module/error.js.map +1 -1
  45. package/lib/module/externalAttribution.js +2 -0
  46. package/lib/module/externalAttribution.js.map +1 -1
  47. package/lib/module/index.js +24 -18
  48. package/lib/module/index.js.map +1 -1
  49. package/lib/module/reporter.js +3 -10
  50. package/lib/module/reporter.js.map +1 -1
  51. package/lib/module/revenue.js +2 -0
  52. package/lib/module/revenue.js.map +1 -1
  53. package/lib/module/specs/NativeAppMetrica.js +5 -0
  54. package/lib/module/specs/NativeAppMetrica.js.map +1 -0
  55. package/lib/module/specs/NativeReporter.js +5 -0
  56. package/lib/module/specs/NativeReporter.js.map +1 -0
  57. package/lib/module/types.js +28 -0
  58. package/lib/module/types.js.map +1 -0
  59. package/lib/module/userProfile.js +2 -0
  60. package/lib/module/userProfile.js.map +1 -1
  61. package/lib/module/utils.js +3 -1
  62. package/lib/module/utils.js.map +1 -1
  63. package/lib/typescript/src/deferredDeeplink.d.ts.map +1 -1
  64. package/lib/typescript/src/ecommerce.d.ts +1 -1
  65. package/lib/typescript/src/ecommerce.d.ts.map +1 -1
  66. package/lib/typescript/src/index.d.ts +7 -50
  67. package/lib/typescript/src/index.d.ts.map +1 -1
  68. package/lib/typescript/src/reporter.d.ts.map +1 -1
  69. package/lib/typescript/src/specs/NativeAppMetrica.d.ts +41 -0
  70. package/lib/typescript/src/specs/NativeAppMetrica.d.ts.map +1 -0
  71. package/lib/typescript/src/specs/NativeReporter.d.ts +21 -0
  72. package/lib/typescript/src/specs/NativeReporter.d.ts.map +1 -0
  73. package/lib/typescript/src/types.d.ts +74 -0
  74. package/lib/typescript/src/types.d.ts.map +1 -0
  75. package/lib/typescript/src/utils.d.ts.map +1 -1
  76. package/package.json +28 -23
  77. package/src/deferredDeeplink.ts +5 -1
  78. package/src/ecommerce.ts +2 -2
  79. package/src/error.ts +1 -1
  80. package/src/index.ts +49 -86
  81. package/src/reporter.ts +20 -25
  82. package/src/specs/NativeAppMetrica.ts +55 -0
  83. package/src/specs/NativeReporter.ts +31 -0
  84. package/src/types.ts +105 -0
  85. package/src/utils.ts +5 -3
  86. package/ios/AMARNStartupParamsUtils.m +0 -53
  87. /package/ios/{AMARNExceptionSerializer.m → AMARNExceptionSerializer.mm} +0 -0
  88. /package/ios/{AMARNExternalAttribution.m → AMARNExternalAttribution.mm} +0 -0
  89. /package/ios/{AMARNUserProfileSerializer.m → AMARNUserProfileSerializer.mm} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appmetrica/react-native-analytics",
3
- "version": "3.6.0",
3
+ "version": "4.1.0",
4
4
  "description": "React Native plugin for AppMetrica analytics tool",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -29,8 +29,10 @@
29
29
  "test": "jest",
30
30
  "typecheck": "tsc --noEmit",
31
31
  "lint": "eslint \"**/*.{js,ts,tsx}\"",
32
+ "format": "prettier --write \"src/**/*.{ts,tsx}\"",
33
+ "format:check": "prettier --check \"src/**/*.{ts,tsx}\"",
32
34
  "clean": "del-cli android/build lib",
33
- "prepare": "bob build"
35
+ "prepack": "bob build"
34
36
  },
35
37
  "keywords": [
36
38
  "appmetrica",
@@ -55,20 +57,19 @@
55
57
  "registry": "https://registry.npmjs.org/"
56
58
  },
57
59
  "devDependencies": {
58
- "@react-native/eslint-config": "^0.73.1",
59
- "@types/jest": "^29.5.5",
60
+ "@react-native/eslint-config": "^0.76.0",
61
+ "@types/jest": "^29.5.12",
60
62
  "@types/jsdom": "^21.1.7",
61
- "@types/react": "^18.2.44",
62
63
  "@types/node": "^22.10.0",
64
+ "@types/react": "^18.2.6",
63
65
  "del-cli": "^5.1.0",
64
66
  "eslint": "^8.51.0",
65
67
  "eslint-config-prettier": "^9.0.0",
66
- "eslint-plugin-prettier": "^5.0.1",
67
68
  "jest": "^29.7.0",
68
69
  "prettier": "^3.0.3",
69
- "react": "18.2.0",
70
- "react-native": "0.74.2",
71
- "react-native-builder-bob": "^0.20.0",
70
+ "react": "18.3.1",
71
+ "react-native": "0.76.0",
72
+ "react-native-builder-bob": "^0.40.17",
72
73
  "typescript": "^5.2.2"
73
74
  },
74
75
  "resolutions": {
@@ -76,7 +77,7 @@
76
77
  },
77
78
  "peerDependencies": {
78
79
  "react": "*",
79
- "react-native": "*"
80
+ "react-native": ">=0.76.0 <1.0.0"
80
81
  },
81
82
  "jest": {
82
83
  "preset": "react-native",
@@ -91,22 +92,12 @@
91
92
  "@react-native",
92
93
  "prettier"
93
94
  ],
94
- "rules": {
95
- "prettier/prettier": [
96
- "error",
97
- {
98
- "quoteProps": "consistent",
99
- "singleQuote": true,
100
- "tabWidth": 2,
101
- "trailingComma": "es5",
102
- "useTabs": false
103
- }
104
- ]
105
- }
95
+ "rules": {}
106
96
  },
107
97
  "eslintIgnore": [
108
98
  "node_modules/",
109
- "lib/"
99
+ "lib/",
100
+ "babel.config.js"
110
101
  ],
111
102
  "prettier": {
112
103
  "quoteProps": "consistent",
@@ -128,5 +119,19 @@
128
119
  }
129
120
  ]
130
121
  ]
122
+ },
123
+ "codegenConfig": {
124
+ "name": "AppMetricaNativeSpec",
125
+ "type": "modules",
126
+ "jsSrcsDir": "src/specs",
127
+ "android": {
128
+ "javaPackageName": "io.appmetrica.analytics.reactnative"
129
+ },
130
+ "ios": {
131
+ "modulesProvider": {
132
+ "AppMetrica": "AMARNAppMetrica",
133
+ "AppMetricaReporter": "AMARNReporter"
134
+ }
135
+ }
131
136
  }
132
137
  }
@@ -1,4 +1,8 @@
1
- export type DeferredDeeplinkError = 'NO_REFERRER' | 'NOT_A_FIRST_LAUNCH' | 'PARSE_ERROR' | 'UNKNOWN';
1
+ export type DeferredDeeplinkError =
2
+ | 'NO_REFERRER'
3
+ | 'NOT_A_FIRST_LAUNCH'
4
+ | 'PARSE_ERROR'
5
+ | 'UNKNOWN';
2
6
 
3
7
  export interface DeferredDeeplinkListener {
4
8
  onSuccess: (deeplink: string) => void;
package/src/ecommerce.ts CHANGED
@@ -53,7 +53,7 @@ export type ECommerceOrder = {
53
53
  };
54
54
 
55
55
  export type ECommerceEventType =
56
- | 'showSceenEvent'
56
+ | 'showScreenEvent'
57
57
  | 'showProductCardEvent'
58
58
  | 'showProductDetailsEvent'
59
59
  | 'addCartItemEvent'
@@ -73,7 +73,7 @@ export interface ECommerceEvent {
73
73
  export class ECommerce {
74
74
  static showScreenEvent(screen: ECommerceScreen): ECommerceEvent {
75
75
  return {
76
- ecommerceEvent: 'showSceenEvent',
76
+ ecommerceEvent: 'showScreenEvent',
77
77
  ecommerceScreen: normalizeECommerceScreen(screen),
78
78
  };
79
79
  }
package/src/error.ts CHANGED
@@ -47,7 +47,7 @@ function parseStackTrace(
47
47
  }
48
48
  });
49
49
  return array;
50
- } catch(e) {
50
+ } catch (e) {
51
51
  console.log(e);
52
52
  return undefined;
53
53
  }
package/src/index.ts CHANGED
@@ -1,32 +1,27 @@
1
- import { Linking, NativeModules, Platform } from 'react-native';
1
+ import { Linking } from 'react-native';
2
+ import AppMetricaNative from './specs/NativeAppMetrica';
2
3
  import type { ECommerceEvent } from './ecommerce';
3
4
  import type { AdRevenue, Revenue } from './revenue';
4
5
  import type { UserProfile } from './userProfile';
5
6
  import type { ExternalAttribution } from './externalAttribution';
6
7
  import { normalizeAdRevenue } from './utils';
7
8
  import { AppMetricaError } from './error';
8
- import { Reporter, type IReporter, type ReporterConfig } from './reporter';
9
+ import { Reporter } from './reporter';
10
+ import type { IReporter, ReporterConfig } from './reporter';
9
11
  import type {
10
12
  DeferredDeeplinkListener,
11
13
  DeferredDeeplinkParametersListener,
14
+ DeferredDeeplinkError,
12
15
  } from './deferredDeeplink';
13
16
 
14
- const LINKING_ERROR =
15
- `The package '@appmetrica/react-native-analytics' doesn't seem to be linked. Make sure: \n\n` +
16
- Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
17
- '- You rebuilt the app after installing the package\n' +
18
- '- You are not using Expo Go\n';
19
-
20
- const AppMetricaNative = NativeModules.AppMetrica
21
- ? NativeModules.AppMetrica
22
- : new Proxy(
23
- {},
24
- {
25
- get() {
26
- throw new Error(LINKING_ERROR);
27
- },
28
- }
29
- );
17
+ import type {
18
+ AppMetricaConfig,
19
+ StartupParamsReason,
20
+ StartupParamsCallback,
21
+ Location,
22
+ StartupParamsItem,
23
+ } from './types';
24
+ import { StartupParams } from './types';
30
25
 
31
26
  var activated = false;
32
27
 
@@ -44,71 +39,15 @@ function appOpenTracking() {
44
39
  Linking.addEventListener('url', callback);
45
40
  }
46
41
 
47
- export type AppMetricaConfig = {
48
- apiKey: string;
49
- appVersion?: string;
50
- crashReporting?: boolean;
51
- firstActivationAsUpdate?: boolean;
52
- location?: Location;
53
- locationTracking?: boolean;
54
- logs?: boolean;
55
- sessionTimeout?: number;
56
- statisticsSending?: boolean;
57
- preloadInfo?: PreloadInfo;
58
- maxReportsInDatabaseCount?: number;
59
- nativeCrashReporting?: boolean; // Android only
60
- activationAsSessionStart?: boolean; // iOS only
61
- sessionsAutoTracking?: boolean; // iOS only
62
- appOpenTrackingEnabled?: boolean;
63
- userProfileID?: string;
64
-
65
- errorEnvironment?: Record<string, string | undefined>;
66
- appEnvironment?: Record<string, string | undefined>;
67
- maxReportsCount?: number;
68
- dispatchPeriodSeconds?: number;
69
- };
70
-
71
- export type PreloadInfo = {
72
- trackingId: string;
73
- additionalInfo?: Record<string, string>;
74
- };
75
-
76
- export type Location = {
77
- latitude: number;
78
- longitude: number;
79
- altitude?: number;
80
- accuracy?: number;
81
- course?: number;
82
- speed?: number;
83
- timestamp?: number;
84
- };
85
-
86
- export type StartupParamsReason = 'UNKNOWN' | 'NETWORK' | 'INVALID_RESPONSE';
87
-
88
- export type StartupParams = {
89
- deviceIdHash?: string;
90
- deviceId?: string;
91
- uuid?: string;
92
- };
93
-
94
- export type StartupParamsCallback = (
95
- params?: StartupParams,
96
- reason?: StartupParamsReason
97
- ) => void;
98
-
99
- export const DEVICE_ID_HASH_KEY = 'appmetrica_device_id_hash';
100
- export const DEVICE_ID_KEY = 'appmetrica_device_id';
101
- export const UUID_KEY = 'appmetrica_uuid';
102
-
103
42
  export * from './ecommerce';
104
43
  export * from './revenue';
105
44
  export * from './userProfile';
106
45
  export * from './externalAttribution';
107
46
  export type { IReporter, ReporterConfig } from './reporter';
108
47
  export * from './deferredDeeplink';
48
+ export * from './types';
109
49
 
110
50
  export default class AppMetrica {
111
-
112
51
  private static reporters: Map<string, Reporter> = new Map();
113
52
 
114
53
  static activate(config: AppMetricaConfig) {
@@ -122,11 +61,11 @@ export default class AppMetrica {
122
61
  }
123
62
 
124
63
  // Android only
125
- static async getLibraryApiLevel(): Promise<number> {
64
+ static getLibraryApiLevel(): number {
126
65
  return AppMetricaNative.getLibraryApiLevel();
127
66
  }
128
67
 
129
- static async getLibraryVersion(): Promise<string> {
68
+ static getLibraryVersion(): string {
130
69
  return AppMetricaNative.getLibraryVersion();
131
70
  }
132
71
 
@@ -146,7 +85,9 @@ export default class AppMetrica {
146
85
  AppMetricaNative.reportError(
147
86
  identifier,
148
87
  message,
149
- _reason instanceof Error ? AppMetricaError.withError(_reason) : AppMetricaError.withObject(_reason)
88
+ _reason instanceof Error
89
+ ? AppMetricaError.withError(_reason)
90
+ : AppMetricaError.withObject(_reason)
150
91
  );
151
92
  }
152
93
 
@@ -154,8 +95,14 @@ export default class AppMetrica {
154
95
  AppMetricaNative.reportUnhandledException(AppMetricaError.withError(error));
155
96
  }
156
97
 
157
- static reportErrorWithoutIdentifier(message: string | undefined, error: Error) {
158
- AppMetricaNative.reportErrorWithoutIdentifier(message, AppMetricaError.withError(error));
98
+ static reportErrorWithoutIdentifier(
99
+ message: string | undefined,
100
+ error: Error
101
+ ) {
102
+ AppMetricaNative.reportErrorWithoutIdentifier(
103
+ message,
104
+ AppMetricaError.withError(error)
105
+ );
159
106
  }
160
107
 
161
108
  static reportEvent(eventName: string, attributes?: Record<string, any>) {
@@ -166,7 +113,13 @@ export default class AppMetrica {
166
113
  listener: StartupParamsCallback,
167
114
  identifiers: Array<string>
168
115
  ) {
169
- AppMetricaNative.requestStartupParams(identifiers, listener);
116
+ const adapter = (params?: Object, reason?: Object) => {
117
+ const startupParams = params
118
+ ? new StartupParams(params as Record<string, StartupParamsItem>)
119
+ : undefined;
120
+ listener(startupParams, reason as StartupParamsReason);
121
+ };
122
+ AppMetricaNative.requestStartupParams(adapter, identifiers);
170
123
  }
171
124
 
172
125
  static resumeSession() {
@@ -240,17 +193,21 @@ export default class AppMetrica {
240
193
  AppMetricaNative.activateReporter(config);
241
194
  }
242
195
 
243
- static getDeviceId(): Promise<string | null> {
196
+ static getDeviceId(): string | null {
244
197
  return AppMetricaNative.getDeviceId();
245
198
  }
246
199
 
247
- static getUuid(): Promise<string | null> {
200
+ static getUuid(): string | null {
248
201
  return AppMetricaNative.getUuid();
249
202
  }
250
203
 
251
204
  static requestDeferredDeeplink(listener: DeferredDeeplinkListener) {
205
+ const adaptedOnFailure = (error: string, referrer?: string) => {
206
+ listener.onFailure(error as DeferredDeeplinkError, referrer);
207
+ };
208
+
252
209
  AppMetricaNative.requestDeferredDeeplink(
253
- listener.onFailure,
210
+ adaptedOnFailure,
254
211
  listener.onSuccess
255
212
  );
256
213
  }
@@ -258,9 +215,15 @@ export default class AppMetrica {
258
215
  static requestDeferredDeeplinkParameters(
259
216
  listener: DeferredDeeplinkParametersListener
260
217
  ) {
218
+ const adaptedOnFailure = (error: string, referrer?: string) => {
219
+ listener.onFailure(error as DeferredDeeplinkError, referrer);
220
+ };
221
+ const adaptedOnSuccess = (parameters: Object) => {
222
+ listener.onSuccess(parameters as Record<string, string>);
223
+ };
261
224
  AppMetricaNative.requestDeferredDeeplinkParameters(
262
- listener.onFailure,
263
- listener.onSuccess
225
+ adaptedOnFailure,
226
+ adaptedOnSuccess
264
227
  );
265
228
  }
266
229
  }
package/src/reporter.ts CHANGED
@@ -1,28 +1,15 @@
1
- import { NativeModules, Platform } from 'react-native';
2
1
  import type { UserProfile } from './userProfile';
3
2
  import type { AdRevenue, Revenue } from './revenue';
4
3
  import type { ECommerceEvent } from './ecommerce';
5
4
  import { AppMetricaError } from './error';
6
-
7
- const LINKING_ERROR =
8
- `The package '@appmetrica/react-native-analytics' doesn't seem to be linked. Make sure: \n\n` +
9
- Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
10
- '- You rebuilt the app after installing the package\n' +
11
- '- You are not using Expo Go\n';
12
-
13
- const ReporterNativeModule = NativeModules.AppMetricaReporter
14
- ? NativeModules.AppMetricaReporter
15
- : new Proxy(
16
- {},
17
- {
18
- get() {
19
- throw new Error(LINKING_ERROR);
20
- },
21
- }
22
- );
5
+ import ReporterNativeModule from './specs/NativeReporter';
23
6
 
24
7
  export interface IReporter {
25
- reportError(identifier: string, message?: string, _reason?: Error | Object): void;
8
+ reportError(
9
+ identifier: string,
10
+ message?: string,
11
+ _reason?: Error | Object
12
+ ): void;
26
13
  reportErrorWithoutIdentifier(message: string | undefined, error: Error): void;
27
14
  reportUnhandledException(error: Error): void;
28
15
  reportEvent(eventName: string, attributes?: Record<string, any>): void;
@@ -40,7 +27,6 @@ export interface IReporter {
40
27
  }
41
28
 
42
29
  export class Reporter implements IReporter {
43
-
44
30
  private apiKey: string;
45
31
 
46
32
  constructor(apiKey: string) {
@@ -52,16 +38,25 @@ export class Reporter implements IReporter {
52
38
  this.apiKey,
53
39
  identifier,
54
40
  message,
55
- _reason instanceof Error ? AppMetricaError.withError(_reason) : AppMetricaError.withObject(_reason)
41
+ _reason instanceof Error
42
+ ? AppMetricaError.withError(_reason)
43
+ : AppMetricaError.withObject(_reason)
56
44
  );
57
45
  }
58
46
 
59
47
  reportErrorWithoutIdentifier(message: string | undefined, error: Error) {
60
- ReporterNativeModule.reportErrorWithoutIdentifier(this.apiKey, message, AppMetricaError.withError(error));
48
+ ReporterNativeModule.reportErrorWithoutIdentifier(
49
+ this.apiKey,
50
+ message,
51
+ AppMetricaError.withError(error)
52
+ );
61
53
  }
62
54
 
63
55
  reportUnhandledException(error: Error) {
64
- ReporterNativeModule.reportUnhandledException(this.apiKey, AppMetricaError.withError(error));
56
+ ReporterNativeModule.reportUnhandledException(
57
+ this.apiKey,
58
+ AppMetricaError.withError(error)
59
+ );
65
60
  }
66
61
 
67
62
  reportEvent(eventName: string, attributes?: Record<string, any>) {
@@ -109,7 +104,7 @@ export class Reporter implements IReporter {
109
104
  }
110
105
 
111
106
  reportRevenue(revenue: Revenue) {
112
- ReporterNativeModule.reportRevenue(this.apiKey, revenue)
107
+ ReporterNativeModule.reportRevenue(this.apiKey, revenue);
113
108
  }
114
109
  }
115
110
 
@@ -123,4 +118,4 @@ export type ReporterConfig = {
123
118
  dispatchPeriodSeconds?: number;
124
119
  userProfileID?: string;
125
120
  maxReportsCount?: number;
126
- }
121
+ };
@@ -0,0 +1,55 @@
1
+ import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport';
2
+ import { TurboModuleRegistry } from 'react-native';
3
+
4
+ export interface Spec extends TurboModule {
5
+ activate(config: Object): void;
6
+ pauseSession(): void;
7
+ resumeSession(): void;
8
+ sendEventsBuffer(): void;
9
+ setDataSendingEnabled(enabled: boolean): void;
10
+ setLocationTracking(enabled: boolean): void;
11
+ setLocation(location?: Object): void;
12
+ setUserProfileID(userProfileID?: string): void;
13
+ reportAppOpen(deeplink?: string): void;
14
+ reportEvent(eventName: string, attributes?: Object): void;
15
+ reportECommerce(event: Object): void;
16
+ reportRevenue(revenue: Object): void;
17
+ reportAdRevenue(adRevenue: Object): void;
18
+ reportUserProfile(userProfile: Object): void;
19
+ reportExternalAttribution(attribution: Object): void;
20
+ reportError(identifier: string, message?: string, error?: Object): void;
21
+ reportErrorWithoutIdentifier(
22
+ message: string | undefined,
23
+ error: Object
24
+ ): void;
25
+ reportUnhandledException(error: Object): void;
26
+ putAppEnvironmentValue(key: string, value?: string): void;
27
+ putErrorEnvironmentValue(key: string, value?: string): void;
28
+ clearAppEnvironment(): void;
29
+ activateReporter(config: Object): void;
30
+ touchReporter(apiKey: string): void;
31
+ requestStartupParams(
32
+ listener: (params?: Object, reason?: Object) => void,
33
+ identifiers: Array<string>
34
+ ): void;
35
+ requestDeferredDeeplink(
36
+ onFailure: (error: string, referrer?: string) => void,
37
+ onSuccess: (deeplink: string) => void
38
+ ): void;
39
+ requestDeferredDeeplinkParameters(
40
+ onFailure: (error: string, referrer?: string) => void,
41
+ onSuccess: (parameters: Object) => void
42
+ ): void;
43
+ getDeviceId(): string | null;
44
+ getUuid(): string | null;
45
+ getLibraryVersion(): string;
46
+ getLibraryApiLevel(): number;
47
+
48
+ readonly getConstants: () => {
49
+ DEVICE_ID_HASH_KEY: string;
50
+ DEVICE_ID_KEY: string;
51
+ UUID_KEY: string;
52
+ };
53
+ }
54
+
55
+ export default TurboModuleRegistry.getEnforcing<Spec>('AppMetrica');
@@ -0,0 +1,31 @@
1
+ import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport';
2
+ import { TurboModuleRegistry } from 'react-native';
3
+
4
+ export interface Spec extends TurboModule {
5
+ pauseSession(apiKey: string): void;
6
+ resumeSession(apiKey: string): void;
7
+ sendEventsBuffer(apiKey: string): void;
8
+ setDataSendingEnabled(apiKey: string, enabled: boolean): void;
9
+ setUserProfileID(apiKey: string, userProfileID?: string): void;
10
+ reportEvent(apiKey: string, eventName: string, attributes?: Object): void;
11
+ reportECommerce(apiKey: string, event: Object): void;
12
+ reportRevenue(apiKey: string, revenue: Object): void;
13
+ reportAdRevenue(apiKey: string, adRevenue: Object): void;
14
+ reportUserProfile(apiKey: string, userProfile: Object): void;
15
+ reportError(
16
+ apiKey: string,
17
+ identifier: string,
18
+ message?: string,
19
+ error?: Object
20
+ ): void;
21
+ reportErrorWithoutIdentifier(
22
+ apiKey: string,
23
+ message: string | undefined,
24
+ error: Object
25
+ ): void;
26
+ reportUnhandledException(apiKey: string, error: Object): void;
27
+ putAppEnvironmentValue(apiKey: string, key: string, value?: string): void;
28
+ clearAppEnvironment(apiKey: string): void;
29
+ }
30
+
31
+ export default TurboModuleRegistry.getEnforcing<Spec>('AppMetricaReporter');
package/src/types.ts ADDED
@@ -0,0 +1,105 @@
1
+ import AppMetricaNative from './specs/NativeAppMetrica';
2
+
3
+ export type AppMetricaConfig = {
4
+ apiKey: string;
5
+ appVersion?: string;
6
+ crashReporting?: boolean;
7
+ firstActivationAsUpdate?: boolean;
8
+ location?: Location;
9
+ locationTracking?: boolean;
10
+ logs?: boolean;
11
+ sessionTimeout?: number;
12
+ statisticsSending?: boolean;
13
+ preloadInfo?: PreloadInfo;
14
+ maxReportsInDatabaseCount?: number;
15
+ nativeCrashReporting?: boolean;
16
+ activationAsSessionStart?: boolean;
17
+ sessionsAutoTracking?: boolean;
18
+ appOpenTrackingEnabled?: boolean;
19
+ userProfileID?: string;
20
+ errorEnvironment?: Record<string, string | undefined>;
21
+ appEnvironment?: Record<string, string | undefined>;
22
+ maxReportsCount?: number;
23
+ dispatchPeriodSeconds?: number;
24
+ appBuildNumber?: number;
25
+ revenueAutoTrackingEnabled?: boolean;
26
+ deviceType?: string;
27
+ advIdentifiersTracking?: boolean;
28
+ };
29
+
30
+ export type PreloadInfo = {
31
+ trackingId: string;
32
+ additionalInfo?: Record<string, string>;
33
+ };
34
+
35
+ export type Location = {
36
+ latitude: number;
37
+ longitude: number;
38
+ altitude?: number;
39
+ accuracy?: number;
40
+ course?: number;
41
+ speed?: number;
42
+ timestamp?: number;
43
+ };
44
+
45
+ export type StartupParamsReason = 'UNKNOWN' | 'NETWORK' | 'INVALID_RESPONSE';
46
+
47
+ export class StartupParams {
48
+ private static constants = AppMetricaNative.getConstants();
49
+ static readonly DEVICE_ID_HASH_KEY = this.constants.DEVICE_ID_HASH_KEY;
50
+ static readonly DEVICE_ID_KEY = this.constants.DEVICE_ID_KEY;
51
+ static readonly UUID_KEY = this.constants.UUID_KEY;
52
+
53
+ readonly deviceIdHash?: string;
54
+ readonly deviceId?: string;
55
+ readonly uuid?: string;
56
+
57
+ constructor(readonly params?: Record<string, StartupParamsItem>) {
58
+ if (params) {
59
+ this.deviceIdHash = this.parameterForKey(
60
+ StartupParams.DEVICE_ID_HASH_KEY
61
+ );
62
+ this.deviceId = this.parameterForKey(StartupParams.DEVICE_ID_KEY);
63
+ this.uuid = this.parameterForKey(StartupParams.UUID_KEY);
64
+ }
65
+ }
66
+
67
+ parameterForKey(key: string): string | undefined {
68
+ return this.params?.[key]?.id;
69
+ }
70
+ }
71
+
72
+ export type StartupParamsCallback = (
73
+ params?: StartupParams,
74
+ reason?: StartupParamsReason
75
+ ) => void;
76
+
77
+ export type ReporterConfig = {
78
+ apiKey: string;
79
+ sessionTimeout?: number;
80
+ statisticsSending?: boolean;
81
+ maxReportsCount?: number;
82
+ dispatchPeriodSeconds?: number;
83
+ logs?: boolean;
84
+ };
85
+
86
+ export type StartupParamsItem = {
87
+ id?: string;
88
+ errorDetails?: string;
89
+ status: StartupParamsItemStatus;
90
+ };
91
+
92
+ export type StartupParamsItemStatus =
93
+ | 'OK'
94
+ | 'FEATURE_DISABLED'
95
+ | 'INVALID_VALUE_FROM_PROVIDER'
96
+ | 'NETWORK_ERROR'
97
+ | 'PROVIDER_UNAVAILABLE'
98
+ | 'UNKNOWN_ERROR';
99
+
100
+ export enum PredefinedDeviceTypes {
101
+ PHONE = 'phone',
102
+ TABLET = 'tablet',
103
+ TV = 'tv',
104
+ CAR = 'car',
105
+ }
package/src/utils.ts CHANGED
@@ -18,7 +18,7 @@ export function normalizeECommerceOrder(order: ECommerceOrder): ECommerceOrder {
18
18
  if (order.payload instanceof Map) {
19
19
  newOrder.payload = convertMap(order.payload);
20
20
  }
21
- newOrder.products = order.products.map(normalizeECommerceCartItem)
21
+ newOrder.products = order.products.map(normalizeECommerceCartItem);
22
22
  return newOrder;
23
23
  }
24
24
 
@@ -48,13 +48,15 @@ export function normalizeECommerceReferrer(
48
48
  return undefined;
49
49
  }
50
50
  const newReferrer = { ...referrer } as ECommerceReferrer;
51
- if (referrer.screen != undefined) {
51
+ if (referrer.screen !== undefined) {
52
52
  newReferrer.screen = normalizeECommerceScreen(referrer.screen);
53
53
  }
54
54
  return newReferrer;
55
55
  }
56
56
 
57
- export function normalizeECommerceScreen(screen: ECommerceScreen): ECommerceScreen {
57
+ export function normalizeECommerceScreen(
58
+ screen: ECommerceScreen
59
+ ): ECommerceScreen {
58
60
  const newScreen = { ...screen } as ECommerceScreen;
59
61
  if (screen.payload instanceof Map) {
60
62
  newScreen.payload = convertMap(screen.payload);