@appmetrica/react-native-analytics 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/android/build.gradle +1 -1
  2. package/android/src/main/java/io/appmetrica/analytics/reactnative/AppMetricaModule.java +10 -0
  3. package/android/src/main/java/io/appmetrica/analytics/reactnative/UserProfileSerializer.java +257 -0
  4. package/android/src/main/java/io/appmetrica/analytics/reactnative/Utils.java +9 -0
  5. package/appmetrica-react-native-analytics.podspec +1 -1
  6. package/ios/AMARNAppMetrica.m +6 -0
  7. package/ios/AMARNAppMetricaUtils.h +2 -0
  8. package/ios/AMARNAppMetricaUtils.m +8 -0
  9. package/ios/AMARNUserProfileSerializer.h +6 -0
  10. package/ios/AMARNUserProfileSerializer.m +182 -0
  11. package/lib/commonjs/ecommerce.js +10 -9
  12. package/lib/commonjs/ecommerce.js.map +1 -1
  13. package/lib/commonjs/index.js +17 -1
  14. package/lib/commonjs/index.js.map +1 -1
  15. package/lib/commonjs/userProfile.js +283 -0
  16. package/lib/commonjs/userProfile.js.map +1 -0
  17. package/lib/commonjs/utils.js +72 -0
  18. package/lib/commonjs/utils.js.map +1 -0
  19. package/lib/module/ecommerce.js +10 -9
  20. package/lib/module/ecommerce.js.map +1 -1
  21. package/lib/module/index.js +6 -1
  22. package/lib/module/index.js.map +1 -1
  23. package/lib/module/userProfile.js +267 -0
  24. package/lib/module/userProfile.js.map +1 -0
  25. package/lib/module/utils.js +61 -0
  26. package/lib/module/utils.js.map +1 -0
  27. package/lib/typescript/src/ecommerce.d.ts +3 -3
  28. package/lib/typescript/src/ecommerce.d.ts.map +1 -1
  29. package/lib/typescript/src/index.d.ts +5 -1
  30. package/lib/typescript/src/index.d.ts.map +1 -1
  31. package/lib/typescript/src/revenue.d.ts +1 -1
  32. package/lib/typescript/src/revenue.d.ts.map +1 -1
  33. package/lib/typescript/src/userProfile.d.ts +84 -0
  34. package/lib/typescript/src/userProfile.d.ts.map +1 -0
  35. package/lib/typescript/src/utils.d.ts +9 -0
  36. package/lib/typescript/src/utils.d.ts.map +1 -0
  37. package/package.json +1 -1
  38. package/src/ecommerce.ts +20 -12
  39. package/src/index.ts +10 -2
  40. package/src/revenue.ts +1 -1
  41. package/src/userProfile.ts +362 -0
  42. package/src/utils.ts +71 -0
@@ -85,5 +85,5 @@ dependencies {
85
85
  // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
86
86
  //noinspection GradleDynamicVersion
87
87
  implementation "com.facebook.react:react-native:+"
88
- implementation "io.appmetrica.analytics:analytics:6.5.0"
88
+ implementation "io.appmetrica.analytics:analytics:7.0.0"
89
89
  }
@@ -11,6 +11,7 @@ import com.facebook.react.bridge.ReactMethod;
11
11
  import com.facebook.react.bridge.ReadableArray;
12
12
  import com.facebook.react.bridge.ReadableMap;
13
13
  import com.facebook.react.module.annotations.ReactModule;
14
+
14
15
  import io.appmetrica.analytics.AppMetrica;
15
16
  import io.appmetrica.analytics.AppMetricaConfig;
16
17
  import io.appmetrica.analytics.ecommerce.ECommerceEvent;
@@ -136,4 +137,13 @@ public class AppMetricaModule extends ReactContextBaseJavaModule {
136
137
  public void reportAdRevenue(ReadableMap revenue) {
137
138
  AppMetrica.reportAdRevenue(Utils.toAdRevenue(revenue));
138
139
  }
140
+
141
+ @ReactMethod
142
+ public void reportUserProfile(ReadableMap userProfile) {
143
+ try {
144
+ AppMetrica.reportUserProfile(Utils.toUserProfile(userProfile));
145
+ } catch (Throwable e) {
146
+ Log.w(TAG, "Cannot parse user profile", e);
147
+ }
148
+ }
139
149
  }
@@ -0,0 +1,257 @@
1
+ package io.appmetrica.analytics.reactnative;
2
+
3
+ import androidx.annotation.NonNull;
4
+
5
+ import com.facebook.react.bridge.ReadableArray;
6
+ import com.facebook.react.bridge.ReadableMap;
7
+
8
+ import io.appmetrica.analytics.profile.Attribute;
9
+ import io.appmetrica.analytics.profile.BirthDateAttribute;
10
+ import io.appmetrica.analytics.profile.BooleanAttribute;
11
+ import io.appmetrica.analytics.profile.CounterAttribute;
12
+ import io.appmetrica.analytics.profile.GenderAttribute;
13
+ import io.appmetrica.analytics.profile.NameAttribute;
14
+ import io.appmetrica.analytics.profile.NotificationsEnabledAttribute;
15
+ import io.appmetrica.analytics.profile.NumberAttribute;
16
+ import io.appmetrica.analytics.profile.StringAttribute;
17
+ import io.appmetrica.analytics.profile.UserProfile;
18
+ import io.appmetrica.analytics.profile.UserProfileUpdate;
19
+
20
+ final class UserProfileSerializer {
21
+ private UserProfileSerializer() {}
22
+
23
+ @NonNull
24
+ public static UserProfile fromReadableMap(@NonNull ReadableMap profileMap){
25
+
26
+ ReadableArray attributes = profileMap.getArray("attributes");
27
+ if (attributes == null) {
28
+ throw new IllegalArgumentException();
29
+ }
30
+ UserProfile.Builder builder = UserProfile.newBuilder();
31
+
32
+ for (int idx = 0; idx < attributes.size(); idx++) {
33
+
34
+ ReadableMap attribute = attributes.getMap(idx);
35
+ if (attribute != null) {
36
+ builder.apply(parseUserProfileUpdate(attribute));
37
+ }
38
+ }
39
+
40
+ return builder.build();
41
+ }
42
+
43
+ @NonNull
44
+ private static UserProfileUpdate<?> parseUserProfileUpdate(@NonNull ReadableMap map){
45
+ String type = map.getString("type");
46
+
47
+ if (type == null) {
48
+ throw new IllegalArgumentException("Type should not be null");
49
+ }
50
+
51
+ if (type.startsWith("BirthDate")) {
52
+ return parseBirthDate(type, map);
53
+ }
54
+ if (type.startsWith("Boolean")) {
55
+ return parseBoolean(type, map);
56
+ }
57
+ if (type.startsWith("Counter")) {
58
+ return parseCounter(type, map);
59
+ }
60
+ if (type.startsWith("Gender")) {
61
+ return parseGender(type, map);
62
+ }
63
+ if (type.startsWith("Name")) {
64
+ return parseName(type, map);
65
+ }
66
+ if (type.startsWith("NotificationsEnabled")) {
67
+ return parseNotificationsEnabled(type, map);
68
+ }
69
+ if (type.startsWith("Number")) {
70
+ return parseNumber(type, map);
71
+ }
72
+ if (type.startsWith("String")) {
73
+ return parseString(type, map);
74
+ }
75
+ throw new IllegalArgumentException("Unknown UserProfile type " + type);
76
+ }
77
+
78
+ @NonNull
79
+ private static UserProfileUpdate<?> parseBirthDate(@NonNull String type, @NonNull ReadableMap map) {
80
+ BirthDateAttribute att = Attribute.birthDate();
81
+ switch (type) {
82
+ case "BirthDateWithAge": {
83
+ int age = map.getInt("age");
84
+ boolean ifUndefined = map.getBoolean("ifUndefined");
85
+ return ifUndefined ? att.withAgeIfUndefined(age) : att.withAge(age);
86
+ }
87
+ case "BirthDateWithYear": {
88
+ int year = map.getInt("year");
89
+ boolean ifUndefined = map.getBoolean("ifUndefined");
90
+ return ifUndefined ? att.withBirthDateIfUndefined(year) : att.withBirthDate(year);
91
+ }
92
+ case "BirthDateWithMonth": {
93
+ int year = map.getInt("year");
94
+ int month = map.getInt("month");
95
+ boolean ifUndefined = map.getBoolean("ifUndefined");
96
+ return ifUndefined ? att.withBirthDateIfUndefined(year, month) : att.withBirthDate(year, month);
97
+ }
98
+ case "BirthDateWithDay": {
99
+ int year = map.getInt("year");
100
+ int month = map.getInt("month");
101
+ int days = map.getInt("day");
102
+ boolean ifUndefined = map.getBoolean("ifUndefined");
103
+ return ifUndefined ? att.withBirthDateIfUndefined(year, month, days) : att.withBirthDate(year, month, days);
104
+ }
105
+ case "BirthDateValueReset": {
106
+ return att.withValueReset();
107
+ }
108
+ }
109
+ throw new IllegalArgumentException("Unknown UserProfile type " + type);
110
+ }
111
+
112
+ @NonNull
113
+ private static UserProfileUpdate<?> parseBoolean(@NonNull String type, @NonNull ReadableMap map) {
114
+ String key = map.getString("key");
115
+ if (key == null) {
116
+ throw new IllegalArgumentException("Key should not be null");
117
+ }
118
+ BooleanAttribute att = Attribute.customBoolean(key);
119
+ switch (type) {
120
+ case "BooleanValue": {
121
+ boolean value = map.getBoolean("value");
122
+ boolean ifUndefined = map.getBoolean("ifUndefined");
123
+ return ifUndefined ? att.withValueIfUndefined(value) : att.withValue(value);
124
+ }
125
+ case "BooleanValueReset": {
126
+ return att.withValueReset();
127
+ }
128
+ }
129
+ throw new IllegalArgumentException("Unknown UserProfile type " + type);
130
+ }
131
+
132
+ @NonNull
133
+ private static UserProfileUpdate<?> parseCounter(@NonNull String type, @NonNull ReadableMap map) {
134
+ String key = map.getString("key");
135
+ if (key == null) {
136
+ throw new IllegalArgumentException("Key should not be null");
137
+ }
138
+ CounterAttribute att = Attribute.customCounter(key);
139
+ if (type.equals("Counter")) {
140
+ double delta = map.getDouble("delta");
141
+ return att.withDelta(delta);
142
+ }
143
+ throw new IllegalArgumentException("Unknown UserProfile type " + type);
144
+ }
145
+
146
+ @NonNull
147
+ private static UserProfileUpdate<?> parseGender(@NonNull String type, @NonNull ReadableMap map) {
148
+ GenderAttribute att = Attribute.gender();
149
+ // BirthDate
150
+ switch (type) {
151
+ case "GenderValue": {
152
+ String value = map.getString("value");
153
+ if (value == null) {
154
+ throw new IllegalArgumentException("Value should not be null");
155
+ }
156
+
157
+ GenderAttribute.Gender gender = getGender(value);
158
+ boolean ifUndefined = map.getBoolean("ifUndefined");
159
+ return ifUndefined ? att.withValueIfUndefined(gender) : att.withValue(gender);
160
+ }
161
+ case "GenderValueReset": {
162
+ return att.withValueReset();
163
+ }
164
+ }
165
+ throw new IllegalArgumentException("Unknown UserProfile type " + type);
166
+ }
167
+
168
+ @NonNull
169
+ private static GenderAttribute.Gender getGender(@NonNull String value) {
170
+ switch (value) {
171
+ case "female":
172
+ return GenderAttribute.Gender.FEMALE;
173
+ case "male":
174
+ return GenderAttribute.Gender.MALE;
175
+ default:
176
+ return GenderAttribute.Gender.OTHER;
177
+ }
178
+ }
179
+
180
+ @NonNull
181
+ private static UserProfileUpdate<?> parseName(@NonNull String type, @NonNull ReadableMap map) {
182
+ NameAttribute att = Attribute.name();
183
+ switch (type) {
184
+ case "NameValue": {
185
+ String value = map.getString("value");
186
+ if (value == null) {
187
+ throw new IllegalArgumentException("Value should not be null");
188
+ }
189
+ boolean ifUndefined = map.getBoolean("ifUndefined");
190
+ return ifUndefined ? att.withValueIfUndefined(value) : att.withValue(value);
191
+ }
192
+ case "NameValueReset": {
193
+ return att.withValueReset();
194
+ }
195
+ }
196
+ throw new IllegalArgumentException("Unknown UserProfile type " + type);
197
+ }
198
+
199
+ @NonNull
200
+ private static UserProfileUpdate<?> parseNotificationsEnabled(@NonNull String type, @NonNull ReadableMap map) {
201
+ NotificationsEnabledAttribute att = Attribute.notificationsEnabled();
202
+ switch (type) {
203
+ case "NotificationsEnabledValue": {
204
+ boolean value = map.getBoolean("value");
205
+ boolean ifUndefined = map.getBoolean("ifUndefined");
206
+ return ifUndefined ? att.withValueIfUndefined(value) : att.withValue(value);
207
+ }
208
+ case "NotificationsEnabledValueReset": {
209
+ return att.withValueReset();
210
+ }
211
+ }
212
+ throw new IllegalArgumentException("Unknown UserProfile type " + type);
213
+ }
214
+
215
+ @NonNull
216
+ private static UserProfileUpdate<?> parseNumber(@NonNull String type, @NonNull ReadableMap map) {
217
+ String key = map.getString("key");
218
+ if (key == null) {
219
+ throw new IllegalArgumentException("Key should not be null");
220
+ }
221
+ NumberAttribute att = Attribute.customNumber(key);
222
+ switch (type) {
223
+ case "NumberValue": {
224
+ double value = map.getDouble("value");
225
+ boolean ifUndefined = map.getBoolean("ifUndefined");
226
+ return ifUndefined ? att.withValueIfUndefined(value) : att.withValue(value);
227
+ }
228
+ case "NumberValueReset": {
229
+ return att.withValueReset();
230
+ }
231
+ }
232
+ throw new IllegalArgumentException("Unknown UserProfile type " + type);
233
+ }
234
+
235
+ @NonNull
236
+ private static UserProfileUpdate<?> parseString(@NonNull String type, @NonNull ReadableMap map) {
237
+ String key = map.getString("key");
238
+ if (key == null) {
239
+ throw new IllegalArgumentException("Key should not be null");
240
+ }
241
+ StringAttribute att = Attribute.customString(key);
242
+ switch (type) {
243
+ case "StringValue": {
244
+ String value = map.getString("value");
245
+ if (value == null) {
246
+ throw new IllegalArgumentException("Value should not be null");
247
+ }
248
+ boolean ifUndefined = map.getBoolean("ifUndefined");
249
+ return ifUndefined ? att.withValueIfUndefined(value) : att.withValue(value);
250
+ }
251
+ case "StringValueReset": {
252
+ return att.withValueReset();
253
+ }
254
+ }
255
+ throw new IllegalArgumentException("Unknown UserProfile type " + type);
256
+ }
257
+ }
@@ -13,6 +13,7 @@ import io.appmetrica.analytics.AppMetricaConfig;
13
13
  import io.appmetrica.analytics.PreloadInfo;
14
14
  import io.appmetrica.analytics.Revenue;
15
15
  import io.appmetrica.analytics.StartupParamsCallback;
16
+ import io.appmetrica.analytics.profile.UserProfile;
16
17
  import io.appmetrica.analytics.ecommerce.ECommerceAmount;
17
18
  import io.appmetrica.analytics.ecommerce.ECommerceCartItem;
18
19
  import io.appmetrica.analytics.ecommerce.ECommerceEvent;
@@ -71,6 +72,9 @@ abstract class Utils {
71
72
  if (configMap.hasKey("sessionsAutoTracking")) {
72
73
  builder.withSessionsAutoTrackingEnabled(configMap.getBoolean("sessionsAutoTracking"));
73
74
  }
75
+ if (configMap.hasKey("userProfileID")) {
76
+ builder.withUserProfileID(configMap.getString("userProfileID"));
77
+ }
74
78
 
75
79
  return builder.build();
76
80
  }
@@ -454,6 +458,11 @@ abstract class Utils {
454
458
  }
455
459
  }
456
460
 
461
+ @NonNull
462
+ static UserProfile toUserProfile(ReadableMap userProfileMap) {
463
+ return UserProfileSerializer.fromReadableMap(userProfileMap);
464
+ }
465
+
457
466
  @Nullable
458
467
  private static Map<String, String> toMapOfStrings(@Nullable ReadableMap oldMap) {
459
468
  if (oldMap == null) {
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
16
16
 
17
17
  s.source_files = "ios/**/*.{h,m,mm}"
18
18
 
19
- s.dependency "AppMetricaAnalytics", "5.4.0"
19
+ s.dependency "AppMetricaAnalytics", "5.6.0"
20
20
 
21
21
  # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
22
22
  # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
@@ -2,6 +2,7 @@
2
2
  #import "AMARNAppMetrica.h"
3
3
  #import "AMARNAppMetricaUtils.h"
4
4
  #import "AMARNStartupParamsUtils.h"
5
+ #import "AMARNUserProfileSerializer.h"
5
6
  #import <AppMetricaCrashes/AppMetricaCrashes.h>
6
7
 
7
8
  @implementation AMARNAppMetrica
@@ -109,6 +110,11 @@ RCT_EXPORT_METHOD(reportAdRevenue:(NSDictionary *)revenueDict)
109
110
  [AMAAppMetrica reportAdRevenue:[AMARNAppMetricaUtils adRevenueForDict:revenueDict] onFailure:nil];
110
111
  }
111
112
 
113
+ RCT_EXPORT_METHOD(reportUserProfile:(NSDictionary *)userProfileDict)
114
+ {
115
+ [AMAAppMetrica reportUserProfile:[AMARNAppMetricaUtils userProfileForDict:userProfileDict] onFailure:nil];
116
+ }
117
+
112
118
  - (NSObject *)wrap:(NSObject *)value
113
119
  {
114
120
  if (value == nil) {
@@ -2,6 +2,7 @@
2
2
  #import <CoreLocation/CoreLocation.h>
3
3
  #import <AppMetricaCore/AppMetricaCore.h>
4
4
  #import <AppMetricaCrashes/AppMetricaCrashes.h>
5
+ #import "AMARNUserProfileSerializer.h"
5
6
 
6
7
  @interface AMARNAppMetricaUtils : NSObject
7
8
 
@@ -20,5 +21,6 @@
20
21
  + (AMAAdRevenueInfo *)adRevenueForDict:(NSDictionary *)revenueDict;
21
22
  + (AMAAdType)toAdType:(NSString *)type;
22
23
  + (NSDictionary *)convertRevenueInfoPayload:(NSString *)payload;
24
+ + (AMAUserProfile *)userProfileForDict:(NSDictionary *)userProfileDict;
23
25
 
24
26
  @end
@@ -40,6 +40,9 @@
40
40
  if (configDict[@"maxReportsInDatabaseCount"] != nil) {
41
41
  configuration.maxReportsInDatabaseCount = [configDict[@"maxReportsInDatabaseCount"] unsignedIntegerValue];
42
42
  }
43
+ if (configDict[@"userProfileID"] != nil) {
44
+ configuration.userProfileID = configDict[@"userProfileID"];
45
+ }
43
46
 
44
47
  return configuration;
45
48
  }
@@ -365,4 +368,9 @@
365
368
  }
366
369
  }
367
370
 
371
+ + (AMAUserProfile *)userProfileForDict:(NSDictionary *)userProfileDict
372
+ {
373
+ return amarn_deserializeUserProfile(userProfileDict);
374
+ }
375
+
368
376
  @end
@@ -0,0 +1,6 @@
1
+
2
+ #import <AppMetricaCore/AppMetricaCore.h>
3
+
4
+ @class AMAUserProfile;
5
+
6
+ AMAUserProfile *amarn_deserializeUserProfile(NSDictionary *dictionary);
@@ -0,0 +1,182 @@
1
+
2
+ #import "AMARNUserProfileSerializer.h"
3
+
4
+ AMAUserProfileUpdate *amarn_birthDateAttributeFromDictionary(NSDictionary *dictionary)
5
+ {
6
+ NSString *type = dictionary[@"type"];
7
+ if ([type isEqualToString:@"BirthDateWithAge"]) {
8
+ return [[AMAProfileAttribute birthDate] withAge:[dictionary[@"age"] unsignedIntegerValue]];
9
+ }
10
+ if ([type isEqualToString:@"BirthDateWithYear"]) {
11
+ return [[AMAProfileAttribute birthDate] withYear:[dictionary[@"year"] unsignedIntegerValue]];
12
+ }
13
+ if ([type isEqualToString:@"BirthDateWithMonth"]) {
14
+ return [[AMAProfileAttribute birthDate] withYear:[dictionary[@"year"] unsignedIntegerValue]
15
+ month:[dictionary[@"month"] unsignedIntegerValue]];
16
+ }
17
+ if ([type isEqualToString:@"BirthDateWithDay"]) {
18
+ return [[AMAProfileAttribute birthDate] withYear:[dictionary[@"year"] unsignedIntegerValue]
19
+ month:[dictionary[@"month"] unsignedIntegerValue]
20
+ day:[dictionary[@"day"] unsignedIntegerValue]];
21
+ }
22
+ if ([type isEqualToString:@"BirthDateValueReset"]) {
23
+ return [[AMAProfileAttribute birthDate] withValueReset];
24
+ }
25
+ return nil;
26
+ }
27
+
28
+ AMAUserProfileUpdate *amarn_customBoolAttributeUpdateFromDictionary(NSDictionary *dictionary)
29
+ {
30
+ NSString *type = dictionary[@"type"];
31
+ if ([type isEqualToString:@"BooleanValue"]) {
32
+ NSString *key = dictionary[@"key"];
33
+ bool value = [dictionary[@"value"] boolValue];
34
+ if ([dictionary[@"ifUndefined"] boolValue]) {
35
+ return [[AMAProfileAttribute customBool:key] withValueIfUndefined:value];
36
+ }
37
+ return [[AMAProfileAttribute customBool:key] withValue:value];
38
+ }
39
+ if ([type isEqualToString:@"BooleanValueReset"]) {
40
+ NSString *key = dictionary[@"key"];
41
+ return [[AMAProfileAttribute customBool:key] withValueReset];
42
+ }
43
+ return nil;
44
+ }
45
+
46
+ AMAUserProfileUpdate *amarn_customCounterAttributeUpdateFromDictionary(NSDictionary *dictionary)
47
+ {
48
+ NSString *type = dictionary[@"type"];
49
+ if ([type isEqualToString:@"Counter"]) {
50
+ NSString *key = dictionary[@"key"];
51
+ double value = [dictionary[@"delta"] doubleValue];
52
+ return [[AMAProfileAttribute customCounter:key] withDelta:value];
53
+ }
54
+ return nil;
55
+ }
56
+
57
+ AMAGenderType amarn_genderTypeForString(NSString *genderStr)
58
+ {
59
+ if ([genderStr isEqualToString:@"male"]) {
60
+ return AMAGenderTypeMale;
61
+ }
62
+ if ([genderStr isEqualToString:@"female"]) {
63
+ return AMAGenderTypeFemale;
64
+ }
65
+ return AMAGenderTypeOther;
66
+ }
67
+
68
+ AMAUserProfileUpdate *amarn_genderAttributeFromDictionary(NSDictionary *dictionary)
69
+ {
70
+ NSString *type = dictionary[@"type"];
71
+ if ([type isEqualToString:@"GenderValue"]) {
72
+ AMAGenderType value = amarn_genderTypeForString(dictionary[@"value"]);
73
+ return [[AMAProfileAttribute gender] withValue:value];
74
+ }
75
+ if ([type isEqualToString:@"GenderValueReset"]) {
76
+ return [[AMAProfileAttribute gender] withValueReset];
77
+ }
78
+ return nil;
79
+ }
80
+
81
+ AMAUserProfileUpdate *amarn_nameAttributeFromDictionary(NSDictionary *dictionary)
82
+ {
83
+ NSString *type = dictionary[@"type"];
84
+ if ([type isEqualToString:@"NameValue"]) {
85
+ NSString *value = dictionary[@"value"];
86
+ return [[AMAProfileAttribute name] withValue:value];
87
+ }
88
+ if ([type isEqualToString:@"NameValueReset"]) {
89
+ return [[AMAProfileAttribute name] withValueReset];
90
+ }
91
+ return nil;
92
+ }
93
+
94
+ AMAUserProfileUpdate *amarn_notificationEnabledAttributeFromDictionary(NSDictionary *dictionary)
95
+ {
96
+ NSString *type = dictionary[@"type"];
97
+ if ([type isEqualToString:@"NotificationsEnabledValue"]) {
98
+ bool value = [dictionary[@"value"] boolValue];
99
+ return [[AMAProfileAttribute notificationsEnabled] withValue:value];
100
+ }
101
+ if ([type isEqualToString:@"NotificationsEnabledValueReset"]) {
102
+ return [[AMAProfileAttribute notificationsEnabled] withValueReset];
103
+ }
104
+ return nil;
105
+ }
106
+
107
+ AMAUserProfileUpdate *amarn_customNumberAttributeUpdateFromDictionary(NSDictionary *dictionary)
108
+ {
109
+ NSString *type = dictionary[@"type"];
110
+ if ([type isEqualToString:@"NumberValue"]) {
111
+ NSString *key = dictionary[@"key"];
112
+ double value = [dictionary[@"value"] doubleValue];
113
+ if ([dictionary[@"ifUndefined"] boolValue]) {
114
+ return [[AMAProfileAttribute customNumber:key] withValueIfUndefined:value];
115
+ }
116
+ return [[AMAProfileAttribute customNumber:key] withValue:value];
117
+ }
118
+ if ([type isEqualToString:@"NumberValueReset"]) {
119
+ NSString *key = dictionary[@"key"];
120
+ return [[AMAProfileAttribute customNumber:key] withValueReset];
121
+ }
122
+ return nil;
123
+ }
124
+
125
+ AMAUserProfileUpdate *amarn_customStringAttributeUpdateFromDictionary(NSDictionary *dictionary)
126
+ {
127
+ NSString *type = dictionary[@"type"];
128
+ if ([type isEqualToString:@"StringValue"]) {
129
+ NSString *key = dictionary[@"key"];
130
+ NSString *value = dictionary[@"value"];
131
+ if ([dictionary[@"ifUndefined"] boolValue]) {
132
+ return [[AMAProfileAttribute customString:key] withValueIfUndefined:value];
133
+ }
134
+ return [[AMAProfileAttribute customString:key] withValue:value];
135
+ }
136
+ if ([type isEqualToString:@"StringValueReset"]) {
137
+ NSString *key = dictionary[@"key"];
138
+ return [[AMAProfileAttribute customString:key] withValueReset];
139
+ }
140
+ return nil;
141
+ }
142
+
143
+ AMAUserProfileUpdate *amarn_userProfileUpdateFromDictionary(NSDictionary *dictionary)
144
+ {
145
+ return amarn_birthDateAttributeFromDictionary(dictionary)
146
+ ?: amarn_customBoolAttributeUpdateFromDictionary(dictionary)
147
+ ?: amarn_customCounterAttributeUpdateFromDictionary(dictionary)
148
+ ?: amarn_genderAttributeFromDictionary(dictionary)
149
+ ?: amarn_nameAttributeFromDictionary(dictionary)
150
+ ?: amarn_notificationEnabledAttributeFromDictionary(dictionary)
151
+ ?: amarn_customNumberAttributeUpdateFromDictionary(dictionary)
152
+ ?: amarn_customStringAttributeUpdateFromDictionary(dictionary);
153
+ }
154
+
155
+ AMAUserProfile *amarn_deserializeUserProfile(NSDictionary *dictionary) {
156
+
157
+ if (!dictionary) {
158
+ return nil;
159
+ }
160
+
161
+ NSArray *attributes = dictionary[@"attributes"];
162
+
163
+ if (!attributes && attributes.count == 0) {
164
+ return nil;
165
+ }
166
+
167
+ AMAMutableUserProfile *userProfile = [[AMAMutableUserProfile alloc] init];
168
+
169
+ for (NSDictionary* attribute in attributes) {
170
+
171
+ AMAUserProfileUpdate *update = amarn_userProfileUpdateFromDictionary(attribute);
172
+
173
+ if (!update) {
174
+ return nil;
175
+ }
176
+
177
+ [userProfile apply:update];
178
+ }
179
+
180
+
181
+ return userProfile;
182
+ }
@@ -4,49 +4,50 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.ECommerce = void 0;
7
+ var _utils = require("./utils");
7
8
  class ECommerce {
8
9
  static showScreenEvent(screen) {
9
10
  return {
10
11
  ecommerceEvent: 'showSceenEvent',
11
- ecommerceScreen: screen
12
+ ecommerceScreen: (0, _utils.normalizeECommerceScreen)(screen)
12
13
  };
13
14
  }
14
15
  static showProductCardEvent(product, screen) {
15
16
  return {
16
17
  ecommerceEvent: 'showProductCardEvent',
17
- ecommerceScreen: screen,
18
- product: product
18
+ ecommerceScreen: (0, _utils.normalizeECommerceScreen)(screen),
19
+ product: (0, _utils.normalizeECommerceProduct)(product)
19
20
  };
20
21
  }
21
22
  static showProductDetailsEvent(product, referrer) {
22
23
  return {
23
24
  ecommerceEvent: 'showProductDetailsEvent',
24
- product: product,
25
- referrer: referrer
25
+ product: (0, _utils.normalizeECommerceProduct)(product),
26
+ referrer: (0, _utils.normalizeECommerceReferrer)(referrer)
26
27
  };
27
28
  }
28
29
  static addCartItemEvent(item) {
29
30
  return {
30
31
  ecommerceEvent: 'addCartItemEvent',
31
- cartItem: item
32
+ cartItem: (0, _utils.normalizeECommerceCartItem)(item)
32
33
  };
33
34
  }
34
35
  static removeCartItemEvent(item) {
35
36
  return {
36
37
  ecommerceEvent: 'removeCartItemEvent',
37
- cartItem: item
38
+ cartItem: (0, _utils.normalizeECommerceCartItem)(item)
38
39
  };
39
40
  }
40
41
  static beginCheckoutEvent(order) {
41
42
  return {
42
43
  ecommerceEvent: 'beginCheckoutEvent',
43
- order: order
44
+ order: (0, _utils.normalizeECommerceOrder)(order)
44
45
  };
45
46
  }
46
47
  static purchaseEvent(order) {
47
48
  return {
48
49
  ecommerceEvent: 'purchaseEvent',
49
- order: order
50
+ order: (0, _utils.normalizeECommerceOrder)(order)
50
51
  };
51
52
  }
52
53
  }
@@ -1 +1 @@
1
- {"version":3,"names":["ECommerce","showScreenEvent","screen","ecommerceEvent","ecommerceScreen","showProductCardEvent","product","showProductDetailsEvent","referrer","addCartItemEvent","item","cartItem","removeCartItemEvent","beginCheckoutEvent","order","purchaseEvent","exports"],"sourceRoot":"../../src","sources":["ecommerce.ts"],"mappings":";;;;;;AAgEO,MAAMA,SAAS,CAAC;EACrB,OAAOC,eAAeA,CAACC,MAAuB,EAAkB;IAC9D,OAAO;MACLC,cAAc,EAAE,gBAAgB;MAChCC,eAAe,EAAEF;IACnB,CAAC;EACH;EAEA,OAAOG,oBAAoBA,CACzBC,OAAyB,EACzBJ,MAAuB,EACP;IAChB,OAAO;MACLC,cAAc,EAAE,sBAAsB;MACtCC,eAAe,EAAEF,MAAM;MACvBI,OAAO,EAAEA;IACX,CAAC;EACH;EAEA,OAAOC,uBAAuBA,CAC5BD,OAAyB,EACzBE,QAA4B,EACZ;IAChB,OAAO;MACLL,cAAc,EAAE,yBAAyB;MACzCG,OAAO,EAAEA,OAAO;MAChBE,QAAQ,EAAEA;IACZ,CAAC;EACH;EAEA,OAAOC,gBAAgBA,CAACC,IAAuB,EAAkB;IAC/D,OAAO;MACLP,cAAc,EAAE,kBAAkB;MAClCQ,QAAQ,EAAED;IACZ,CAAC;EACH;EAEA,OAAOE,mBAAmBA,CAACF,IAAuB,EAAkB;IAClE,OAAO;MACLP,cAAc,EAAE,qBAAqB;MACrCQ,QAAQ,EAAED;IACZ,CAAC;EACH;EAEA,OAAOG,kBAAkBA,CAACC,KAAqB,EAAkB;IAC/D,OAAO;MACLX,cAAc,EAAE,oBAAoB;MACpCW,KAAK,EAAEA;IACT,CAAC;EACH;EAEA,OAAOC,aAAaA,CAACD,KAAqB,EAAkB;IAC1D,OAAO;MACLX,cAAc,EAAE,eAAe;MAC/BW,KAAK,EAAEA;IACT,CAAC;EACH;AACF;AAACE,OAAA,CAAAhB,SAAA,GAAAA,SAAA","ignoreList":[]}
1
+ {"version":3,"names":["_utils","require","ECommerce","showScreenEvent","screen","ecommerceEvent","ecommerceScreen","normalizeECommerceScreen","showProductCardEvent","product","normalizeECommerceProduct","showProductDetailsEvent","referrer","normalizeECommerceReferrer","addCartItemEvent","item","cartItem","normalizeECommerceCartItem","removeCartItemEvent","beginCheckoutEvent","order","normalizeECommerceOrder","purchaseEvent","exports"],"sourceRoot":"../../src","sources":["ecommerce.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAwEO,MAAMC,SAAS,CAAC;EACrB,OAAOC,eAAeA,CAACC,MAAuB,EAAkB;IAC9D,OAAO;MACLC,cAAc,EAAE,gBAAgB;MAChCC,eAAe,EAAE,IAAAC,+BAAwB,EAACH,MAAM;IAClD,CAAC;EACH;EAEA,OAAOI,oBAAoBA,CACzBC,OAAyB,EACzBL,MAAuB,EACP;IAChB,OAAO;MACLC,cAAc,EAAE,sBAAsB;MACtCC,eAAe,EAAE,IAAAC,+BAAwB,EAACH,MAAM,CAAC;MACjDK,OAAO,EAAE,IAAAC,gCAAyB,EAACD,OAAO;IAC5C,CAAC;EACH;EAEA,OAAOE,uBAAuBA,CAC5BF,OAAyB,EACzBG,QAA4B,EACZ;IAChB,OAAO;MACLP,cAAc,EAAE,yBAAyB;MACzCI,OAAO,EAAE,IAAAC,gCAAyB,EAACD,OAAO,CAAC;MAC3CG,QAAQ,EAAE,IAAAC,iCAA0B,EAACD,QAAQ;IAC/C,CAAC;EACH;EAEA,OAAOE,gBAAgBA,CAACC,IAAuB,EAAkB;IAC/D,OAAO;MACLV,cAAc,EAAE,kBAAkB;MAClCW,QAAQ,EAAE,IAAAC,iCAA0B,EAACF,IAAI;IAC3C,CAAC;EACH;EAEA,OAAOG,mBAAmBA,CAACH,IAAuB,EAAkB;IAClE,OAAO;MACLV,cAAc,EAAE,qBAAqB;MACrCW,QAAQ,EAAE,IAAAC,iCAA0B,EAACF,IAAI;IAC3C,CAAC;EACH;EAEA,OAAOI,kBAAkBA,CAACC,KAAqB,EAAkB;IAC/D,OAAO;MACLf,cAAc,EAAE,oBAAoB;MACpCe,KAAK,EAAE,IAAAC,8BAAuB,EAACD,KAAK;IACtC,CAAC;EACH;EAEA,OAAOE,aAAaA,CAACF,KAAqB,EAAkB;IAC1D,OAAO;MACLf,cAAc,EAAE,eAAe;MAC/Be,KAAK,EAAE,IAAAC,8BAAuB,EAACD,KAAK;IACtC,CAAC;EACH;AACF;AAACG,OAAA,CAAArB,SAAA,GAAAA,SAAA","ignoreList":[]}