@metrixorg/react-native-plugin 1.5.0 → 2.0.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.
@@ -2,14 +2,13 @@ apply plugin: 'com.android.library'
2
2
 
3
3
 
4
4
  android {
5
- compileSdkVersion 28
6
- buildToolsVersion "28.0.3"
5
+ compileSdkVersion 31
7
6
 
8
7
  defaultConfig {
9
8
  minSdkVersion 16
10
- targetSdkVersion 28
11
- versionCode 100500199
12
- versionName "1.5.1"
9
+ targetSdkVersion 31
10
+ versionCode 200000055
11
+ versionName "2.0.0.beta5"
13
12
  }
14
13
 
15
14
  buildTypes {
@@ -29,6 +28,7 @@ rootProject.allprojects {
29
28
 
30
29
  dependencies {
31
30
  implementation 'com.facebook.react:react-native:+'
32
- implementation 'ir.metrix:metrix-reactnative:1.5.1'
33
31
 
32
+ implementation 'ir.metrix.analytics:metrix-reactnative:2.0.0.beta5'
33
+ implementation 'ir.metrix.attribution:metrix-reactnative:2.0.0.beta5'
34
34
  }
@@ -1,32 +1,28 @@
1
1
  package ir.metrix.reactnative;
2
2
 
3
- import android.app.Application;
4
3
  import android.net.Uri;
5
- import android.os.Bundle;
6
4
 
7
5
  import com.facebook.react.bridge.Arguments;
8
- import com.facebook.react.bridge.Callback;
9
6
  import com.facebook.react.bridge.ReactApplicationContext;
10
7
  import com.facebook.react.bridge.ReactContextBaseJavaModule;
11
8
  import com.facebook.react.bridge.ReactMethod;
12
9
  import com.facebook.react.bridge.ReadableMap;
13
10
  import com.facebook.react.bridge.ReadableMapKeySetIterator;
14
11
  import com.facebook.react.bridge.WritableMap;
15
-
16
12
  import com.facebook.react.modules.core.DeviceEventManagerModule;
17
13
 
18
- import android.util.Log;
19
-
20
14
  import java.util.HashMap;
21
15
  import java.util.Map;
22
16
 
23
- import ir.metrix.AttributionData;
24
- import ir.metrix.messaging.RevenueCurrency;
25
- import ir.metrix.OnAttributionChangeListener;
26
- import ir.metrix.OnDeeplinkResponseListener;
27
- import ir.metrix.UserIdListener;
28
- import ir.metrix.session.SessionIdListener;
29
- import ir.metrix.session.SessionNumberListener;
17
+ import ir.metrix.analytics.SessionIdListener;
18
+ import ir.metrix.analytics.SessionNumberListener;
19
+ import ir.metrix.analytics.messaging.MessageChannel;
20
+ import ir.metrix.analytics.messaging.RevenueCurrency;
21
+ import ir.metrix.analytics.messaging.UserGender;
22
+ import ir.metrix.attribution.AttributionData;
23
+ import ir.metrix.attribution.OnAttributionChangeListener;
24
+ import ir.metrix.attribution.OnDeeplinkResponseListener;
25
+ import ir.metrix.attribution.UserIdListener;
30
26
 
31
27
  public class MetrixModule extends ReactContextBaseJavaModule {
32
28
 
@@ -43,7 +39,7 @@ public class MetrixModule extends ReactContextBaseJavaModule {
43
39
 
44
40
  @ReactMethod
45
41
  public void newEvent(String eventName) {
46
- ir.metrix.Metrix.newEvent(eventName);
42
+ ir.metrix.analytics.MetrixAnalytics.newEvent(eventName);
47
43
  }
48
44
 
49
45
  @ReactMethod
@@ -56,75 +52,146 @@ public class MetrixModule extends ReactContextBaseJavaModule {
56
52
  customAttr.put(key, customAttributes.getString(key));
57
53
  }
58
54
 
59
- ir.metrix.Metrix.newEvent(eventName, customAttr);
55
+ ir.metrix.analytics.MetrixAnalytics.newEvent(eventName, customAttr);
60
56
  }
61
57
 
62
58
  @ReactMethod
63
59
  public void newRevenueSimple(String slug, Double revenue) {
64
- ir.metrix.Metrix.newRevenue(slug, revenue);
60
+ ir.metrix.analytics.MetrixAnalytics.newRevenue(slug, revenue);
65
61
  }
66
62
 
67
63
  @ReactMethod
68
64
  public void newRevenueCurrency(String slug, Double revenue, String currency) {
69
- ir.metrix.Metrix.newRevenue(slug, revenue, RevenueCurrency.valueOf(currency));
65
+ ir.metrix.analytics.MetrixAnalytics.newRevenue(slug, revenue, RevenueCurrency.valueOf(currency));
70
66
  }
71
67
 
72
68
  @ReactMethod
73
- public void newRevenueOrderId(String slug, Double revenue, String orderId) {
74
- ir.metrix.Metrix.newRevenue(slug, revenue, orderId);
69
+ public void setSessionNumberListener() {
70
+ ir.metrix.analytics.MetrixAnalytics.setSessionNumberListener(
71
+ new SessionNumberListener() {
72
+ @Override
73
+ public void onSessionNumberChanged(int sessionNumber) {
74
+ sendStringEvent("onSessionNumberChangedListener", String.valueOf(sessionNumber));
75
+ }
76
+ }
77
+ );
75
78
  }
76
79
 
77
80
  @ReactMethod
78
- public void newRevenueFull(String slug, Double revenue, String currency, String orderId) {
79
- ir.metrix.Metrix.newRevenue(slug, revenue, RevenueCurrency.valueOf(currency), orderId);
81
+ public void setSessionIdListener() {
82
+ ir.metrix.analytics.MetrixAnalytics.setSessionIdListener(
83
+ new SessionIdListener() {
84
+ @Override
85
+ public void onSessionIdChanged(String sessionId) {
86
+ sendStringEvent("onSessionIdChangedListener", sessionId);
87
+ }
88
+ }
89
+ );
80
90
  }
81
91
 
82
92
  @ReactMethod
83
- public void addUserAttributes(ReadableMap userAttributes) {
84
-
85
- Map<String, String> userAttrs = new HashMap<>();
86
-
93
+ public void setUserAttributes(ReadableMap userAttributes) {
87
94
  ReadableMapKeySetIterator userAttributesMapKeySetIterator = userAttributes.keySetIterator();
88
95
  while (userAttributesMapKeySetIterator.hasNextKey()) {
89
96
  String key = userAttributesMapKeySetIterator.nextKey();
90
- userAttrs.put(key, userAttributes.getString(key));
97
+ ir.metrix.analytics.MetrixAnalytics.User.setCustomAttribute(key, userAttributes.getString(key));
91
98
  }
99
+ }
92
100
 
93
- ir.metrix.Metrix.addUserAttributes(userAttrs);
101
+ @ReactMethod
102
+ public void setUserId(String id) {
103
+ ir.metrix.analytics.MetrixAnalytics.User.setUserId(id);
94
104
  }
95
105
 
96
106
  @ReactMethod
97
- public void setPushToken(String token) {
98
- ir.metrix.Metrix.setPushToken(token);
107
+ public void deleteUserId() {
108
+ ir.metrix.analytics.MetrixAnalytics.User.deleteUserId();
99
109
  }
100
110
 
101
111
  @ReactMethod
102
- public void setSessionNumberListener() {
103
- ir.metrix.Metrix.setSessionNumberListener(
104
- new SessionNumberListener() {
105
- @Override
106
- public void onSessionNumberChanged(int sessionNumber) {
107
- sendStringEvent("onSessionNumberChangedListener", String.valueOf(sessionNumber));
108
- }
109
- }
110
- );
112
+ public void setUserFirstName(String firstName) {
113
+ ir.metrix.analytics.MetrixAnalytics.User.setFirstName(firstName);
111
114
  }
112
115
 
113
116
  @ReactMethod
114
- public void setSessionIdListener() {
115
- ir.metrix.Metrix.setSessionIdListener(
116
- new SessionIdListener() {
117
- @Override
118
- public void onSessionIdChanged(String sessionId) {
119
- sendStringEvent("onSessionIdChangedListener", sessionId);
120
- }
121
- }
122
- );
117
+ public void setUserLastName(String lastName) {
118
+ ir.metrix.analytics.MetrixAnalytics.User.setLastName(lastName);
119
+ }
120
+
121
+ @ReactMethod
122
+ public void setUserPhoneNumber(String phoneNumber) {
123
+ ir.metrix.analytics.MetrixAnalytics.User.setPhoneNumber(phoneNumber);
124
+ }
125
+
126
+ @ReactMethod
127
+ public void setUserHashedPhoneNumber(String hashedPhoneNumber) {
128
+ ir.metrix.analytics.MetrixAnalytics.User.setHashedPhoneNumber(hashedPhoneNumber);
129
+ }
130
+
131
+ @ReactMethod
132
+ public void setUserEmail(String email) {
133
+ ir.metrix.analytics.MetrixAnalytics.User.setEmail(email);
134
+ }
135
+
136
+ @ReactMethod
137
+ public void setUserHashedEmail(String hashedEmail) {
138
+ ir.metrix.analytics.MetrixAnalytics.User.setHashedEmail(hashedEmail);
139
+ }
140
+
141
+ @ReactMethod
142
+ public void setUserCountry(String country) {
143
+ ir.metrix.analytics.MetrixAnalytics.User.setCountry(country);
144
+ }
145
+
146
+ @ReactMethod
147
+ public void setUserCity(String city) {
148
+ ir.metrix.analytics.MetrixAnalytics.User.setCity(city);
149
+ }
150
+
151
+ @ReactMethod
152
+ public void setUserRegion(String region) {
153
+ ir.metrix.analytics.MetrixAnalytics.User.setRegion(region);
154
+ }
155
+
156
+ @ReactMethod
157
+ public void setUserLocality(String locality) {
158
+ ir.metrix.analytics.MetrixAnalytics.User.setLocality(locality);
159
+ }
160
+
161
+ @ReactMethod
162
+ public void setUserGender(UserGender gender) {
163
+ ir.metrix.analytics.MetrixAnalytics.User.setGender(gender);
164
+ }
165
+
166
+ @ReactMethod
167
+ public void setUserBirthday(Long birthday) {
168
+ ir.metrix.analytics.MetrixAnalytics.User.setBirthday(birthday);
169
+ }
170
+
171
+ @ReactMethod
172
+ public void setUserFcmToken(String fcmToken) {
173
+ ir.metrix.analytics.MetrixAnalytics.User.setFcmToken(fcmToken);
174
+ }
175
+
176
+ @ReactMethod
177
+ public void userChannelEnabled(String channel) {
178
+ ir.metrix.analytics.MetrixAnalytics.User.channelEnabled(MessageChannel.valueOf(channel));
179
+ }
180
+
181
+ @ReactMethod
182
+ public void userChannelDisabled(String channel) {
183
+ ir.metrix.analytics.MetrixAnalytics.User.channelDisabled(MessageChannel.valueOf(channel));
184
+ }
185
+
186
+
187
+ @ReactMethod
188
+ public void setPushToken(String token) {
189
+ ir.metrix.attribution.MetrixAttribution.setPushToken(token);
123
190
  }
124
191
 
125
192
  @ReactMethod
126
193
  public void setOnAttributionChangedListener() {
127
- ir.metrix.Metrix.setOnAttributionChangedListener(
194
+ ir.metrix.attribution.MetrixAttribution.setOnAttributionChangedListener(
128
195
  new OnAttributionChangeListener() {
129
196
  @Override
130
197
  public void onAttributionChanged(AttributionData attributionData) {
@@ -137,7 +204,7 @@ public class MetrixModule extends ReactContextBaseJavaModule {
137
204
 
138
205
  @ReactMethod
139
206
  public void setUserIdListener() {
140
- ir.metrix.Metrix.setUserIdListener(
207
+ ir.metrix.attribution.MetrixAttribution.setUserIdListener(
141
208
  new UserIdListener() {
142
209
  @Override
143
210
  public void onUserIdReceived(String userId) {
@@ -148,7 +215,7 @@ public class MetrixModule extends ReactContextBaseJavaModule {
148
215
 
149
216
  @ReactMethod
150
217
  public void setOnDeeplinkResponseListener(final boolean shouldLaunchDeeplink) {
151
- ir.metrix.Metrix.setOnDeeplinkResponseListener(
218
+ ir.metrix.attribution.MetrixAttribution.setOnDeeplinkResponseListener(
152
219
  new OnDeeplinkResponseListener() {
153
220
  @Override
154
221
  public boolean launchReceivedDeeplink(Uri deeplink) {
@@ -190,13 +257,13 @@ public class MetrixModule extends ReactContextBaseJavaModule {
190
257
 
191
258
  private void sendObjectEvent(String eventName, WritableMap param) {
192
259
  getReactApplicationContext()
193
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
194
- .emit(eventName, param);
260
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
261
+ .emit(eventName, param);
195
262
  }
196
263
 
197
264
  private void sendStringEvent(String eventName, String param) {
198
265
  getReactApplicationContext()
199
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
200
- .emit(eventName, param);
266
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
267
+ .emit(eventName, param);
201
268
  }
202
269
  }
package/index.js CHANGED
@@ -55,26 +55,139 @@ Metrix.newEvent = function(eventName, customAttributes) {
55
55
  }
56
56
  };
57
57
 
58
- Metrix.newRevenue = function(slug, revenue, currencyOrderId, orderId) {
59
- if (currencyOrderId == null && orderId == null) {
58
+ Metrix.newRevenue = function(slug, revenue, currency) {
59
+ if (currency == null) {
60
60
  module_metrix.newRevenueSimple(slug, revenue);
61
- } else if (currencyOrderId != null && orderId == null) {
62
- if (typeof currencyOrderId === 'string') {
63
- module_metrix.newRevenueOrderId(slug, revenue, currencyOrderId);
61
+ } else if (currency != null) {
62
+ if (typeof currency === 'string') {
63
+ module_metrix.newRevenueOrderId(slug, revenue, currency);
64
64
  } else {
65
- let currency = getCurrency(currencyOrderId)
66
- module_metrix.newRevenueCurrency(slug, revenue, currency);
65
+ let currencyValue = getCurrency(currency)
66
+ module_metrix.newRevenueCurrency(slug, revenue, currencyValue);
67
67
  }
68
- } else {
69
- let currency = getCurrency(currencyOrderId)
70
- module_metrix.newRevenueFull(slug, revenue, currency, orderId);
71
68
  }
72
69
  };
73
70
 
74
- Metrix.addUserAttributes = function(userAttributes) {
75
- module_metrix.addUserAttributes(userAttributes);
71
+ Metrix.setUserAttributes = function(userAttributes) {
72
+ if (Platform.OS === "android") {
73
+ module_metrix.setUserAttributes(userAttributes);
74
+ } else if (Platform.OS === "ios") {
75
+ module_metrix.addUserAttributes(userAttributes);
76
+ }
76
77
  };
77
78
 
79
+ Metrix.setUserId = function(id) {
80
+ if (Platform.OS === "android") {
81
+ module_metrix.setUserId(id);
82
+ }
83
+ }
84
+
85
+ Metrix.deleteUserId = function() {
86
+ if (Platform.OS === "android") {
87
+ module_metrix.deleteUserId();
88
+ }
89
+ }
90
+
91
+ Metrix.setUserFirstName = function(firstName) {
92
+ if (Platform.OS === "android") {
93
+ module_metrix.setUserFirstName(firstName);
94
+ }
95
+ }
96
+
97
+ Metrix.setUserLastName = function(lastName) {
98
+ if (Platform.OS === "android") {
99
+ module_metrix.setUserLastName(lastName);
100
+ }
101
+ }
102
+
103
+ Metrix.setUserPhoneNumber = function(phoneNumber) {
104
+ if (Platform.OS === "android") {
105
+ module_metrix.setUserPhoneNumber(phoneNumber);
106
+ }
107
+ }
108
+
109
+ Metrix.setUserHashedPhoneNumber = function(hashedPhoneNumber) {
110
+ if (Platform.OS === "android") {
111
+ module_metrix.setUserHashedPhoneNumber(hashedPhoneNumber);
112
+ }
113
+ }
114
+
115
+ Metrix.setUserEmail = function(email) {
116
+ if (Platform.OS === "android") {
117
+ module_metrix.setUserEmail(email);
118
+ }
119
+ }
120
+
121
+ Metrix.setUserHashedEmail = function(hashedEmail) {
122
+ if (Platform.OS === "android") {
123
+ module_metrix.setUserHashedEmail(hashedEmail);
124
+ }
125
+ }
126
+
127
+ Metrix.setUserCountry = function(country) {
128
+ if (Platform.OS === "android") {
129
+ module_metrix.setUserCountry(country);
130
+ }
131
+ }
132
+
133
+ Metrix.setUserCity = function(city) {
134
+ if (Platform.OS === "android") {
135
+ module_metrix.setUserCity(city);
136
+ }
137
+ }
138
+
139
+ Metrix.setUserRegion = function(region) {
140
+ if (Platform.OS === "android") {
141
+ module_metrix.setUserRegion(region);
142
+ }
143
+ }
144
+
145
+ Metrix.setUserLocality = function(locality) {
146
+ if (Platform.OS === "android") {
147
+ module_metrix.setUserLocality(locality);
148
+ }
149
+ }
150
+
151
+ Metrix.setUserGender = function(gender) {
152
+ if (Platform.OS === "android") {
153
+ module_metrix.setUserGender(gender);
154
+ }
155
+ }
156
+
157
+ Metrix.setUserBirthday = function(birthday) {
158
+ if (Platform.OS === "android") {
159
+ module_metrix.setUserBirthday(birthday);
160
+ }
161
+ }
162
+
163
+ Metrix.setUserFcmToken = function(fcmToken) {
164
+ if (Platform.OS === "android") {
165
+ module_metrix.setUserFcmToken(fcmToken);
166
+ }
167
+ }
168
+
169
+ Metrix.userChannelEnabled = function(channel) {
170
+ if (Platform.OS === "android") {
171
+ if (typeof channel === 'string') {
172
+ module_metrix.userChannelEnabled(channel);
173
+ } else {
174
+ let channelValue = getChannel(channel)
175
+ module_metrix.userChannelEnabled(channelValue);
176
+ }
177
+ }
178
+ }
179
+
180
+ Metrix.userChannelDisabled = function(channel) {
181
+ if (Platform.OS === "android") {
182
+ if (typeof channel === 'string') {
183
+ module_metrix.userChannelDisabled(channel);
184
+ } else {
185
+ let channelValue = getChannel(channel)
186
+ module_metrix.userChannelDisabled(channelValue);
187
+ }
188
+ }
189
+ }
190
+
78
191
  // not used in android
79
192
  Metrix.setStore = function(storeName) {
80
193
  if (Platform.OS === "ios") {
@@ -98,7 +211,6 @@ Metrix.setDefaultTracker = function(trackerToken) {
98
211
 
99
212
  module.exports = { Metrix }
100
213
 
101
-
102
214
  function getCurrency(currency) {
103
215
  let cr = null;
104
216
  if (Platform.OS === "android") {
@@ -118,4 +230,17 @@ function getCurrency(currency) {
118
230
  }
119
231
 
120
232
  return cr;
233
+ }
234
+
235
+ function getChannel(channel) {
236
+ let ch = null;
237
+ if (channel === 2) {
238
+ ch = "SMS";
239
+ } else if (channel === 1) {
240
+ ch = "PUSH";
241
+ } else {
242
+ ch = "EMAIL";
243
+ }
244
+
245
+ return ch;
121
246
  }
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@metrixorg/react-native-plugin",
3
- "version": "1.5.0",
3
+ "version": "2.0.0",
4
4
  "description": "Metrix React native plugin",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1",
8
8
  "deploy": "git checkout master && git pull && git merge develop",
9
- "major": "npm version major",
10
- "minor": "npm version minor",
11
- "patch": "npm version patch"
9
+ "major": "2",
10
+ "minor": "0",
11
+ "patch": "0"
12
12
  },
13
13
  "author": "Metrix",
14
14
  "license": "Apache 2.0",