@appmetrica/react-native-analytics 3.0.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 (39) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +29 -0
  3. package/android/build.gradle +89 -0
  4. package/android/gradle.properties +3 -0
  5. package/android/src/main/AndroidManifest.xml +4 -0
  6. package/android/src/main/AndroidManifestNew.xml +2 -0
  7. package/android/src/main/java/io/appmetrica/analytics/reactnative/AppMetricaModule.java +139 -0
  8. package/android/src/main/java/io/appmetrica/analytics/reactnative/AppMetricaPackage.java +28 -0
  9. package/android/src/main/java/io/appmetrica/analytics/reactnative/ReactNativeStartupParamsListener.java +38 -0
  10. package/android/src/main/java/io/appmetrica/analytics/reactnative/Utils.java +483 -0
  11. package/appmetrica-react-native-analytics.podspec +43 -0
  12. package/ios/AMARNAppMetrica.h +6 -0
  13. package/ios/AMARNAppMetrica.m +120 -0
  14. package/ios/AMARNAppMetricaUtils.h +24 -0
  15. package/ios/AMARNAppMetricaUtils.m +368 -0
  16. package/ios/AMARNStartupParamsUtils.h +8 -0
  17. package/ios/AMARNStartupParamsUtils.m +53 -0
  18. package/lib/commonjs/ecommerce.js +54 -0
  19. package/lib/commonjs/ecommerce.js.map +1 -0
  20. package/lib/commonjs/index.js +125 -0
  21. package/lib/commonjs/index.js.map +1 -0
  22. package/lib/commonjs/revenue.js +16 -0
  23. package/lib/commonjs/revenue.js.map +1 -0
  24. package/lib/module/ecommerce.js +47 -0
  25. package/lib/module/ecommerce.js.map +1 -0
  26. package/lib/module/index.js +91 -0
  27. package/lib/module/index.js.map +1 -0
  28. package/lib/module/revenue.js +10 -0
  29. package/lib/module/revenue.js.map +1 -0
  30. package/lib/typescript/src/ecommerce.d.ts +58 -0
  31. package/lib/typescript/src/ecommerce.d.ts.map +1 -0
  32. package/lib/typescript/src/index.d.ts +64 -0
  33. package/lib/typescript/src/index.d.ts.map +1 -0
  34. package/lib/typescript/src/revenue.d.ts +34 -0
  35. package/lib/typescript/src/revenue.d.ts.map +1 -0
  36. package/package.json +130 -0
  37. package/src/ecommerce.ts +122 -0
  38. package/src/index.ts +169 -0
  39. package/src/revenue.ts +36 -0
package/src/index.ts ADDED
@@ -0,0 +1,169 @@
1
+ import { Linking, NativeModules, Platform } from 'react-native';
2
+ import type { ECommerceEvent } from './ecommerce';
3
+ import type { AdRevenue, Revenue } from './revenue';
4
+
5
+ const LINKING_ERROR =
6
+ `The package '@appmetrica/react-native-analytics' doesn't seem to be linked. Make sure: \n\n` +
7
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
8
+ '- You rebuilt the app after installing the package\n' +
9
+ '- You are not using Expo Go\n';
10
+
11
+ const AppMetricaNative = NativeModules.AppMetrica
12
+ ? NativeModules.AppMetrica
13
+ : new Proxy(
14
+ {},
15
+ {
16
+ get() {
17
+ throw new Error(LINKING_ERROR);
18
+ },
19
+ }
20
+ );
21
+
22
+ var activated = false;
23
+
24
+ function appOpenTracking() {
25
+ const getUrlAsync = async () => {
26
+ const initialUrl = await Linking.getInitialURL();
27
+ if (initialUrl != null) {
28
+ AppMetricaNative.reportAppOpen(initialUrl);
29
+ }
30
+ };
31
+ const callback = (event: { url: string }) => {
32
+ AppMetricaNative.reportAppOpen(event.url);
33
+ };
34
+ getUrlAsync();
35
+ Linking.addEventListener('url', callback);
36
+ }
37
+
38
+ export type AppMetricaConfig = {
39
+ apiKey: string;
40
+ appVersion?: string;
41
+ crashReporting?: boolean;
42
+ firstActivationAsUpdate?: boolean;
43
+ location?: Location;
44
+ locationTracking?: boolean;
45
+ logs?: boolean;
46
+ sessionTimeout?: number;
47
+ statisticsSending?: boolean;
48
+ preloadInfo?: PreloadInfo;
49
+ maxReportsInDatabaseCount?: number;
50
+ nativeCrashReporting?: boolean; // Android only
51
+ activationAsSessionStart?: boolean; // iOS only
52
+ sessionsAutoTracking?: boolean; // iOS only
53
+ appOpenTrackingEnabled?: boolean;
54
+ };
55
+
56
+ export type PreloadInfo = {
57
+ trackingId: string;
58
+ additionalInfo?: Record<string, string>;
59
+ };
60
+
61
+ export type Location = {
62
+ latitude: number;
63
+ longitude: number;
64
+ altitude?: number;
65
+ accuracy?: number;
66
+ course?: number;
67
+ speed?: number;
68
+ timestamp?: number;
69
+ };
70
+
71
+ export type StartupParamsReason = 'UNKNOWN' | 'NETWORK' | 'INVALID_RESPONSE';
72
+
73
+ export type StartupParams = {
74
+ deviceIdHash?: string;
75
+ deviceId?: string;
76
+ uuid?: string;
77
+ };
78
+
79
+ export type StartupParamsCallback = (
80
+ params?: StartupParams,
81
+ reason?: StartupParamsReason
82
+ ) => void;
83
+
84
+ export const DEVICE_ID_HASH_KEY = 'appmetrica_device_id_hash';
85
+ export const DEVICE_ID_KEY = 'appmetrica_device_id';
86
+ export const UUID_KEY = 'appmetrica_uuid';
87
+
88
+ export * from './ecommerce';
89
+ export * from './revenue';
90
+
91
+ export default class AppMetrica {
92
+ static activate(config: AppMetricaConfig) {
93
+ if (!activated) {
94
+ AppMetricaNative.activate(config);
95
+ if (config.appOpenTrackingEnabled !== false) {
96
+ appOpenTracking();
97
+ }
98
+ activated = true;
99
+ }
100
+ }
101
+
102
+ // Android only
103
+ static async getLibraryApiLevel(): Promise<number> {
104
+ return AppMetricaNative.getLibraryApiLevel();
105
+ }
106
+
107
+ static async getLibraryVersion(): Promise<string> {
108
+ return AppMetricaNative.getLibraryVersion();
109
+ }
110
+
111
+ static pauseSession() {
112
+ AppMetricaNative.pauseSession();
113
+ }
114
+
115
+ static reportAppOpen(deeplink?: string) {
116
+ AppMetricaNative.reportAppOpen(deeplink);
117
+ }
118
+
119
+ static reportError(identifier: string, message: string, _reason: Object) {
120
+ AppMetricaNative.reportError(identifier, message);
121
+ }
122
+
123
+ static reportEvent(eventName: string, attributes?: Record<string, any>) {
124
+ AppMetricaNative.reportEvent(eventName, attributes);
125
+ }
126
+
127
+ static requestStartupParams(
128
+ listener: StartupParamsCallback,
129
+ identifiers: Array<string>
130
+ ) {
131
+ AppMetricaNative.requestStartupParams(identifiers, listener);
132
+ }
133
+
134
+ static resumeSession() {
135
+ AppMetricaNative.resumeSession();
136
+ }
137
+
138
+ static sendEventsBuffer() {
139
+ AppMetricaNative.sendEventsBuffer();
140
+ }
141
+
142
+ static setLocation(location?: Location) {
143
+ AppMetricaNative.setLocation(location);
144
+ }
145
+
146
+ static setLocationTracking(enabled: boolean) {
147
+ AppMetricaNative.setLocationTracking(enabled);
148
+ }
149
+
150
+ static setDataSendingEnabled(enabled: boolean) {
151
+ AppMetricaNative.setDataSendingEnabled(enabled);
152
+ }
153
+
154
+ static setUserProfileID(userProfileID?: string) {
155
+ AppMetricaNative.setUserProfileID(userProfileID);
156
+ }
157
+
158
+ static reportECommerce(event: ECommerceEvent) {
159
+ AppMetricaNative.reportECommerce(event);
160
+ }
161
+
162
+ static reportRevenue(revenue: Revenue) {
163
+ AppMetricaNative.reportRevenue(revenue);
164
+ }
165
+
166
+ static reportAdRevenue(adRevenue: AdRevenue) {
167
+ AppMetricaNative.reportAdRevenue(adRevenue);
168
+ }
169
+ }
package/src/revenue.ts ADDED
@@ -0,0 +1,36 @@
1
+ export type Revenue = {
2
+ price: number;
3
+ currency: string;
4
+ productID?: string;
5
+ quantity?: number;
6
+ payload?: string;
7
+ receipt?: Receipt;
8
+ };
9
+
10
+ export type Receipt = {
11
+ transactionID?: string;
12
+ receiptData?: string;
13
+ signature?: string;
14
+ };
15
+
16
+ export type AdRevenue = {
17
+ price: number | string;
18
+ currency: string;
19
+ payload?: Map<string, string>;
20
+ adNetwork?: string;
21
+ adPlacementID?: string;
22
+ adPlacementName?: string;
23
+ adType?: AdType;
24
+ adUnitID?: string;
25
+ adUnitName?: string;
26
+ precision?: string;
27
+ };
28
+
29
+ export enum AdType {
30
+ NATIVE = 'native',
31
+ BANNER = 'banner',
32
+ MREC = 'mrec',
33
+ INTERSTITIAL = 'interstitial',
34
+ REWARDED = 'rewarded',
35
+ OTHER = 'other',
36
+ }