release 2.0.0

This commit is contained in:
Aliaksei Nestsiarovich
2020-06-08 22:14:06 +03:00
commit a5bdc83170
81 changed files with 10985 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
<!--
~ Version for React Native
~ © 2020 YANDEX
~ You may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~ https://yandex.com/legal/appmetrica_sdk_agreement/
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yandex.metrica.plugin.reactnative">
</manifest>

View File

@@ -0,0 +1,130 @@
/*
* Version for React Native
* © 2020 YANDEX
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://yandex.com/legal/appmetrica_sdk_agreement/
*/
package com.yandex.metrica.plugin.reactnative;
import android.app.Activity;
import android.util.Log;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import com.yandex.metrica.YandexMetrica;
public class AppMetricaModule extends ReactContextBaseJavaModule {
private static final String TAG = "AppMetricaModule";
private final ReactApplicationContext reactContext;
public AppMetricaModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
}
@Override
public String getName() {
return "AppMetrica";
}
@ReactMethod
public void activate(ReadableMap configMap) {
YandexMetrica.activate(reactContext, Utils.toYandexMetricaConfig(configMap));
enableActivityAutoTracking();
}
private void enableActivityAutoTracking() {
Activity activity = getCurrentActivity();
if (activity != null) { // TODO: check
YandexMetrica.enableActivityAutoTracking(activity.getApplication());
} else {
Log.w(TAG, "Activity is not attached");
}
}
@ReactMethod
public void getLibraryApiLevel(Promise promise) {
promise.resolve(YandexMetrica.getLibraryApiLevel());
}
@ReactMethod
public void getLibraryVersion(Promise promise) {
promise.resolve(YandexMetrica.getLibraryVersion());
}
@ReactMethod
public void pauseSession() {
YandexMetrica.pauseSession(getCurrentActivity());
}
@ReactMethod
public void reportAppOpen(String deeplink) {
YandexMetrica.reportAppOpen(deeplink);
}
@ReactMethod
public void reportError(String message) {
try {
Integer.valueOf("00xffWr0ng");
} catch (Throwable error) {
YandexMetrica.reportError(message, error);
}
}
@ReactMethod
public void reportEvent(String eventName, ReadableMap attributes) {
if (attributes == null) {
YandexMetrica.reportEvent(eventName);
} else {
YandexMetrica.reportEvent(eventName, attributes.toHashMap());
}
}
@ReactMethod
public void reportReferralUrl(String referralUrl) {
YandexMetrica.reportReferralUrl(referralUrl);
}
@ReactMethod
public void requestAppMetricaDeviceID(Callback listener) {
YandexMetrica.requestAppMetricaDeviceID(new ReactNativeAppMetricaDeviceIDListener(listener));
}
@ReactMethod
public void resumeSession() {
YandexMetrica.resumeSession(getCurrentActivity());
}
@ReactMethod
public void sendEventsBuffer() {
YandexMetrica.sendEventsBuffer();
}
@ReactMethod
public void setLocation(ReadableMap locationMap) {
YandexMetrica.setLocation(Utils.toLocation(locationMap));
}
@ReactMethod
public void setLocationTracking(boolean enabled) {
YandexMetrica.setLocationTracking(enabled);
}
@ReactMethod
public void setStatisticsSending(boolean enabled) {
YandexMetrica.setStatisticsSending(reactContext, enabled);
}
@ReactMethod
public void setUserProfileID(String userProfileID) {
YandexMetrica.setUserProfileID(userProfileID);
}
}

View File

@@ -0,0 +1,31 @@
/*
* Version for React Native
* © 2020 YANDEX
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://yandex.com/legal/appmetrica_sdk_agreement/
*/
package com.yandex.metrica.plugin.reactnative;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.bridge.JavaScriptModule;
public class AppMetricaPackage implements ReactPackage {
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Arrays.<NativeModule>asList(new AppMetricaModule(reactContext));
}
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
}

View File

@@ -0,0 +1,31 @@
/*
* Version for React Native
* © 2020 YANDEX
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://yandex.com/legal/appmetrica_sdk_agreement/
*/
package com.yandex.metrica.plugin.reactnative;
import com.facebook.react.bridge.Callback;
import com.yandex.metrica.AppMetricaDeviceIDListener;
public class ReactNativeAppMetricaDeviceIDListener implements AppMetricaDeviceIDListener {
private final Callback listener;
ReactNativeAppMetricaDeviceIDListener(Callback listener) {
this.listener = listener;
}
@Override
public void onLoaded(/* Nullable */ String deviceId) {
listener.invoke(deviceId, null);
}
@Override
public void onError(/* NonNull */ Reason reason) {
listener.invoke(null, reason.toString());
}
}

View File

@@ -0,0 +1,116 @@
/*
* Version for React Native
* © 2020 YANDEX
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://yandex.com/legal/appmetrica_sdk_agreement/
*/
package com.yandex.metrica.plugin.reactnative;
import android.location.Location;
import com.facebook.react.bridge.ReadableMap;
import com.yandex.metrica.PreloadInfo;
import com.yandex.metrica.YandexMetricaConfig;
import java.util.Iterator;
import java.util.Map;
abstract class Utils {
static YandexMetricaConfig toYandexMetricaConfig(ReadableMap configMap) {
YandexMetricaConfig.Builder builder = YandexMetricaConfig.newConfigBuilder(configMap.getString("apiKey"));
if (configMap.hasKey("appVersion")) {
builder.withAppVersion(configMap.getString("appVersion"));
}
if (configMap.hasKey("crashReporting")) {
builder.withCrashReporting(configMap.getBoolean("crashReporting"));
}
if (configMap.hasKey("firstActivationAsUpdate")) {
builder.handleFirstActivationAsUpdate(configMap.getBoolean("firstActivationAsUpdate"));
}
if (configMap.hasKey("installedAppCollecting")) {
builder.withInstalledAppCollecting(configMap.getBoolean("installedAppCollecting"));
}
if (configMap.hasKey("location")) {
builder.withLocation(toLocation(configMap.getMap("location")));
}
if (configMap.hasKey("locationTracking")) {
builder.withLocationTracking(configMap.getBoolean("locationTracking"));
}
if (configMap.hasKey("logs") && configMap.getBoolean("logs")) {
builder.withLogs();
}
if (configMap.hasKey("maxReportsInDatabaseCount")) {
builder.withMaxReportsInDatabaseCount(configMap.getInt("maxReportsInDatabaseCount"));
}
if (configMap.hasKey("nativeCrashReporting")) {
builder.withNativeCrashReporting(configMap.getBoolean("nativeCrashReporting"));
}
if (configMap.hasKey("preloadInfo")) {
builder.withPreloadInfo(toPreloadInfo(configMap.getMap("preloadInfo")));
}
if (configMap.hasKey("sessionTimeout")) {
builder.withSessionTimeout(configMap.getInt("sessionTimeout"));
}
if (configMap.hasKey("statisticsSending")) {
builder.withStatisticsSending(configMap.getBoolean("statisticsSending"));
}
return builder.build();
}
static Location toLocation(ReadableMap locationMap) {
if (locationMap == null) {
return null;
}
Location location = new Location("Custom");
if (locationMap.hasKey("latitude")) {
location.setLatitude(locationMap.getDouble("latitude"));
}
if (locationMap.hasKey("longitude")) {
location.setLongitude(locationMap.getDouble("longitude"));
}
if (locationMap.hasKey("altitude")) {
location.setAltitude(locationMap.getDouble("altitude"));
}
if (locationMap.hasKey("accuracy")) {
location.setAccuracy((float) locationMap.getDouble("accuracy"));
}
if (locationMap.hasKey("course")) {
location.setBearing((float) locationMap.getDouble("course"));
}
if (locationMap.hasKey("speed")) {
location.setSpeed((float) locationMap.getDouble("speed"));
}
if (locationMap.hasKey("timestamp")) {
location.setTime((long) locationMap.getDouble("timestamp"));
}
return location;
}
private static PreloadInfo toPreloadInfo(ReadableMap preloadInfoMap) {
if (preloadInfoMap == null) {
return null;
}
PreloadInfo.Builder builder = PreloadInfo.newBuilder(preloadInfoMap.getString("trackingId"));
if (preloadInfoMap.hasKey("additionalInfo")) {
ReadableMap additionalInfo = preloadInfoMap.getMap("additionalInfo");
if (additionalInfo != null) {
for (Map.Entry<String, Object> entry : additionalInfo.toHashMap().entrySet()) {
Object value = entry.getValue();
builder.setAdditionalParams(entry.getKey(), value == null ? null : value.toString());
}
}
}
return builder.build();
}
}