add reportUserProfile

This commit is contained in:
Andrey Bondarenko 2021-01-21 16:10:35 +10:00
parent f606229340
commit c54ba7d4d2
6 changed files with 49 additions and 7 deletions

View File

@ -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 <alex98@yandex-team.ru>
AndreyBondarenko <mail@andreybondarenko.info>

View File

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

View File

@ -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"));

View File

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

View File

@ -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",

View File

@ -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"]