@appmetrica/react-native-analytics 3.3.0 → 3.4.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 (46) hide show
  1. package/android/build.gradle +1 -1
  2. package/android/src/main/java/io/appmetrica/analytics/reactnative/AppMetricaModule.java +60 -6
  3. package/android/src/main/java/io/appmetrica/analytics/reactnative/AppMetricaPackage.java +1 -0
  4. package/android/src/main/java/io/appmetrica/analytics/reactnative/ExceptionSerializer.java +91 -0
  5. package/android/src/main/java/io/appmetrica/analytics/reactnative/ExternalAttributionSerializer.java +16 -9
  6. package/android/src/main/java/io/appmetrica/analytics/reactnative/ReactNativeDeferredDeeplinkListener.java +48 -0
  7. package/android/src/main/java/io/appmetrica/analytics/reactnative/ReactNativeDeferredDeeplinkParametersListener.java +53 -0
  8. package/android/src/main/java/io/appmetrica/analytics/reactnative/ReporterModule.java +130 -0
  9. package/android/src/main/java/io/appmetrica/analytics/reactnative/Utils.java +55 -1
  10. package/appmetrica-react-native-analytics.podspec +1 -1
  11. package/ios/AMARNAppMetrica.m +77 -7
  12. package/ios/AMARNAppMetricaUtils.h +1 -0
  13. package/ios/AMARNAppMetricaUtils.m +46 -0
  14. package/ios/AMARNExceptionSerializer.h +6 -0
  15. package/ios/AMARNExceptionSerializer.m +65 -0
  16. package/ios/AMARNReporter.h +6 -0
  17. package/ios/AMARNReporter.m +131 -0
  18. package/lib/commonjs/deferredDeeplink.js +2 -0
  19. package/lib/commonjs/deferredDeeplink.js.map +1 -0
  20. package/lib/commonjs/error.js +71 -0
  21. package/lib/commonjs/error.js.map +1 -0
  22. package/lib/commonjs/index.js +53 -1
  23. package/lib/commonjs/index.js.map +1 -1
  24. package/lib/commonjs/reporter.js +69 -0
  25. package/lib/commonjs/reporter.js.map +1 -0
  26. package/lib/module/deferredDeeplink.js +2 -0
  27. package/lib/module/deferredDeeplink.js.map +1 -0
  28. package/lib/module/error.js +63 -0
  29. package/lib/module/error.js.map +1 -0
  30. package/lib/module/index.js +42 -1
  31. package/lib/module/index.js.map +1 -1
  32. package/lib/module/reporter.js +62 -0
  33. package/lib/module/reporter.js.map +1 -0
  34. package/lib/typescript/src/deferredDeeplink.d.ts +10 -0
  35. package/lib/typescript/src/deferredDeeplink.d.ts.map +1 -0
  36. package/lib/typescript/src/error.d.ts +19 -0
  37. package/lib/typescript/src/error.d.ts.map +1 -0
  38. package/lib/typescript/src/index.d.ts +19 -1
  39. package/lib/typescript/src/index.d.ts.map +1 -1
  40. package/lib/typescript/src/reporter.d.ts +51 -0
  41. package/lib/typescript/src/reporter.d.ts.map +1 -0
  42. package/package.json +3 -1
  43. package/src/deferredDeeplink.ts +11 -0
  44. package/src/error.ts +87 -0
  45. package/src/index.ts +79 -2
  46. package/src/reporter.ts +126 -0
@@ -0,0 +1,126 @@
1
+ import { NativeModules, Platform } from 'react-native';
2
+ import type { UserProfile } from './userProfile';
3
+ import type { AdRevenue, Revenue } from './revenue';
4
+ import type { ECommerceEvent } from './ecommerce';
5
+ 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
+ );
23
+
24
+ export interface IReporter {
25
+ reportError(identifier: string, message?: string, _reason?: Error | Object): void;
26
+ reportErrorWithoutIdentifier(message: string | undefined, error: Error): void;
27
+ reportUnhandledException(error: Error): void;
28
+ reportEvent(eventName: string, attributes?: Record<string, any>): void;
29
+ pauseSession(): void;
30
+ resumeSession(): void;
31
+ sendEventsBuffer(): void;
32
+ clearAppEnvironment(): void;
33
+ putAppEnvironmentValue(key: string, value?: string): void;
34
+ setUserProfileID(userProfileID?: string): void;
35
+ setDataSendingEnabled(enabled: boolean): void;
36
+ reportUserProfile(userProfile: UserProfile): void;
37
+ reportAdRevenue(adRevenue: AdRevenue): void;
38
+ reportECommerce(event: ECommerceEvent): void;
39
+ reportRevenue(revenue: Revenue): void;
40
+ }
41
+
42
+ export class Reporter implements IReporter {
43
+
44
+ private apiKey: string;
45
+
46
+ constructor(apiKey: string) {
47
+ this.apiKey = apiKey;
48
+ }
49
+
50
+ reportError(identifier: string, message?: string, _reason?: Error | Object) {
51
+ ReporterNativeModule.reportError(
52
+ this.apiKey,
53
+ identifier,
54
+ message,
55
+ _reason instanceof Error ? AppMetricaError.withError(_reason) : AppMetricaError.withObject(_reason)
56
+ );
57
+ }
58
+
59
+ reportErrorWithoutIdentifier(message: string | undefined, error: Error) {
60
+ ReporterNativeModule.reportErrorWithoutIdentifier(this.apiKey, message, AppMetricaError.withError(error));
61
+ }
62
+
63
+ reportUnhandledException(error: Error) {
64
+ ReporterNativeModule.reportUnhandledException(this.apiKey, AppMetricaError.withError(error));
65
+ }
66
+
67
+ reportEvent(eventName: string, attributes?: Record<string, any>) {
68
+ ReporterNativeModule.reportEvent(this.apiKey, eventName, attributes);
69
+ }
70
+
71
+ pauseSession() {
72
+ ReporterNativeModule.pauseSession(this.apiKey);
73
+ }
74
+
75
+ resumeSession() {
76
+ ReporterNativeModule.resumeSession(this.apiKey);
77
+ }
78
+
79
+ sendEventsBuffer() {
80
+ ReporterNativeModule.sendEventsBuffer(this.apiKey);
81
+ }
82
+
83
+ clearAppEnvironment() {
84
+ ReporterNativeModule.clearAppEnvironment(this.apiKey);
85
+ }
86
+
87
+ putAppEnvironmentValue(key: string, value?: string) {
88
+ ReporterNativeModule.putAppEnvironmentValue(this.apiKey, key, value);
89
+ }
90
+
91
+ setUserProfileID(userProfileID: string) {
92
+ ReporterNativeModule.setUserProfileID(this.apiKey, userProfileID);
93
+ }
94
+
95
+ setDataSendingEnabled(enabled: boolean) {
96
+ ReporterNativeModule.setDataSendingEnabled(this.apiKey, enabled);
97
+ }
98
+
99
+ reportUserProfile(profile: UserProfile) {
100
+ ReporterNativeModule.reportUserProfile(this.apiKey, profile);
101
+ }
102
+
103
+ reportAdRevenue(adRevenue: AdRevenue) {
104
+ ReporterNativeModule.reportAdRevenue(this.apiKey, adRevenue);
105
+ }
106
+
107
+ reportECommerce(ecommerce: ECommerceEvent) {
108
+ ReporterNativeModule.reportECommerce(this.apiKey, ecommerce);
109
+ }
110
+
111
+ reportRevenue(revenue: Revenue) {
112
+ ReporterNativeModule.reportRevenue(this.apiKey, revenue)
113
+ }
114
+ }
115
+
116
+ export type ReporterConfig = {
117
+ apiKey: string;
118
+ logs?: boolean;
119
+ maxReportsInDatabaseCount?: number;
120
+ sessionTimeout?: number;
121
+ dataSendingEnabled?: boolean;
122
+ appEnvironment?: Record<string, string | undefined>;
123
+ dispatchPeriodSeconds?: number;
124
+ userProfileID?: string;
125
+ maxReportsCount?: number;
126
+ }