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

159
android/build.gradle Normal file
View File

@@ -0,0 +1,159 @@
/*
* 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/
*/
// android/build.gradle
// based on:
//
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle
// original location:
// - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/build.gradle
//
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/app/build.gradle
// original location:
// - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/app/build.gradle
def DEFAULT_COMPILE_SDK_VERSION = 28
def DEFAULT_BUILD_TOOLS_VERSION = '28.0.3'
def DEFAULT_MIN_SDK_VERSION = 16
def DEFAULT_TARGET_SDK_VERSION = 28
def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
apply plugin: 'com.android.library'
apply plugin: 'maven'
buildscript {
// The Android Gradle plugin is only required when opening the android folder stand-alone.
// This avoids unnecessary downloads and potential conflicts when the library is included as a
// module dependency in an application project.
// ref: https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:build_script_external_dependencies
if (project == rootProject) {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
}
}
}
apply plugin: 'com.android.library'
apply plugin: 'maven'
android {
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
}
}
repositories {
// ref: https://www.baeldung.com/maven-local-repository
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {
// Android JSC is installed from npm
url "$rootDir/../node_modules/jsc-android/dist"
}
google()
jcenter()
}
dependencies {
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+' // From node_modules
implementation 'com.yandex.android:mobmetricalib:3.13.3'
implementation 'com.android.installreferrer:installreferrer:1.1.2'
}
def configureReactNativePom(def pom) {
def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)
pom.project {
name packageJson.title
artifactId packageJson.name
version = packageJson.version
group = "com.yandex.metrica.plugin.reactnative"
description packageJson.description
url packageJson.repository.baseUrl
licenses {
license {
name packageJson.license
url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
distribution 'repo'
}
}
developers {
developer {
id packageJson.author.username
name packageJson.author.name
}
}
}
}
afterEvaluate { project ->
// some Gradle build hooks ref:
// https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html
task androidJavadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += files(android.bootClasspath)
classpath += files(project.getConfigurations().getByName('compile').asList())
include '**/*.java'
}
task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
classifier = 'javadoc'
from androidJavadoc.destinationDir
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
include '**/*.java'
}
android.libraryVariants.all { variant ->
def name = variant.name.capitalize()
def javaCompileTask = variant.javaCompileProvider.get()
task "jar${name}"(type: Jar, dependsOn: javaCompileTask) {
from javaCompileTask.destinationDir
}
}
artifacts {
archives androidSourcesJar
archives androidJavadocJar
}
task installArchives(type: Upload) {
configuration = configurations.archives
repositories.mavenDeployer {
// Deploy to react-native-event-bridge/maven, ready to publish to npm
repository url: "file://${projectDir}/../android/maven"
configureReactNativePom pom
}
}
}

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();
}
}