From 79c045577c495ec9f2c68a877ebe23a3b0761701 Mon Sep 17 00:00:00 2001 From: Andrey Bondarenko Date: Thu, 21 Jan 2021 18:23:32 +1000 Subject: [PATCH] update files iOS --- android/build.gradle | 2 ++ index.js | 2 +- ios/AppMetrica.m | 10 +++++++++- ios/AppMetricaUtils.m | 32 ++++++++++++++++++++++++++++++++ package.json | 2 +- 5 files changed, 45 insertions(+), 3 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 17c4759..ad29ba3 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -84,6 +84,8 @@ dependencies { implementation 'com.yandex.android:mobmetricalib:3.18.0' implementation "com.yandex.android:mobmetricapushlib:1.10.0" implementation 'com.android.installreferrer:installreferrer:1.1.2' + implementation "com.google.firebase:firebase-messaging:21.0.0" + implementation "com.google.android.gms:play-services-base:17.5.0" } def configureReactNativePom(def pom) { diff --git a/index.js b/index.js index 7ed5dbb..4b3f863 100644 --- a/index.js +++ b/index.js @@ -68,7 +68,7 @@ export default { } else { AppMetrica.initPush(token); } - } + }, reportUserProfile(config: UserProfileConfig){ AppMetrica.reportUserProfile(config); diff --git a/ios/AppMetrica.m b/ios/AppMetrica.m index d7f9ef4..d902c3b 100644 --- a/ios/AppMetrica.m +++ b/ios/AppMetrica.m @@ -23,7 +23,15 @@ RCT_EXPORT_METHOD(activate:(NSDictionary *)configDict) [YMMYandexMetrica activateWithConfiguration:[AppMetricaUtils configurationForDictionary:configDict]]; } -RCT_EXPORT_METHOD(initPush:(NSString *)deviceToken) +RCT_EXPORT_METHOD(reportUserProfile:(NSDictionary *)configDict) +{ +// [YMPYandexMetrica reportUserProfile:[AppMetricaUtils configurationForUserProfile:configDict]]; + [YMMYandexMetrica reportUserProfile:[AppMetricaUtils configurationForUserProfile:configDict] onFailure:^(NSError *error) { + NSLog(@"Error: %@", error); + }]; +} + +RCT_EXPORT_METHOD(initPush:(NSData *)deviceToken) { [YMPYandexMetricaPush setDeviceTokenFromData:deviceToken]; } diff --git a/ios/AppMetricaUtils.m b/ios/AppMetricaUtils.m index 9b324fa..b3baa6a 100644 --- a/ios/AppMetricaUtils.m +++ b/ios/AppMetricaUtils.m @@ -52,6 +52,38 @@ return configuration; } + ++ (YMMMutableUserProfile *)configurationForUserProfile:(NSDictionary *)configDict +{ + YMMMutableUserProfile *profile = [[YMMMutableUserProfile alloc] init]; + + id timeLeftAttribute = [YMMProfileAttribute customCounter:@"time_left"]; + [profile apply:[timeLeftAttribute withDelta:-4.42]]; + + if (configDict[@"name"] != nil) { + id nameAttribute = [YMMProfileAttribute name]; + [profile apply:[nameAttribute withValue:configDict[@"name"]]]; + } + if (configDict[@"floor"] != nil && [configDict[@"floor"] isEqualToString:@"male"]) { + id genderAttribute = [YMMProfileAttribute gender]; + [profile apply:[genderAttribute withValue:YMMGenderTypeMale]]; + } + if (configDict[@"floor"] != nil && [configDict[@"floor"] isEqualToString:@"female"]) { + id genderAttribute = [YMMProfileAttribute gender]; + [profile apply:[genderAttribute withValue:YMMGenderTypeFemale]]; + } + if (configDict[@"age"] != nil) { + id birthDateAttribute = [YMMProfileAttribute birthDate]; + [profile apply:[birthDateAttribute withAge:[configDict[@"age"] unsignedIntegerValue]]]; + } + if (configDict[@"isNotification"] != nil) { + id isNotificationAttribute = [YMMProfileAttribute notificationsEnabled]; + [profile apply:[isNotificationAttribute withValue:configDict[@"isNotification"]]]; + } + + return profile; +} + + (CLLocation *)locationForDictionary:(NSDictionary *)locationDict { if (locationDict == nil) { diff --git a/package.json b/package.json index 3bcba85..6ead7d3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "react-native-appmetrica-next", "title": "Yandex AppMetrica React Native Plugin && AppMetricaPushSDK (fireBase CloudMessage)", - "version": "1.0.3", + "version": "1.0.4", "description": "React Native plugin for AppMetrica analytics tool", "main": "index.js", "scripts": {