From c54ba7d4d2db9efe1909bac94cb295eb9058cc8f Mon Sep 17 00:00:00 2001 From: Andrey Bondarenko Date: Thu, 21 Jan 2021 16:10:35 +1000 Subject: [PATCH] add reportUserProfile --- AUTHORS | 4 ++-- .../plugin/reactnative/AppMetricaModule.java | 5 ++++ .../metrica/plugin/reactnative/Utils.java | 24 +++++++++++++++++++ index.js | 13 ++++++++++ package.json | 8 +++---- react-native-appmetrica-next.podspec | 2 +- 6 files changed, 49 insertions(+), 7 deletions(-) diff --git a/AUTHORS b/AUTHORS index 254d78a..a9e05b4 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,3 +1,3 @@ -The following authors have created the source code of "react-native-appmetrica" published and distributed by YANDEX LLC as the owner: +The following authors have created the source code of "react-native-appmetrica-next" published and distributed by YANDEX LLC as the owner: -Aliaksei Nestsiarovich \ No newline at end of file +AndreyBondarenko \ No newline at end of file diff --git a/android/src/main/java/com/yandex/metrica/plugin/reactnative/AppMetricaModule.java b/android/src/main/java/com/yandex/metrica/plugin/reactnative/AppMetricaModule.java index 6d85f85..bb00f2b 100644 --- a/android/src/main/java/com/yandex/metrica/plugin/reactnative/AppMetricaModule.java +++ b/android/src/main/java/com/yandex/metrica/plugin/reactnative/AppMetricaModule.java @@ -50,6 +50,11 @@ public class AppMetricaModule extends ReactContextBaseJavaModule { } } + @ReactMethod + public void reportUserProfile(ReadableMap configAttributes) { + YandexMetrica.reportUserProfile(Utils.toYandexProfileConfig(configAttributes)); + } + @ReactMethod public void getLibraryApiLevel(Promise promise) { promise.resolve(YandexMetrica.getLibraryApiLevel()); diff --git a/android/src/main/java/com/yandex/metrica/plugin/reactnative/Utils.java b/android/src/main/java/com/yandex/metrica/plugin/reactnative/Utils.java index 4d23bb8..f85662f 100644 --- a/android/src/main/java/com/yandex/metrica/plugin/reactnative/Utils.java +++ b/android/src/main/java/com/yandex/metrica/plugin/reactnative/Utils.java @@ -9,16 +9,40 @@ package com.yandex.metrica.plugin.reactnative; import android.location.Location; +import android.util.Log; import com.facebook.react.bridge.ReadableMap; import com.yandex.metrica.PreloadInfo; import com.yandex.metrica.YandexMetricaConfig; +import com.yandex.metrica.profile.GenderAttribute; +import com.yandex.metrica.profile.UserProfile; +import com.yandex.metrica.profile.Attribute; import java.util.Iterator; import java.util.Map; abstract class Utils { + static UserProfile toYandexProfileConfig(ReadableMap configMap) { + UserProfile.Builder userProfile = UserProfile.newBuilder(); + if (configMap.hasKey("name")) { + userProfile.apply(Attribute.name().withValue(configMap.getString("name"))); + } + if (configMap.hasKey("floor") && configMap.getString("floor") == "male") { + userProfile.apply(Attribute.gender().withValue(GenderAttribute.Gender.MALE)); + } else if(configMap.hasKey("floor") && configMap.getString("floor") == "female") { + + userProfile.apply(Attribute.gender().withValue(GenderAttribute.Gender.FEMALE)); + } + if (configMap.hasKey("age")) { + userProfile.apply(Attribute.birthDate().withAge(configMap.getInt("age"))); + } + if (configMap.hasKey("isNotification")) { + userProfile.apply(Attribute.notificationsEnabled().withValue(configMap.getBoolean("isNotification"))); + } + return userProfile.build(); + } + static YandexMetricaConfig toYandexMetricaConfig(ReadableMap configMap) { YandexMetricaConfig.Builder builder = YandexMetricaConfig.newConfigBuilder(configMap.getString("apiKey")); diff --git a/index.js b/index.js index 26d08b2..eeaf7c0 100644 --- a/index.js +++ b/index.js @@ -30,6 +30,15 @@ type AppMetricaConfig = { sessionsAutoTracking?: boolean, } +type FloorType = 'male' | 'female'; + +type UserProfileConfig = { + name: string, + floor?: FloorType, + age: number, + isNotification: boolean, +} + type PreloadInfo = { trackingId: string, additionalInfo?: Object, @@ -53,6 +62,10 @@ export default { AppMetrica.activate(config); }, + reportUserProfile(config: UserProfileConfig){ + AppMetrica.reportUserProfile(config); + }, + // Android async getLibraryApiLevel(): number { return AppMetrica.getLibraryApiLevel(); diff --git a/package.json b/package.json index 48a38c3..a836b25 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "react-native-appmetrica", + "name": "react-native-appmetrica-next", "title": "Yandex AppMetrica React Native Plugin", - "version": "2.0.0", + "version": "1.0.2", "description": "React Native plugin for AppMetrica analytics tool", "main": "index.js", "scripts": { @@ -9,7 +9,7 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/yandexmobile/react-native-appmetrica.git" + "url": "git+https://github.com/aspidvip/react-native-appmetrica-next.git" }, "keywords": [ "yandex", @@ -23,7 +23,7 @@ "react-native-android" ], "author": { - "name": "YANDEX LLC" + "name": "YANDEX LLC && Andrey Bondarenko" }, "license": "MIT", "homepage": "https://appmetrica.yandex.com/docs", diff --git a/react-native-appmetrica-next.podspec b/react-native-appmetrica-next.podspec index c6a13de..7216fb5 100644 --- a/react-native-appmetrica-next.podspec +++ b/react-native-appmetrica-next.podspec @@ -3,7 +3,7 @@ require "json" package = JSON.parse(File.read(File.join(__dir__, "package.json"))) Pod::Spec.new do |s| - s.name = "react-native-appmetrica-next-next" + s.name = "react-native-appmetrica-next" s.version = package["version"] s.summary = package["description"] s.homepage = package["homepage"]