plotline-engage 4.0.8 → 4.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.
@@ -107,44 +107,51 @@ public class RNPlotline extends ReactContextBaseJavaModule {
107
107
  Plotline.track(eventName, activity);
108
108
  }
109
109
 
110
- @ReactMethod
111
- public void track(String eventName, ReadableMap object){
112
- final Activity activity = getCurrentActivity();
113
- JSONObject properties = new JSONObject();
110
+ public JSONObject getJSONObjectFromReadableMap(ReadableMap object) {
111
+ JSONObject jsonObject = new JSONObject();
114
112
  if (object != null) {
115
113
  ReadableMapKeySetIterator iterator = object.keySetIterator();
116
114
  while (iterator.hasNextKey()) {
117
115
  String key = iterator.nextKey();
118
116
  ReadableType type = object.getType(key);
119
- if (type == ReadableType.String) {
120
- try {
121
- properties.put((String) key, (String) object.getString(key));
122
- } catch (JSONException e) {
117
+ try {
118
+ switch (type) {
119
+ case String:
120
+ jsonObject.put(key, object.getString(key));
121
+ break;
122
+ case Number:
123
+ double doubleValue = object.getDouble(key);
124
+ if (doubleValue == (int) doubleValue) {
125
+ jsonObject.put(key, (int) doubleValue);
126
+ } else {
127
+ jsonObject.put(key, doubleValue);
128
+ }
129
+ break;
130
+ case Boolean:
131
+ jsonObject.put(key, object.getBoolean(key));
132
+ break;
133
+ default:
134
+ break;
135
+ }
136
+ } catch (Exception e) {
123
137
  e.printStackTrace();
124
- }
125
138
  }
126
139
  }
127
140
  }
141
+ return jsonObject;
142
+ }
143
+
144
+
145
+ @ReactMethod
146
+ public void track(String eventName, ReadableMap object){
147
+ final Activity activity = getCurrentActivity();
148
+ JSONObject properties = getJSONObjectFromReadableMap(object);
128
149
  Plotline.track(eventName, properties, activity);
129
150
  }
130
151
 
131
152
  @ReactMethod
132
153
  public void identify(ReadableMap object) {
133
- JSONObject jsonObject = new JSONObject();
134
- if (object != null) {
135
- ReadableMapKeySetIterator iterator = object.keySetIterator();
136
- while (iterator.hasNextKey()) {
137
- String key = iterator.nextKey();
138
- ReadableType type = object.getType(key);
139
- if (type == ReadableType.String) {
140
- try {
141
- jsonObject.put((String) key, (String) object.getString(key));
142
- } catch (JSONException e) {
143
- e.printStackTrace();
144
- }
145
- }
146
- }
147
- }
154
+ JSONObject jsonObject = getJSONObjectFromReadableMap(object);
148
155
  Plotline.identify(jsonObject);
149
156
  }
150
157
 
package/index.js CHANGED
@@ -4,6 +4,28 @@ import { ScrollView as RNScrollView, FlatList as RNFlatList} from 'react-native'
4
4
  import React from 'react';
5
5
  const { RNPlotline } = NativeModules;
6
6
 
7
+ function convertToStringValues(obj) {
8
+ const convertedObj = {};
9
+
10
+ for (let key in obj) {
11
+ if (obj.hasOwnProperty(key)) {
12
+ const value = obj[key];
13
+
14
+ if (typeof value === 'number') {
15
+ convertedObj[key] = String(value);
16
+ }
17
+ else if (typeof value === 'boolean') {
18
+ convertedObj[key] = value ? "true" : "false";
19
+ }
20
+ else if (typeof value === 'string') {
21
+ convertedObj[key] = value;
22
+ }
23
+ }
24
+ }
25
+
26
+ return convertedObj;
27
+ }
28
+
7
29
  class plotline {
8
30
  constructor() {
9
31
  this.throttledNotifyScroll = this.throttle(this.handleScroll, 250);
@@ -43,7 +65,7 @@ class plotline {
43
65
 
44
66
  track (eventName, properties) {
45
67
  if (properties)
46
- RNPlotline.track(eventName, properties);
68
+ RNPlotline.track(eventName, convertToStringValues(properties));
47
69
  else
48
70
  RNPlotline.track(eventName, null);
49
71
  }
@@ -53,7 +75,7 @@ class plotline {
53
75
  }
54
76
 
55
77
  identify (obj) {
56
- RNPlotline.identify(obj);
78
+ RNPlotline.identify(convertToStringValues(obj));
57
79
  }
58
80
 
59
81
  setLocale (locale) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plotline-engage",
3
- "version": "4.0.8",
3
+ "version": "4.1.0",
4
4
  "description": "React Native plugin for Plotline",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"