@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.
- package/android/build.gradle +12 -16
- package/android/src/main/AndroidManifest.xml +1 -1
- package/android/src/main/AndroidManifestNew.xml +1 -1
- package/android/src/main/java/io/appmetrica/analytics/reactnative/AppMetricaModule.java +56 -49
- package/android/src/main/java/io/appmetrica/analytics/reactnative/AppMetricaPackage.java +26 -14
- package/android/src/main/java/io/appmetrica/analytics/reactnative/ReactNativeDeferredDeeplinkListener.java +1 -3
- package/android/src/main/java/io/appmetrica/analytics/reactnative/ReactNativeDeferredDeeplinkParametersListener.java +4 -5
- package/android/src/main/java/io/appmetrica/analytics/reactnative/ReactNativeStartupParamsListener.java +23 -7
- package/android/src/main/java/io/appmetrica/analytics/reactnative/ReporterModule.java +17 -18
- package/android/src/main/java/io/appmetrica/analytics/reactnative/Utils.java +19 -27
- package/appmetrica-react-native-analytics.podspec +2 -23
- package/ios/AMARNAppMetrica.h +6 -2
- package/ios/{AMARNAppMetrica.m → AMARNAppMetrica.mm} +65 -39
- package/ios/{AMARNAppMetricaUtils.m → AMARNAppMetricaUtils.mm} +10 -1
- package/ios/AMARNReporter.h +6 -2
- package/ios/{AMARNReporter.m → AMARNReporter.mm} +24 -20
- package/ios/AMARNStartupParamsUtils.mm +33 -0
- package/lib/commonjs/deferredDeeplink.js.map +1 -1
- package/lib/commonjs/ecommerce.js +1 -1
- package/lib/commonjs/ecommerce.js.map +1 -1
- package/lib/commonjs/error.js +1 -1
- package/lib/commonjs/error.js.map +1 -1
- package/lib/commonjs/externalAttribution.js.map +1 -1
- package/lib/commonjs/index.js +63 -52
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/reporter.js +17 -25
- package/lib/commonjs/reporter.js.map +1 -1
- package/lib/commonjs/revenue.js.map +1 -1
- package/lib/commonjs/specs/NativeAppMetrica.js +9 -0
- package/lib/commonjs/specs/NativeAppMetrica.js.map +1 -0
- package/lib/commonjs/specs/NativeReporter.js +9 -0
- package/lib/commonjs/specs/NativeReporter.js.map +1 -0
- package/lib/commonjs/types.js +34 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/userProfile.js.map +1 -1
- package/lib/commonjs/utils.js +1 -1
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/module/deferredDeeplink.js +1 -1
- package/lib/module/deferredDeeplink.js.map +1 -1
- package/lib/module/ecommerce.js +3 -1
- package/lib/module/ecommerce.js.map +1 -1
- package/lib/module/error.js +3 -1
- package/lib/module/error.js.map +1 -1
- package/lib/module/externalAttribution.js +2 -0
- package/lib/module/externalAttribution.js.map +1 -1
- package/lib/module/index.js +24 -18
- package/lib/module/index.js.map +1 -1
- package/lib/module/reporter.js +3 -10
- package/lib/module/reporter.js.map +1 -1
- package/lib/module/revenue.js +2 -0
- package/lib/module/revenue.js.map +1 -1
- package/lib/module/specs/NativeAppMetrica.js +5 -0
- package/lib/module/specs/NativeAppMetrica.js.map +1 -0
- package/lib/module/specs/NativeReporter.js +5 -0
- package/lib/module/specs/NativeReporter.js.map +1 -0
- package/lib/module/types.js +28 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/userProfile.js +2 -0
- package/lib/module/userProfile.js.map +1 -1
- package/lib/module/utils.js +3 -1
- package/lib/module/utils.js.map +1 -1
- package/lib/typescript/src/deferredDeeplink.d.ts.map +1 -1
- package/lib/typescript/src/ecommerce.d.ts +1 -1
- package/lib/typescript/src/ecommerce.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +7 -50
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/reporter.d.ts.map +1 -1
- package/lib/typescript/src/specs/NativeAppMetrica.d.ts +41 -0
- package/lib/typescript/src/specs/NativeAppMetrica.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeReporter.d.ts +21 -0
- package/lib/typescript/src/specs/NativeReporter.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +74 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/utils.d.ts.map +1 -1
- package/package.json +28 -23
- package/src/deferredDeeplink.ts +5 -1
- package/src/ecommerce.ts +2 -2
- package/src/error.ts +1 -1
- package/src/index.ts +49 -86
- package/src/reporter.ts +20 -25
- package/src/specs/NativeAppMetrica.ts +55 -0
- package/src/specs/NativeReporter.ts +31 -0
- package/src/types.ts +105 -0
- package/src/utils.ts +5 -3
- package/ios/AMARNStartupParamsUtils.m +0 -53
- /package/ios/{AMARNExceptionSerializer.m → AMARNExceptionSerializer.mm} +0 -0
- /package/ios/{AMARNExternalAttribution.m → AMARNExternalAttribution.mm} +0 -0
- /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
|
+
"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
|
-
"
|
|
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.
|
|
59
|
-
"@types/jest": "^29.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.
|
|
70
|
-
"react-native": "0.
|
|
71
|
-
"react-native-builder-bob": "^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
|
}
|
package/src/deferredDeeplink.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
export type DeferredDeeplinkError =
|
|
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
|
-
| '
|
|
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: '
|
|
76
|
+
ecommerceEvent: 'showScreenEvent',
|
|
77
77
|
ecommerceScreen: normalizeECommerceScreen(screen),
|
|
78
78
|
};
|
|
79
79
|
}
|
package/src/error.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,32 +1,27 @@
|
|
|
1
|
-
import { Linking
|
|
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
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
|
64
|
+
static getLibraryApiLevel(): number {
|
|
126
65
|
return AppMetricaNative.getLibraryApiLevel();
|
|
127
66
|
}
|
|
128
67
|
|
|
129
|
-
static
|
|
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
|
|
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(
|
|
158
|
-
|
|
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
|
-
|
|
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():
|
|
196
|
+
static getDeviceId(): string | null {
|
|
244
197
|
return AppMetricaNative.getDeviceId();
|
|
245
198
|
}
|
|
246
199
|
|
|
247
|
-
static getUuid():
|
|
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
|
-
|
|
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
|
-
|
|
263
|
-
|
|
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(
|
|
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
|
|
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(
|
|
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(
|
|
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
|
|
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(
|
|
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);
|