@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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 YANDEX LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # @appmetrica/react-native-analytics
2
+
3
+ React Native bridge to the [AppMetrica](https://appmetrica.io) on both iOS and Android.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ npm install @appmetrica/react-native-analytics
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```js
14
+ import AppMetrica from '@appmetrica/react-native-analytics';
15
+
16
+ // Starts the statistics collection process.
17
+ AppMetrica.activateWithConfig({
18
+ apiKey: '...KEY...',
19
+ sessionTimeout: 120,
20
+ firstActivationAsUpdate: false,
21
+ });
22
+
23
+ // Sends a custom event message and additional parameters (optional).
24
+ AppMetrica.reportEvent('My event');
25
+ AppMetrica.reportEvent('My event', {foo: 'bar'});
26
+
27
+ // Send a custom error event.
28
+ AppMetrica.reportError('My error');
29
+ ```
@@ -0,0 +1,89 @@
1
+ buildscript {
2
+ repositories {
3
+ google()
4
+ mavenCentral()
5
+ }
6
+
7
+ dependencies {
8
+ classpath "com.android.tools.build:gradle:7.2.1"
9
+ }
10
+ }
11
+
12
+ def reactNativeArchitectures() {
13
+ def value = rootProject.getProperties().get("reactNativeArchitectures")
14
+ return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
15
+ }
16
+
17
+ def isNewArchitectureEnabled() {
18
+ return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
19
+ }
20
+
21
+ apply plugin: "com.android.library"
22
+
23
+ if (isNewArchitectureEnabled()) {
24
+ apply plugin: "com.facebook.react"
25
+ }
26
+
27
+ def getExtOrDefault(name) {
28
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["AppMetrica_" + name]
29
+ }
30
+
31
+ def getExtOrIntegerDefault(name) {
32
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["AppMetrica_" + name]).toInteger()
33
+ }
34
+
35
+ def supportsNamespace() {
36
+ def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
37
+ def major = parsed[0].toInteger()
38
+ def minor = parsed[1].toInteger()
39
+
40
+ // Namespace support was added in 7.3.0
41
+ return (major == 7 && minor >= 3) || major >= 8
42
+ }
43
+
44
+ android {
45
+ if (supportsNamespace()) {
46
+ namespace "io.appmetrica.analytics.reactnative"
47
+
48
+ sourceSets {
49
+ main {
50
+ manifest.srcFile "src/main/AndroidManifestNew.xml"
51
+ }
52
+ }
53
+ }
54
+
55
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
56
+
57
+ defaultConfig {
58
+ minSdkVersion getExtOrIntegerDefault("minSdkVersion")
59
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
60
+ }
61
+
62
+ buildTypes {
63
+ release {
64
+ minifyEnabled false
65
+ }
66
+ }
67
+
68
+ lintOptions {
69
+ disable "GradleCompatible"
70
+ }
71
+
72
+ compileOptions {
73
+ sourceCompatibility JavaVersion.VERSION_1_8
74
+ targetCompatibility JavaVersion.VERSION_1_8
75
+ }
76
+ }
77
+
78
+ repositories {
79
+ mavenCentral()
80
+ google()
81
+ }
82
+
83
+ dependencies {
84
+ // For < 0.71, this will be from the local maven repo
85
+ // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
86
+ //noinspection GradleDynamicVersion
87
+ implementation "com.facebook.react:react-native:+"
88
+ implementation "io.appmetrica.analytics:analytics:6.5.0"
89
+ }
@@ -0,0 +1,3 @@
1
+ AppMetrica_minSdkVersion=21
2
+ AppMetrica_targetSdkVersion=31
3
+ AppMetrica_compileSdkVersion=31
@@ -0,0 +1,4 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ package="io.appmetrica.analytics.reactnative">
3
+
4
+ </manifest>
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,139 @@
1
+ package io.appmetrica.analytics.reactnative;
2
+
3
+ import android.app.Activity;
4
+ import android.util.Log;
5
+ import androidx.annotation.NonNull;
6
+ import com.facebook.react.bridge.Callback;
7
+ import com.facebook.react.bridge.Promise;
8
+ import com.facebook.react.bridge.ReactApplicationContext;
9
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
10
+ import com.facebook.react.bridge.ReactMethod;
11
+ import com.facebook.react.bridge.ReadableArray;
12
+ import com.facebook.react.bridge.ReadableMap;
13
+ import com.facebook.react.module.annotations.ReactModule;
14
+ import io.appmetrica.analytics.AppMetrica;
15
+ import io.appmetrica.analytics.AppMetricaConfig;
16
+ import io.appmetrica.analytics.ecommerce.ECommerceEvent;
17
+
18
+ @ReactModule(name = AppMetricaModule.NAME)
19
+ public class AppMetricaModule extends ReactContextBaseJavaModule {
20
+
21
+ public static final String NAME = "AppMetrica";
22
+ public static final String TAG = "AppMetricaModule";
23
+
24
+ @NonNull
25
+ private final ReactApplicationContext reactContext;
26
+
27
+ public AppMetricaModule(@NonNull ReactApplicationContext reactContext) {
28
+ super(reactContext);
29
+ this.reactContext = reactContext;
30
+ }
31
+
32
+ @NonNull
33
+ @Override
34
+ public String getName() {
35
+ return NAME;
36
+ }
37
+
38
+ @ReactMethod
39
+ public void activate(ReadableMap configMap) {
40
+ AppMetricaConfig config = Utils.toAppMetricaConfig(configMap);
41
+ AppMetrica.activate(reactContext, config);
42
+ if (Boolean.TRUE.equals(config.sessionsAutoTrackingEnabled)) {
43
+ AppMetrica.resumeSession(getCurrentActivity());
44
+ }
45
+ }
46
+
47
+ @ReactMethod
48
+ public void getLibraryApiLevel(Promise promise) {
49
+ promise.resolve(AppMetrica.getLibraryApiLevel());
50
+ }
51
+
52
+ @ReactMethod
53
+ public void getLibraryVersion(Promise promise) {
54
+ promise.resolve(AppMetrica.getLibraryVersion());
55
+ }
56
+
57
+ @ReactMethod
58
+ public void pauseSession() {
59
+ AppMetrica.pauseSession(getCurrentActivity());
60
+ }
61
+
62
+ @ReactMethod
63
+ public void reportAppOpen(String deeplink) {
64
+ AppMetrica.reportAppOpen(deeplink);
65
+ }
66
+
67
+ @ReactMethod
68
+ public void reportError(String identifier, String message) {
69
+ try {
70
+ Integer.valueOf("00xffWr0ng");
71
+ } catch (Throwable error) {
72
+ AppMetrica.reportError(identifier, message, error);
73
+ }
74
+ }
75
+
76
+ @ReactMethod
77
+ public void reportEvent(String eventName, ReadableMap attributes) {
78
+ if (attributes == null) {
79
+ AppMetrica.reportEvent(eventName);
80
+ } else {
81
+ AppMetrica.reportEvent(eventName, attributes.toHashMap());
82
+ }
83
+ }
84
+
85
+ @ReactMethod
86
+ public void requestStartupParams(ReadableArray identifiers, Callback listener) {
87
+ AppMetrica.requestStartupParams(reactContext, new ReactNativeStartupParamsListener(listener), Utils.toStartupKeyList(identifiers));
88
+ }
89
+
90
+ @ReactMethod
91
+ public void resumeSession() {
92
+ AppMetrica.resumeSession(getCurrentActivity());
93
+ }
94
+
95
+ @ReactMethod
96
+ public void sendEventsBuffer() {
97
+ AppMetrica.sendEventsBuffer();
98
+ }
99
+
100
+ @ReactMethod
101
+ public void setLocation(ReadableMap locationMap) {
102
+ AppMetrica.setLocation(Utils.toLocation(locationMap));
103
+ }
104
+
105
+ @ReactMethod
106
+ public void setLocationTracking(boolean enabled) {
107
+ AppMetrica.setLocationTracking(enabled);
108
+ }
109
+
110
+ @ReactMethod
111
+ public void setDataSendingEnabled(boolean enabled) {
112
+ AppMetrica.setDataSendingEnabled(enabled);
113
+ }
114
+
115
+ @ReactMethod
116
+ public void setUserProfileID(String userProfileID) {
117
+ AppMetrica.setUserProfileID(userProfileID);
118
+ }
119
+
120
+ @ReactMethod
121
+ public void reportECommerce(ReadableMap ecommerceEvent) {
122
+ ECommerceEvent event = Utils.toECommerceEvent(ecommerceEvent);
123
+ if (event != null) {
124
+ AppMetrica.reportECommerce(event);
125
+ } else {
126
+ Log.w(TAG, "ECommerceEvent is null");
127
+ }
128
+ }
129
+
130
+ @ReactMethod
131
+ public void reportRevenue(ReadableMap revenue) {
132
+ AppMetrica.reportRevenue(Utils.toRevenue(revenue));
133
+ }
134
+
135
+ @ReactMethod
136
+ public void reportAdRevenue(ReadableMap revenue) {
137
+ AppMetrica.reportAdRevenue(Utils.toAdRevenue(revenue));
138
+ }
139
+ }
@@ -0,0 +1,28 @@
1
+ package io.appmetrica.analytics.reactnative;
2
+
3
+ import androidx.annotation.NonNull;
4
+
5
+ import com.facebook.react.ReactPackage;
6
+ import com.facebook.react.bridge.NativeModule;
7
+ import com.facebook.react.bridge.ReactApplicationContext;
8
+ import com.facebook.react.uimanager.ViewManager;
9
+
10
+ import java.util.ArrayList;
11
+ import java.util.Collections;
12
+ import java.util.List;
13
+
14
+ public class AppMetricaPackage implements ReactPackage {
15
+ @NonNull
16
+ @Override
17
+ public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
18
+ List<NativeModule> modules = new ArrayList<>();
19
+ modules.add(new AppMetricaModule(reactContext));
20
+ return modules;
21
+ }
22
+
23
+ @NonNull
24
+ @Override
25
+ public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
26
+ return Collections.emptyList();
27
+ }
28
+ }
@@ -0,0 +1,38 @@
1
+ package io.appmetrica.analytics.reactnative;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import androidx.annotation.Nullable;
5
+
6
+ import com.facebook.react.bridge.Callback;
7
+ import com.facebook.react.bridge.WritableMap;
8
+ import com.facebook.react.bridge.WritableNativeMap;
9
+ import io.appmetrica.analytics.StartupParamsCallback;
10
+
11
+ public class ReactNativeStartupParamsListener implements StartupParamsCallback {
12
+
13
+ @NonNull
14
+ private final Callback listener;
15
+
16
+ ReactNativeStartupParamsListener(@NonNull Callback listener) {
17
+ this.listener = listener;
18
+ }
19
+
20
+ @Override
21
+ public void onReceive(@Nullable Result result) {
22
+ listener.invoke(toParamsMap(result), null);
23
+ }
24
+
25
+ @Override
26
+ public void onRequestError(@NonNull Reason reason, @Nullable Result result) {
27
+ listener.invoke(null, reason.value);
28
+ }
29
+
30
+ private static WritableMap toParamsMap(@Nullable Result result){
31
+ if (result == null) return null;
32
+ WritableMap map = new WritableNativeMap();
33
+ map.putString("deviceId", result.deviceId);
34
+ map.putString("deviceIdHash", result.deviceIdHash);
35
+ map.putString("uuid", result.uuid);
36
+ return map;
37
+ }
38
+ }