@metrixorg/cordova-plugin 1.5.0 → 2.6.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.
- package/package.json +1 -1
- package/plugin.xml +3 -2
- package/src/android/MetrixCordova.java +228 -67
- package/src/android/MetrixCordovaUtils.java +37 -14
- package/src/android/Reflection.java +16 -0
- package/src/android/metrix.gradle +12 -1
- package/src/ios/MetrixCordova.m +1 -0
- package/www/metrix.js +160 -23
package/package.json
CHANGED
package/plugin.xml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<?xml version='1.0' encoding='utf-8'?>
|
|
2
2
|
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
|
3
3
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
4
|
-
id="ir.metrix.cordova" version="
|
|
4
|
+
id="ir.metrix.cordova" version="2.6.0" >
|
|
5
5
|
<name>Metrix</name>
|
|
6
6
|
<description>Metrix SDK plugin for Cordova</description>
|
|
7
7
|
<author>Metrix</author>
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
|
|
28
28
|
<source-file src="src/android/MetrixCordova.java" target-dir="src/ir/metrix/cordova" />
|
|
29
29
|
<source-file src="src/android/MetrixCordovaUtils.java" target-dir="src/ir/metrix/cordova" />
|
|
30
|
+
<source-file src="src/android/Reflection.java" target-dir="src/ir/metrix/cordova" />
|
|
30
31
|
|
|
31
32
|
<framework src="src/android/metrix.gradle" custom="true" type="gradleReference"/>
|
|
32
33
|
</platform>
|
|
@@ -47,7 +48,7 @@
|
|
|
47
48
|
<source url="https://cdn.cocoapods.org/"/>
|
|
48
49
|
</config>
|
|
49
50
|
<pods>
|
|
50
|
-
<pod name="Metrix/cordova" spec="2.0
|
|
51
|
+
<pod name="Metrix/cordova" spec="2.1.0" />
|
|
51
52
|
</pods>
|
|
52
53
|
</podspec>
|
|
53
54
|
|
|
@@ -11,10 +11,21 @@ import org.json.JSONArray;
|
|
|
11
11
|
import org.json.JSONException;
|
|
12
12
|
import org.json.JSONObject;
|
|
13
13
|
import android.os.Bundle;
|
|
14
|
+
import android.Reflection;
|
|
14
15
|
import android.app.Application;
|
|
16
|
+
|
|
15
17
|
import static ir.metrix.cordova.MetrixCordovaUtils.*;
|
|
16
|
-
import ir.metrix.
|
|
17
|
-
|
|
18
|
+
import static ir.metrix.cordova.Reflection.*;
|
|
19
|
+
|
|
20
|
+
import ir.metrix.analytics.SessionIdListener;
|
|
21
|
+
import ir.metrix.analytics.SessionNumberListener;
|
|
22
|
+
import ir.metrix.analytics.messaging.MessageChannel;
|
|
23
|
+
import ir.metrix.analytics.messaging.RevenueCurrency;
|
|
24
|
+
import ir.metrix.analytics.messaging.UserGender;
|
|
25
|
+
import ir.metrix.attribution.AttributionData;
|
|
26
|
+
import ir.metrix.attribution.OnAttributionChangeListener;
|
|
27
|
+
import ir.metrix.attribution.OnDeeplinkResponseListener;
|
|
28
|
+
import ir.metrix.attribution.UserIdListener;
|
|
18
29
|
|
|
19
30
|
public class MetrixCordova extends CordovaPlugin {
|
|
20
31
|
|
|
@@ -28,76 +39,84 @@ public class MetrixCordova extends CordovaPlugin {
|
|
|
28
39
|
@Override
|
|
29
40
|
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
|
|
30
41
|
if (action.equals(COMMAND_INITIALIZE) ||
|
|
31
|
-
action.equals(COMMAND_SET_STORE) ||
|
|
32
|
-
action.equals(COMMAND_SET_APP_SECRET) ||
|
|
33
42
|
action.equals(COMMAND_SET_DEFAULT_TRACKER)) {
|
|
34
43
|
} else if (action.equals(COMMAND_SET_ATTRIBUTION_CHANGE_LISTENER)) {
|
|
35
44
|
attributionCallbackContext = callbackContext;
|
|
36
45
|
setAttributionListener();
|
|
37
|
-
} else if (action.equals(COMMAND_SET_PUSH_TOKEN)) {
|
|
38
|
-
String token = args.getString(0);
|
|
39
|
-
ir.metrix.Metrix.setPushToken(token);
|
|
40
|
-
} else if (action.equals(COMMAND_GET_SESSION_NUMBER)) {
|
|
41
|
-
sessionNumberCallbackContext = callbackContext;
|
|
42
|
-
setSessionNumberListener();
|
|
43
|
-
} else if (action.equals(COMMAND_TRACK_SIMPLE_EVENT)) {
|
|
44
|
-
String slug = args.getString(0);
|
|
45
|
-
ir.metrix.Metrix.newEvent(slug);
|
|
46
|
-
} else if (action.equals(COMMAND_TRACK_CUSTOM_EVENT)) {
|
|
47
|
-
sendCustomEvent(args);
|
|
48
|
-
} else if (action.equals(COMMAND_TRACK_SIMPLE_REVENUE)) {
|
|
49
|
-
trackSimpleRevenue(args);
|
|
50
|
-
} else if (action.equals(COMMAND_TRACK_FULL_REVENUE)) {
|
|
51
|
-
trackFullRevenue(args);
|
|
52
|
-
} else if (action.equals(COMMAND_SET_DEEPLINK_RESPONSE_CALLBACK)) {
|
|
53
|
-
deeplinkCallbackContext = callbackContext;
|
|
54
|
-
setDeeplinkListener();
|
|
55
|
-
} else if (action.equals(COMMAND_ADD_USER_DEFAULT_ATTRIBUTES)) {
|
|
56
|
-
addUserAttributes(args);
|
|
57
46
|
} else if (action.equals(COMMAND_SET_USER_ID_LISTENER)) {
|
|
58
47
|
userIdCallbackContext = callbackContext;
|
|
59
48
|
setUserIdListener();
|
|
60
|
-
} else if (action.equals(
|
|
49
|
+
} else if (action.equals(COMMAND_SET_SESSION_ID_LISTENER)) {
|
|
61
50
|
sessionIdCallbackContext = callbackContext;
|
|
62
51
|
setSessionIdListener();
|
|
52
|
+
} else if (action.equals(COMMAND_SET_SESSION_NUMBER_LISTENER)) {
|
|
53
|
+
sessionNumberCallbackContext = callbackContext;
|
|
54
|
+
setSessionNumberListener();
|
|
55
|
+
} else if (action.equals(COMMAND_SET_DEEPLINK_RESPONSE_LISTENER)) {
|
|
56
|
+
deeplinkCallbackContext = callbackContext;
|
|
57
|
+
setDeeplinkListener();
|
|
63
58
|
} else if (action.equals(COMMAND_SET_SHOULD_LAUNCH_DEEPLINK)) {
|
|
64
59
|
shouldLaunchDeeplink = args.getBoolean(0);
|
|
60
|
+
} else if (action.equals(COMMAND_SET_SIGNATURE)) {
|
|
61
|
+
setSignature(args);
|
|
62
|
+
} else if (action.equals(COMMAND_SET_DEFAULT_TRACKER)) {
|
|
63
|
+
setDefaultTracker(args);
|
|
64
|
+
} else if (action.equals(COMMAND_SET_STORE)) {
|
|
65
|
+
setStore(args);
|
|
66
|
+
} else if (action.equals(COMMAND_TRACK_SIMPLE_EVENT)) {
|
|
67
|
+
sendSimpleEvent(args);
|
|
68
|
+
} else if (action.equals(COMMAND_TRACK_CUSTOM_EVENT)) {
|
|
69
|
+
sendCustomEvent(args);
|
|
70
|
+
} else if (action.equals(COMMAND_TRACK_REVENUE)) {
|
|
71
|
+
trackRevenue(args);
|
|
72
|
+
} else if (action.equals(COMMAND_TRACK_REVENUE_BY_NAME)) {
|
|
73
|
+
trackRevenueByName(args);
|
|
74
|
+
} else if (action.equals(COMMAND_SET_USER_ATTRIBUTES)) {
|
|
75
|
+
setUserAttributes(args);
|
|
76
|
+
} else if (action.equals(COMMAND_SET_USER_CUSTOM_ID)) {
|
|
77
|
+
setUserCustomId(args);
|
|
78
|
+
} else if (action.equals(COMMAND_DELETE_USER_CUSTOM_ID)) {
|
|
79
|
+
deleteUserCustomId();
|
|
80
|
+
} else if (action.equals(COMMAND_SET_USER_FIRST_NAME)) {
|
|
81
|
+
setUserFirstName(args);
|
|
82
|
+
} else if (action.equals(COMMAND_SET_USER_LAST_NAME)) {
|
|
83
|
+
setUserLastName(args);
|
|
84
|
+
} else if (action.equals(COMMAND_SET_USER_PHONE_NUMBER)) {
|
|
85
|
+
setUserPhoneNumber(args);
|
|
86
|
+
} else if (action.equals(COMMAND_SET_USER_HASHED_PHONEN_NUMBER)) {
|
|
87
|
+
setUserHashedPhoneNumber(args);
|
|
88
|
+
} else if (action.equals(COMMAND_SET_USER_EMAIL)) {
|
|
89
|
+
setUserEmail(args);
|
|
90
|
+
} else if (action.equals(COMMAND_SET_USER_HASHED_EMAIL)) {
|
|
91
|
+
setUserHashedEmail(args);
|
|
92
|
+
} else if (action.equals(COMMAND_SET_USER_COUNTRY)) {
|
|
93
|
+
setUserCountry(args);
|
|
94
|
+
} else if (action.equals(COMMAND_SET_USER_CITY)) {
|
|
95
|
+
setUserCity(args);
|
|
96
|
+
} else if (action.equals(COMMAND_SET_USER_REGION)) {
|
|
97
|
+
setUserRegion(args);
|
|
98
|
+
} else if (action.equals(COMMAND_SET_USER_LOCALITY)) {
|
|
99
|
+
setUserLocality(args);
|
|
100
|
+
} else if (action.equals(COMMAND_SET_USER_GENDER)) {
|
|
101
|
+
setUserGender(args);
|
|
102
|
+
} else if (action.equals(COMMAND_SET_USER_BIRTHDAY)) {
|
|
103
|
+
setUserBirthday(args);
|
|
104
|
+
} else if (action.equals(COMMAND_SET_USER_CHANNEL_ENABLED)) {
|
|
105
|
+
userChannelEnabled(args);
|
|
106
|
+
} else if (action.equals(COMMAND_SET_USER_CHANNEL_DISABLED)) {
|
|
107
|
+
userChannelDisabled(args);
|
|
108
|
+
} else if (action.equals(COMMAND_LOADL_IN_APP_MESSAGES)) {
|
|
109
|
+
loadInAppMessages();
|
|
65
110
|
} else {
|
|
66
111
|
callbackContext.error("\"" + action + "\" is not a recognized action.");
|
|
67
112
|
return false;
|
|
68
113
|
}
|
|
69
114
|
return true;
|
|
70
115
|
}
|
|
71
|
-
|
|
72
|
-
private void setSessionNumberListener() {
|
|
73
|
-
if (sessionNumberCallbackContext != null) {
|
|
74
|
-
ir.metrix.Metrix.setSessionNumberListener(new ir.metrix.session.SessionNumberListener() {
|
|
75
|
-
@Override
|
|
76
|
-
public void onSessionNumberChanged(int sessionNum) {
|
|
77
|
-
PluginResult pluginResult = new PluginResult(Status.OK, sessionNum);
|
|
78
|
-
pluginResult.setKeepCallback(true);
|
|
79
|
-
sessionNumberCallbackContext.sendPluginResult(pluginResult);
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
private void setSessionIdListener() {
|
|
86
|
-
if (sessionIdCallbackContext != null) {
|
|
87
|
-
ir.metrix.Metrix.setSessionIdListener(new ir.metrix.session.SessionIdListener() {
|
|
88
|
-
@Override
|
|
89
|
-
public void onSessionIdChanged(String sessionId) {
|
|
90
|
-
PluginResult pluginResult = new PluginResult(Status.OK, sessionId);
|
|
91
|
-
pluginResult.setKeepCallback(true);
|
|
92
|
-
sessionIdCallbackContext.sendPluginResult(pluginResult);
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
116
|
|
|
98
117
|
private void setAttributionListener() {
|
|
99
118
|
if (attributionCallbackContext != null) {
|
|
100
|
-
ir.metrix.
|
|
119
|
+
ir.metrix.attribution.MetrixAttribution.setOnAttributionChangedListener(new OnAttributionChangeListener() {
|
|
101
120
|
@Override
|
|
102
121
|
public void onAttributionChanged(AttributionData attributionData) {
|
|
103
122
|
JSONObject attributionJsonData = new JSONObject(getAttributionMap(attributionData));
|
|
@@ -111,7 +130,7 @@ public class MetrixCordova extends CordovaPlugin {
|
|
|
111
130
|
|
|
112
131
|
private void setUserIdListener() {
|
|
113
132
|
if (userIdCallbackContext != null) {
|
|
114
|
-
ir.metrix.
|
|
133
|
+
ir.metrix.attribution.MetrixAttribution.setUserIdListener(new UserIdListener() {
|
|
115
134
|
@Override
|
|
116
135
|
public void onUserIdReceived(String metrixUserId) {
|
|
117
136
|
PluginResult pluginResult = new PluginResult(Status.OK, metrixUserId);
|
|
@@ -124,7 +143,7 @@ public class MetrixCordova extends CordovaPlugin {
|
|
|
124
143
|
|
|
125
144
|
private void setDeeplinkListener() {
|
|
126
145
|
if (deeplinkCallbackContext != null) {
|
|
127
|
-
ir.metrix.
|
|
146
|
+
ir.metrix.attribution.MetrixAttribution.setOnDeeplinkResponseListener(new OnDeeplinkResponseListener() {
|
|
128
147
|
@Override
|
|
129
148
|
public boolean launchReceivedDeeplink(Uri deeplink) {
|
|
130
149
|
PluginResult pluginResult = new PluginResult(Status.OK, deeplink.toString());
|
|
@@ -136,32 +155,174 @@ public class MetrixCordova extends CordovaPlugin {
|
|
|
136
155
|
});
|
|
137
156
|
}
|
|
138
157
|
}
|
|
158
|
+
|
|
159
|
+
private void setSessionNumberListener() {
|
|
160
|
+
if (sessionNumberCallbackContext != null) {
|
|
161
|
+
ir.metrix.analytics.MetrixAnalytics.setSessionNumberListener(new SessionNumberListener() {
|
|
162
|
+
@Override
|
|
163
|
+
public void onSessionNumberChanged(int sessionNum) {
|
|
164
|
+
PluginResult pluginResult = new PluginResult(Status.OK, sessionNum);
|
|
165
|
+
pluginResult.setKeepCallback(true);
|
|
166
|
+
sessionNumberCallbackContext.sendPluginResult(pluginResult);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
private void setSessionIdListener() {
|
|
173
|
+
if (sessionIdCallbackContext != null) {
|
|
174
|
+
ir.metrix.analytics.MetrixAnalytics.setSessionIdListener(new SessionIdListener() {
|
|
175
|
+
@Override
|
|
176
|
+
public void onSessionIdChanged(String sessionId) {
|
|
177
|
+
PluginResult pluginResult = new PluginResult(Status.OK, sessionId);
|
|
178
|
+
pluginResult.setKeepCallback(true);
|
|
179
|
+
sessionIdCallbackContext.sendPluginResult(pluginResult);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
private void setSignature(final JSONArray args) throws JSONException {
|
|
186
|
+
String signature = args.getString(0);
|
|
187
|
+
ir.metrix.attribution.MetrixAttribution.setSignature(signature);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
private void setDefaultTracker(final JSONArray args) throws JSONException {
|
|
191
|
+
String trackerToken = args.getString(0);
|
|
192
|
+
ir.metrix.attribution.MetrixAttribution.setDefaultTracker(trackerToken);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
private void setStore(final JSONArray args) throws JSONException {
|
|
196
|
+
String store = args.getString(0);
|
|
197
|
+
ir.metrix.attribution.MetrixAttribution.setStore(store);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
private void sendSimpleEvent(final JSONArray args) throws JSONException {
|
|
201
|
+
String slug = args.getString(0);
|
|
202
|
+
ir.metrix.analytics.MetrixAnalytics.newEvent(slug);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
private void sendSimpleEventByName(final JSONArray args) throws JSONException {
|
|
206
|
+
String name = args.getString(0);
|
|
207
|
+
ir.metrix.analytics.MetrixAnalytics.newEventByName(name);
|
|
208
|
+
}
|
|
139
209
|
|
|
140
210
|
private void sendCustomEvent(final JSONArray args) throws JSONException {
|
|
141
211
|
String slug = args.getString(0);
|
|
142
212
|
String attributesJson = args.getString(1);
|
|
143
|
-
Map<String,
|
|
144
|
-
ir.metrix.
|
|
213
|
+
Map<String, Object> attributes = jsonObjectToObjectMap(new JSONObject(attributesJson));
|
|
214
|
+
ir.metrix.analytics.MetrixAnalytics.newEvent(slug, attributes);
|
|
145
215
|
}
|
|
146
|
-
|
|
147
|
-
private void
|
|
148
|
-
String
|
|
149
|
-
|
|
150
|
-
|
|
216
|
+
|
|
217
|
+
private void sendCustomEventByName(final JSONArray args) throws JSONException {
|
|
218
|
+
String name = args.getString(0);
|
|
219
|
+
String attributesJson = args.getString(1);
|
|
220
|
+
Map<String, Object> attributes = jsonObjectToObjectMap(new JSONObject(attributesJson));
|
|
221
|
+
ir.metrix.analytics.MetrixAnalytics.newEventByName(name, attributes);
|
|
151
222
|
}
|
|
152
223
|
|
|
153
|
-
private void
|
|
224
|
+
private void trackRevenue(final JSONArray args) throws JSONException {
|
|
154
225
|
String slug = args.getString(0);
|
|
155
226
|
Double amount = args.getDouble(1);
|
|
156
227
|
RevenueCurrency currency = RevenueCurrency.valueOf(args.getString(2));
|
|
157
|
-
ir.metrix.
|
|
228
|
+
ir.metrix.analytics.MetrixAnalytics.newRevenue(slug, amount, currency);
|
|
158
229
|
}
|
|
159
230
|
|
|
160
|
-
private void
|
|
161
|
-
String
|
|
231
|
+
private void trackRevenueByName(final JSONArray args) throws JSONException {
|
|
232
|
+
String name = args.getString(0);
|
|
162
233
|
Double amount = args.getDouble(1);
|
|
163
234
|
RevenueCurrency currency = RevenueCurrency.valueOf(args.getString(2));
|
|
164
|
-
|
|
165
|
-
|
|
235
|
+
ir.metrix.analytics.MetrixAnalytics.newRevenueByName(name, amount, currency);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
private void setUserAttributes(final JSONArray args) throws JSONException {
|
|
239
|
+
String attributesJson = args.getString(0);
|
|
240
|
+
Map<String, Object> attributes = jsonObjectToObjectMap(new JSONObject(attributesJson));
|
|
241
|
+
for (Map.Entry<String, Object> entry : attributes.entrySet()) {
|
|
242
|
+
ir.metrix.analytics.MetrixAnalytics.User.setCustomAttribute(entry.getKey(), entry.getValue());
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
private void setUserCustomId(final JSONArray args) throws JSONException {
|
|
247
|
+
String id = args.getString(0);
|
|
248
|
+
ir.metrix.analytics.MetrixAnalytics.User.setUserCustomId(id);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
private void deleteUserCustomId() {
|
|
252
|
+
ir.metrix.analytics.MetrixAnalytics.User.deleteUserCustomId();
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
private void setUserFirstName(final JSONArray args) throws JSONException {
|
|
256
|
+
String firstName = args.getString(0);
|
|
257
|
+
ir.metrix.analytics.MetrixAnalytics.User.setFirstName(firstName);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
private void setUserLastName(final JSONArray args) throws JSONException {
|
|
261
|
+
String lastName = args.getString(0);
|
|
262
|
+
ir.metrix.analytics.MetrixAnalytics.User.setLastName(lastName);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
private void setUserPhoneNumber(final JSONArray args) throws JSONException {
|
|
266
|
+
String phoneNumber = args.getString(0);
|
|
267
|
+
ir.metrix.analytics.MetrixAnalytics.User.setPhoneNumber(phoneNumber);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
private void setUserHashedPhoneNumber(final JSONArray args) throws JSONException {
|
|
271
|
+
String hashedPhoneNumber = args.getString(0);
|
|
272
|
+
ir.metrix.analytics.MetrixAnalytics.User.setHashedPhoneNumber(hashedPhoneNumber);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
private void setUserEmail(final JSONArray args) throws JSONException {
|
|
276
|
+
String email = args.getString(0);
|
|
277
|
+
ir.metrix.analytics.MetrixAnalytics.User.setEmail(email);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
private void setUserHashedEmail(final JSONArray args) throws JSONException {
|
|
281
|
+
String hashedEmail = args.getString(0);
|
|
282
|
+
ir.metrix.analytics.MetrixAnalytics.User.setHashedEmail(hashedEmail);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
private void setUserCountry(final JSONArray args) throws JSONException {
|
|
286
|
+
String country = args.getString(0);
|
|
287
|
+
ir.metrix.analytics.MetrixAnalytics.User.setCountry(country);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
private void setUserCity(final JSONArray args) throws JSONException {
|
|
291
|
+
String city = args.getString(0);
|
|
292
|
+
ir.metrix.analytics.MetrixAnalytics.User.setCity(city);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
private void setUserRegion(final JSONArray args) throws JSONException {
|
|
296
|
+
String region = args.getString(0);
|
|
297
|
+
ir.metrix.analytics.MetrixAnalytics.User.setRegion(region);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
private void setUserLocality(final JSONArray args) throws JSONException {
|
|
301
|
+
String locality = args.getString(0);
|
|
302
|
+
ir.metrix.analytics.MetrixAnalytics.User.setLocality(locality);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
private void setUserGender(final JSONArray args) throws JSONException {
|
|
306
|
+
String gender = args.getString(0);
|
|
307
|
+
ir.metrix.analytics.MetrixAnalytics.User.setGender(UserGender.valueOf(gender));
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
private void setUserBirthday(final JSONArray args) throws JSONException {
|
|
311
|
+
double birthday = args.getDouble(0);
|
|
312
|
+
ir.metrix.analytics.MetrixAnalytics.User.setBirthday(Double.valueOf(birthday).longValue());
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
private void userChannelEnabled(final JSONArray args) throws JSONException {
|
|
316
|
+
String channel = args.getString(0);
|
|
317
|
+
ir.metrix.analytics.MetrixAnalytics.User.channelEnabled(MessageChannel.valueOf(channel));
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
private void userChannelDisabled(final JSONArray args) throws JSONException {
|
|
321
|
+
String channel = args.getString(0);
|
|
322
|
+
ir.metrix.analytics.MetrixAnalytics.User.channelDisabled(MessageChannel.valueOf(channel));
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
private void loadInAppMessages() {
|
|
326
|
+
invokeStaticMethod("ir.metrix.notification.MetrixNotification", "loadInAppMessages");
|
|
166
327
|
}
|
|
167
328
|
}
|
|
@@ -11,31 +11,51 @@ import ir.metrix.AttributionData;
|
|
|
11
11
|
public class MetrixCordovaUtils {
|
|
12
12
|
// iOS only
|
|
13
13
|
public static final String COMMAND_INITIALIZE = "initialize";
|
|
14
|
-
public static final String COMMAND_SET_STORE = "seStore";
|
|
15
14
|
public static final String COMMAND_SET_APP_SECRET = "setAppSecret";
|
|
16
|
-
public static final String COMMAND_SET_DEFAULT_TRACKER = "setDefaultTracker";
|
|
17
15
|
|
|
18
|
-
public static final String
|
|
16
|
+
public static final String COMMAND_SET_USER_ID_LISTENER = "setUserIdListener";
|
|
19
17
|
public static final String COMMAND_SET_ATTRIBUTION_CHANGE_LISTENER = "setAttributionChangeListener";
|
|
20
|
-
public static final String
|
|
18
|
+
public static final String COMMAND_SET_DEEPLINK_RESPONSE_LISTENER = "setDeeplinkResponseListener";
|
|
19
|
+
public static final String COMMAND_SET_SHOULD_LAUNCH_DEEPLINK = "setShouldLaunchDeeplink";
|
|
20
|
+
public static final String COMMAND_SET_SESSION_NUMBER_LISTENER = "setSessionNumberListener";
|
|
21
|
+
public static final String COMMAND_SET_SESSION_ID_LISTENER = "setSessionIdListener";
|
|
22
|
+
public static final String COMMAND_SET_STORE = "setStore";
|
|
23
|
+
public static final String COMMAND_SET_DEFAULT_TRACKER = "setDefaultTracker";
|
|
24
|
+
public static final String COMMAND_SET_SIGNATURE = "setSignature";
|
|
21
25
|
public static final String COMMAND_TRACK_SIMPLE_EVENT = "trackSimpleEvent";
|
|
26
|
+
public static final String COMMAND_TRACK_SIMPLE_EVENT_BY_NAME = "trackSimpleEventByName";
|
|
22
27
|
public static final String COMMAND_TRACK_CUSTOM_EVENT = "trackCustomEvent";
|
|
23
|
-
public static final String
|
|
24
|
-
public static final String
|
|
25
|
-
public static final String
|
|
26
|
-
public static final String
|
|
27
|
-
public static final String
|
|
28
|
-
public static final String
|
|
29
|
-
public static final String
|
|
28
|
+
public static final String COMMAND_TRACK_CUSTOM_EVENT_BY_NAME = "trackCustomEventByName";
|
|
29
|
+
public static final String COMMAND_TRACK_REVENUE = "trackRevenue";
|
|
30
|
+
public static final String COMMAND_TRACK_REVENUE_BY_NAME = "trackRevenueByName";
|
|
31
|
+
public static final String COMMAND_SET_USER_ATTRIBUTES = "setUserAttributes";
|
|
32
|
+
public static final String COMMAND_SET_USER_CUSTOM_ID = "setUserCustomId";
|
|
33
|
+
public static final String COMMAND_DELETE_USER_CUSTOM_ID = "deleteUserCustomId";
|
|
34
|
+
public static final String COMMAND_SET_USER_FIRST_NAME = "setUserFirstName";
|
|
35
|
+
public static final String COMMAND_SET_USER_LAST_NAME = "setUserLastName";
|
|
36
|
+
public static final String COMMAND_SET_USER_PHONE_NUMBER = "setUserPhoneNumber";
|
|
37
|
+
public static final String COMMAND_SET_USER_HASHED_PHONEN_NUMBER = "setUserHashedPhoneNumber";
|
|
38
|
+
public static final String COMMAND_SET_USER_EMAIL = "setUserEmail";
|
|
39
|
+
public static final String COMMAND_SET_USER_HASHED_EMAIL = "setUserHashedEmail";
|
|
40
|
+
public static final String COMMAND_SET_USER_COUNTRY = "setUserCountry";
|
|
41
|
+
public static final String COMMAND_SET_USER_CITY = "setUserCity";
|
|
42
|
+
public static final String COMMAND_SET_USER_REGION = "setUserRegion";
|
|
43
|
+
public static final String COMMAND_SET_USER_LOCALITY = "setUserLocality";
|
|
44
|
+
public static final String COMMAND_SET_USER_GENDER = "setUserGender";
|
|
45
|
+
public static final String COMMAND_SET_USER_BIRTHDAY = "setUserBirthday";
|
|
46
|
+
public static final String COMMAND_SET_USER_CHANNEL_ENABLED = "setUserChannelEnabled";
|
|
47
|
+
public static final String COMMAND_SET_USER_CHANNEL_DISABLED = "setUserChannelDisabled";
|
|
48
|
+
public static final String COMMAND_LOADL_IN_APP_MESSAGES = "loadInAppMessages";
|
|
49
|
+
|
|
30
50
|
|
|
31
|
-
public static Map<String,
|
|
32
|
-
Map<String,
|
|
51
|
+
public static Map<String, Object> jsonObjectToObjectMap(JSONObject jsonObject) throws JSONException {
|
|
52
|
+
Map<String, Object> map = new HashMap<String, Object>(jsonObject.length());
|
|
33
53
|
@SuppressWarnings("unchecked")
|
|
34
54
|
Iterator<String> jsonObjectIterator = jsonObject.keys();
|
|
35
55
|
|
|
36
56
|
while (jsonObjectIterator.hasNext()) {
|
|
37
57
|
String key = jsonObjectIterator.next();
|
|
38
|
-
map.put(key, jsonObject.get(key)
|
|
58
|
+
map.put(key, jsonObject.get(key));
|
|
39
59
|
}
|
|
40
60
|
|
|
41
61
|
return map;
|
|
@@ -55,6 +75,9 @@ public class MetrixCordovaUtils {
|
|
|
55
75
|
if (AttributionData.getAcquisitionSource() != null) {
|
|
56
76
|
map.put("acquisitionSource", AttributionData.getAcquisitionSource());
|
|
57
77
|
}
|
|
78
|
+
if (AttributionData.getAcquisitionSubId() != null) {
|
|
79
|
+
map.put("acquisitionSubId", AttributionData.getAcquisitionSubId());
|
|
80
|
+
}
|
|
58
81
|
if (AttributionData.getAttributionStatus() != null) {
|
|
59
82
|
map.put("attributionStatus", AttributionData.getAttributionStatus().name());
|
|
60
83
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
package ir.metrix.cordova;
|
|
2
|
+
|
|
3
|
+
import java.lang.reflect.Method;
|
|
4
|
+
|
|
5
|
+
public class Reflection {
|
|
6
|
+
|
|
7
|
+
public static Object invokeStaticMethod(String className, String methodName) {
|
|
8
|
+
try {
|
|
9
|
+
Class<?> clazz = Class.forName(className);
|
|
10
|
+
Method method = clazz.getDeclaredMethod(methodName);
|
|
11
|
+
return method.invoke(null);
|
|
12
|
+
} catch (Exception e) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,7 +1,18 @@
|
|
|
1
|
+
def Properties gradleProperties = new Properties()
|
|
2
|
+
gradleProperties.load(rootProject.rootProject.file("gradle.properties").newDataInputStream())
|
|
3
|
+
|
|
4
|
+
project.ext {
|
|
5
|
+
notificationEnabled = gradleProperties.getProperty("metrix.notitifcation.enable", "false").toBoolean()
|
|
6
|
+
}
|
|
7
|
+
|
|
1
8
|
repositories {
|
|
2
9
|
mavenCentral()
|
|
3
10
|
}
|
|
4
11
|
|
|
5
12
|
dependencies {
|
|
6
|
-
implementation 'ir.metrix:metrix-cordova:
|
|
13
|
+
implementation 'ir.metrix.analytics:metrix-cordova:2.6.0'
|
|
14
|
+
implementation 'ir.metrix.attribution:metrix-cordova:2.6.0'
|
|
15
|
+
if (project.ext.notificationEnabled) {
|
|
16
|
+
api 'ir.metrix.notification:metrix-cordova:2.6.0'
|
|
17
|
+
}
|
|
7
18
|
}
|
package/src/ios/MetrixCordova.m
CHANGED
|
@@ -267,6 +267,7 @@ NSString* userIdCallbackId;
|
|
|
267
267
|
[self addValueOrEmpty:dictionary key:@"acquisitionAdSet" value:data.acquisitionAdSet];
|
|
268
268
|
[self addValueOrEmpty:dictionary key:@"acquisitionCampaign" value:data.acquisitionCampaign];
|
|
269
269
|
[self addValueOrEmpty:dictionary key:@"acquisitionSource" value:data.acquisitionSource];
|
|
270
|
+
[self addValueOrEmpty:dictionary key:@"acquisitionSubId" value:data.acquisitionSubId];
|
|
270
271
|
[self addValueOrEmpty:dictionary key:@"attributionStatus" value:data.attributionStatusRaw];
|
|
271
272
|
|
|
272
273
|
return dictionary;;
|
package/www/metrix.js
CHANGED
|
@@ -22,6 +22,25 @@ function callCordovaCallback(action, callback) {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
var Metrix = {
|
|
25
|
+
|
|
26
|
+
setSignature: function(signature) {
|
|
27
|
+
if (signature) {
|
|
28
|
+
callCordova('setSignature', signature);
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
setDefaultTracker: function(token) {
|
|
33
|
+
if (token) {
|
|
34
|
+
callCordova('setDefaultTracker', token);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
setStore: function(store) {
|
|
39
|
+
if (store) {
|
|
40
|
+
callCordova('setStore', store);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
|
|
25
44
|
newEvent: function(slug, attributes) {
|
|
26
45
|
if(attributes) {
|
|
27
46
|
callCordova('trackCustomEvent', slug, attributes);
|
|
@@ -30,11 +49,19 @@ var Metrix = {
|
|
|
30
49
|
}
|
|
31
50
|
},
|
|
32
51
|
|
|
33
|
-
|
|
34
|
-
|
|
52
|
+
newEventByName: function(name, attributes) {
|
|
53
|
+
if(attributes) {
|
|
54
|
+
callCordova('trackCustomEventByName', name, attributes);
|
|
55
|
+
} else {
|
|
56
|
+
callCordova('trackSimpleEventByName', name);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
setUserAttributes: function(attributes) {
|
|
61
|
+
callCordova('setUserAttributes', attributes);
|
|
35
62
|
},
|
|
36
63
|
|
|
37
|
-
newRevenue: function(slug, amount, currency
|
|
64
|
+
newRevenue: function(slug, amount, currency) {
|
|
38
65
|
var cr = null;
|
|
39
66
|
if (currency === 0) {
|
|
40
67
|
cr = "IRR";
|
|
@@ -45,11 +72,23 @@ var Metrix = {
|
|
|
45
72
|
} else {
|
|
46
73
|
cr = "IRR";
|
|
47
74
|
}
|
|
48
|
-
|
|
49
|
-
|
|
75
|
+
|
|
76
|
+
callCordova('trackRevenue', slug, amount, cr);
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
newRevenueByName: function(name, amount, currency) {
|
|
80
|
+
var cr = null;
|
|
81
|
+
if (currency === 0) {
|
|
82
|
+
cr = "IRR";
|
|
83
|
+
} else if (currency === 1) {
|
|
84
|
+
cr = "USD";
|
|
85
|
+
} else if (currency === 2) {
|
|
86
|
+
cr = "EUR";
|
|
50
87
|
} else {
|
|
51
|
-
|
|
52
|
-
}
|
|
88
|
+
cr = "IRR";
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
callCordova('trackRevenueByName', name, amount, cr);
|
|
53
92
|
},
|
|
54
93
|
|
|
55
94
|
setOnAttributionChangedListener: function(callback) {
|
|
@@ -77,9 +116,121 @@ var Metrix = {
|
|
|
77
116
|
},
|
|
78
117
|
|
|
79
118
|
// android only
|
|
80
|
-
|
|
119
|
+
setUserCustomId: function(id) {
|
|
81
120
|
if (token) {
|
|
82
|
-
callCordova('
|
|
121
|
+
callCordova('setUserCustomId', id);
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
// android only
|
|
126
|
+
deleteUserCustomId: function() {
|
|
127
|
+
if (token) {
|
|
128
|
+
callCordova('setUserCustomId');
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
// android only
|
|
133
|
+
setUserFirstName: function(firstName) {
|
|
134
|
+
if (token) {
|
|
135
|
+
callCordova('setUserFirstName', firstName);
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
// android only
|
|
140
|
+
setUserLastName: function(lastName) {
|
|
141
|
+
if (token) {
|
|
142
|
+
callCordova('setUserLastName', lastName);
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
// android only
|
|
147
|
+
setUserPhoneNumber: function(phoneNumber) {
|
|
148
|
+
if (token) {
|
|
149
|
+
callCordova('setUserPhoneNumber', phoneNumber);
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
// android only
|
|
154
|
+
setUserHashedPhoneNumber: function(hash) {
|
|
155
|
+
if (token) {
|
|
156
|
+
callCordova('setUserHashedPhoneNumber', hash);
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
|
|
160
|
+
// android only
|
|
161
|
+
setUserEmail: function(email) {
|
|
162
|
+
if (token) {
|
|
163
|
+
callCordova('setUserEmail', email);
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
|
|
167
|
+
// android only
|
|
168
|
+
setUserHashedEmail: function(hash) {
|
|
169
|
+
if (token) {
|
|
170
|
+
callCordova('setUserHashedEmail', hash);
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
|
|
174
|
+
// android only
|
|
175
|
+
setUserCountry: function(coutry) {
|
|
176
|
+
if (token) {
|
|
177
|
+
callCordova('setUserCountry', coutry);
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
|
|
181
|
+
// android only
|
|
182
|
+
setUserCity: function(city) {
|
|
183
|
+
if (token) {
|
|
184
|
+
callCordova('setUserCity', city);
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
// android only
|
|
189
|
+
setUserRegion: function(region) {
|
|
190
|
+
if (token) {
|
|
191
|
+
callCordova('setUserRegion', region);
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
|
|
195
|
+
// android only
|
|
196
|
+
setUserLocality: function(locality) {
|
|
197
|
+
if (token) {
|
|
198
|
+
callCordova('setUserLocality', locality);
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
|
|
202
|
+
// android only
|
|
203
|
+
setUserGender: function(gender) {
|
|
204
|
+
if (token) {
|
|
205
|
+
callCordova('setUserGender', gender);
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
|
|
209
|
+
// android only
|
|
210
|
+
setUserBirthday: function(birthday) {
|
|
211
|
+
if (token) {
|
|
212
|
+
callCordova('setUserBirthday', birthday);
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
|
|
216
|
+
// android only
|
|
217
|
+
setUserChannelEnabled: function(channel) {
|
|
218
|
+
if (token) {
|
|
219
|
+
callCordova('setUserChannelEnabled', channel);
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
|
|
223
|
+
// android only
|
|
224
|
+
setUserChannelDisabled: function(channel) {
|
|
225
|
+
if (token) {
|
|
226
|
+
callCordova('setUserChannelDisabled', channel);
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
|
|
230
|
+
// android only
|
|
231
|
+
loadInAppMessages: function() {
|
|
232
|
+
if (token) {
|
|
233
|
+
callCordova('loadInAppMessages');
|
|
83
234
|
}
|
|
84
235
|
},
|
|
85
236
|
|
|
@@ -102,20 +253,6 @@ var Metrix = {
|
|
|
102
253
|
}
|
|
103
254
|
},
|
|
104
255
|
|
|
105
|
-
// iOS only
|
|
106
|
-
setDefaultTracker: function(token) {
|
|
107
|
-
if (token) {
|
|
108
|
-
callCordova('setDefaultTracker', token);
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
|
|
112
|
-
// iOS only
|
|
113
|
-
setStore: function(store) {
|
|
114
|
-
if (store) {
|
|
115
|
-
callCordova('setStore', store);
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
|
|
119
256
|
// iOS only
|
|
120
257
|
setAppSecret: function(id, info1, info2, info3, info4) {
|
|
121
258
|
if (id && info1 && info2 && info3 && info4) {
|