@snowplow/react-native-tracker 0.2.0 → 1.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.
- package/CHANGELOG +24 -0
- package/LICENSE +2 -2
- package/README.md +130 -230
- package/RNSnowplowTracker.podspec +24 -0
- package/android/build.gradle +8 -9
- package/android/gradle/wrapper/gradle-wrapper.properties +1 -1
- package/android/src/main/java/com/snowplowanalytics/react/tracker/RNSnowplowTrackerModule.java +643 -121
- package/android/src/main/java/com/snowplowanalytics/react/tracker/RNSnowplowTrackerPackage.java +0 -1
- package/android/src/main/java/com/snowplowanalytics/react/util/ConfigUtil.java +345 -0
- package/android/src/main/java/com/snowplowanalytics/react/util/EventUtil.java +291 -68
- package/android/src/main/java/com/snowplowanalytics/react/util/TrackerVersion.java +7 -0
- package/dist/index.d.ts +601 -116
- package/dist/index.js +1479 -107
- package/dist/index.js.map +1 -0
- package/ios/RNSnowplowTracker.h +19 -1
- package/ios/RNSnowplowTracker.m +831 -159
- package/ios/Util/RNConfigUtils.h +44 -0
- package/ios/Util/RNConfigUtils.m +207 -0
- package/ios/Util/RNTrackerVersion.h +27 -0
- package/ios/Util/RNTrackerVersion.m +27 -0
- package/ios/Util/RNUtilities.h +32 -0
- package/ios/Util/RNUtilities.m +68 -0
- package/package.json +44 -14
- package/ios/Podfile +0 -22
- package/ios/Podfile.lock +0 -37
- package/ios/RCTConvert+Snowplow.h +0 -17
- package/ios/RCTConvert+Snowplow.m +0 -57
- package/ios/RNSnowplowTracker.podspec +0 -22
- package/src/api.ts +0 -168
- package/src/index.ts +0 -71
- package/src/types.ts +0 -325
- package/src/utils.ts +0 -47
|
@@ -1,116 +1,339 @@
|
|
|
1
1
|
package com.snowplowanalytics.react.util;
|
|
2
2
|
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
3
5
|
import com.facebook.react.bridge.ReadableMap;
|
|
4
6
|
import com.facebook.react.bridge.ReadableArray;
|
|
5
|
-
import com.snowplowanalytics.snowplow.
|
|
6
|
-
import com.snowplowanalytics.snowplow.
|
|
7
|
-
import com.snowplowanalytics.snowplow.
|
|
8
|
-
import com.snowplowanalytics.snowplow.
|
|
9
|
-
import com.snowplowanalytics.snowplow.
|
|
7
|
+
import com.snowplowanalytics.snowplow.event.DeepLinkReceived;
|
|
8
|
+
import com.snowplowanalytics.snowplow.event.MessageNotification;
|
|
9
|
+
import com.snowplowanalytics.snowplow.event.MessageNotificationAttachment;
|
|
10
|
+
import com.snowplowanalytics.snowplow.event.MessageNotificationTrigger;
|
|
11
|
+
import com.snowplowanalytics.snowplow.event.Structured;
|
|
12
|
+
import com.snowplowanalytics.snowplow.payload.SelfDescribingJson;
|
|
13
|
+
import com.snowplowanalytics.snowplow.event.ScreenView;
|
|
14
|
+
import com.snowplowanalytics.snowplow.event.PageView;
|
|
15
|
+
import com.snowplowanalytics.snowplow.event.Timing;
|
|
16
|
+
import com.snowplowanalytics.snowplow.event.ConsentGranted;
|
|
17
|
+
import com.snowplowanalytics.snowplow.event.ConsentWithdrawn;
|
|
18
|
+
import com.snowplowanalytics.snowplow.event.EcommerceTransactionItem;
|
|
19
|
+
import com.snowplowanalytics.snowplow.event.EcommerceTransaction;
|
|
10
20
|
|
|
11
21
|
import java.util.ArrayList;
|
|
12
22
|
import java.util.List;
|
|
23
|
+
import java.util.Objects;
|
|
24
|
+
import java.util.UUID;
|
|
13
25
|
|
|
14
26
|
public class EventUtil {
|
|
15
27
|
|
|
16
|
-
public static
|
|
28
|
+
public static SelfDescribingJson createSelfDescribingJson(ReadableMap json) {
|
|
29
|
+
String schema = json.getString("schema");
|
|
30
|
+
ReadableMap dataMap = json.getMap("data");
|
|
31
|
+
|
|
32
|
+
return new SelfDescribingJson(schema, dataMap.toHashMap());
|
|
33
|
+
}
|
|
17
34
|
|
|
35
|
+
public static List<SelfDescribingJson> createContexts(ReadableArray contexts) {
|
|
18
36
|
List<SelfDescribingJson> nativeContexts = new ArrayList<>();
|
|
19
37
|
for (int i = 0; i < contexts.size(); i++) {
|
|
20
|
-
SelfDescribingJson json =
|
|
38
|
+
SelfDescribingJson json = createSelfDescribingJson(contexts.getMap(i));
|
|
21
39
|
nativeContexts.add(json);
|
|
22
40
|
}
|
|
41
|
+
|
|
23
42
|
return nativeContexts;
|
|
24
43
|
}
|
|
25
44
|
|
|
26
|
-
public static
|
|
45
|
+
public static Structured createStructuredEvent(ReadableMap argmap) {
|
|
46
|
+
Structured event = new Structured(
|
|
47
|
+
Objects.requireNonNull(argmap.getString("category"), "category can't be null"),
|
|
48
|
+
Objects.requireNonNull(argmap.getString("action"), "action can't be null")
|
|
49
|
+
);
|
|
27
50
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
51
|
+
if (argmap.hasKey("label")) {
|
|
52
|
+
event.label(argmap.getString("label"));
|
|
53
|
+
}
|
|
54
|
+
if (argmap.hasKey("property")) {
|
|
55
|
+
event.property(argmap.getString("property"));
|
|
56
|
+
}
|
|
57
|
+
// React Native forces primitive double type - so null "value" parameter is handled by not setting at all
|
|
58
|
+
if (argmap.hasKey("value") && !argmap.isNull("value")) {
|
|
59
|
+
event.value(argmap.getDouble("value"));
|
|
34
60
|
}
|
|
35
|
-
|
|
61
|
+
|
|
62
|
+
return event;
|
|
36
63
|
}
|
|
37
64
|
|
|
38
|
-
public static
|
|
65
|
+
public static ScreenView createScreenViewEvent(ReadableMap argmap) {
|
|
66
|
+
@NonNull String name = Objects.requireNonNull(argmap.getString("name"), "name can't be null");
|
|
67
|
+
ScreenView event = (
|
|
68
|
+
argmap.hasKey("id") ?
|
|
69
|
+
new ScreenView(name, UUID.fromString(argmap.getString("id"))) :
|
|
70
|
+
new ScreenView(name)
|
|
71
|
+
);
|
|
39
72
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
73
|
+
if (argmap.hasKey("type")) {
|
|
74
|
+
event.type(argmap.getString("type"));
|
|
75
|
+
}
|
|
76
|
+
if (argmap.hasKey("previousName")) {
|
|
77
|
+
event.previousName(argmap.getString("previousName"));
|
|
78
|
+
}
|
|
79
|
+
if (argmap.hasKey("previousType")) {
|
|
80
|
+
event.previousType(argmap.getString("previousType"));
|
|
81
|
+
}
|
|
82
|
+
if (argmap.hasKey("previousId")) {
|
|
83
|
+
event.previousId(argmap.getString("previousId"));
|
|
47
84
|
}
|
|
48
|
-
|
|
85
|
+
if (argmap.hasKey("transitionType")) {
|
|
86
|
+
event.transitionType(argmap.getString("transitionType"));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return event;
|
|
49
90
|
}
|
|
50
91
|
|
|
51
|
-
public static
|
|
92
|
+
public static PageView createPageViewEvent(ReadableMap argmap) {
|
|
93
|
+
PageView event = new PageView(
|
|
94
|
+
Objects.requireNonNull(argmap.getString("pageUrl"), "pageUrl can't be null")
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
if (argmap.hasKey("pageTitle")) {
|
|
98
|
+
event.pageTitle(argmap.getString("pageTitle"));
|
|
99
|
+
}
|
|
100
|
+
if (argmap.hasKey("referrer")) {
|
|
101
|
+
event.referrer(argmap.getString("referrer"));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return event;
|
|
105
|
+
}
|
|
52
106
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
107
|
+
public static Timing createTimingEvent(ReadableMap argmap) {
|
|
108
|
+
Timing event = new Timing(
|
|
109
|
+
Objects.requireNonNull(argmap.getString("category"), "category can't be null"),
|
|
110
|
+
Objects.requireNonNull(argmap.getString("variable"), "variable can't be null"),
|
|
111
|
+
argmap.getInt("timing")
|
|
112
|
+
);
|
|
57
113
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
eventBuilder.label(details.getString("label"));
|
|
114
|
+
if (argmap.hasKey("label")) {
|
|
115
|
+
event.label(argmap.getString("label"));
|
|
61
116
|
}
|
|
62
|
-
|
|
63
|
-
|
|
117
|
+
|
|
118
|
+
return event;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
public static ConsentGranted createConsentGrantedEvent(ReadableMap argmap) {
|
|
122
|
+
ConsentGranted event = new ConsentGranted(
|
|
123
|
+
Objects.requireNonNull(argmap.getString("expiry"), "expiry can't be null"),
|
|
124
|
+
Objects.requireNonNull(argmap.getString("documentId"), "documentId can't be null"),
|
|
125
|
+
Objects.requireNonNull(argmap.getString("version"), "version can't be null")
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
if (argmap.hasKey("name")) {
|
|
129
|
+
event.documentName(argmap.getString("name"));
|
|
64
130
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
eventBuilder.value(details.getDouble("value"));
|
|
131
|
+
if (argmap.hasKey("documentDescription")) {
|
|
132
|
+
event.documentDescription(argmap.getString("documentDescription"));
|
|
68
133
|
}
|
|
69
134
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
135
|
+
return event;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
public static ConsentWithdrawn createConsentWithdrawnEvent(ReadableMap argmap) {
|
|
139
|
+
ConsentWithdrawn event = new ConsentWithdrawn(
|
|
140
|
+
argmap.getBoolean("all"),
|
|
141
|
+
Objects.requireNonNull(argmap.getString("documentId"), "documentId can't be null"),
|
|
142
|
+
Objects.requireNonNull(argmap.getString("version"), "version can't be null")
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
if (argmap.hasKey("name")) {
|
|
146
|
+
event.documentName(argmap.getString("name"));
|
|
73
147
|
}
|
|
74
|
-
|
|
148
|
+
if (argmap.hasKey("documentDescription")) {
|
|
149
|
+
event.documentDescription(argmap.getString("documentDescription"));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return event;
|
|
75
153
|
}
|
|
76
154
|
|
|
77
|
-
public static
|
|
155
|
+
public static List<EcommerceTransactionItem> createEcommerceTransactionItems(ReadableArray items) {
|
|
156
|
+
List<EcommerceTransactionItem> ecomItems = new ArrayList<>();
|
|
157
|
+
for (int i = 0; i < items.size(); i++) {
|
|
158
|
+
ReadableMap argItem = items.getMap(i);
|
|
159
|
+
EcommerceTransactionItem item = new EcommerceTransactionItem(
|
|
160
|
+
Objects.requireNonNull(argItem.getString("sku"), "sku can't be null"),
|
|
161
|
+
argItem.getDouble("price"),
|
|
162
|
+
argItem.getInt("quantity")
|
|
163
|
+
);
|
|
78
164
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
eventBuilder.type(details.getString("screenType"));
|
|
165
|
+
if (argItem.hasKey("name")) {
|
|
166
|
+
item.name(argItem.getString("name"));
|
|
167
|
+
}
|
|
168
|
+
if (argItem.hasKey("category")) {
|
|
169
|
+
item.category(argItem.getString("category"));
|
|
85
170
|
}
|
|
86
|
-
if (
|
|
87
|
-
|
|
171
|
+
if (argItem.hasKey("currency")) {
|
|
172
|
+
item.currency(argItem.getString("currency"));
|
|
88
173
|
}
|
|
89
174
|
|
|
90
|
-
|
|
91
|
-
if (nativeContexts != null) {
|
|
92
|
-
eventBuilder.customContext(nativeContexts);
|
|
175
|
+
ecomItems.add(item);
|
|
93
176
|
}
|
|
94
|
-
|
|
177
|
+
|
|
178
|
+
return ecomItems;
|
|
95
179
|
}
|
|
96
180
|
|
|
97
|
-
public static
|
|
181
|
+
public static EcommerceTransaction createEcommerceTransactionEvent(ReadableMap argmap) {
|
|
182
|
+
List<EcommerceTransactionItem> ecomItems = createEcommerceTransactionItems(
|
|
183
|
+
Objects.requireNonNull(argmap.getArray("items"), "items can't be null")
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
EcommerceTransaction event = new EcommerceTransaction(
|
|
187
|
+
Objects.requireNonNull(argmap.getString("orderId"), "orderId can't be null"),
|
|
188
|
+
argmap.getDouble("totalValue"),
|
|
189
|
+
ecomItems
|
|
190
|
+
);
|
|
98
191
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
192
|
+
if (argmap.hasKey("affiliation")) {
|
|
193
|
+
event.affiliation(argmap.getString("affiliation"));
|
|
194
|
+
}
|
|
195
|
+
if (argmap.hasKey("taxValue")) {
|
|
196
|
+
event.taxValue(argmap.getDouble("taxValue"));
|
|
197
|
+
}
|
|
198
|
+
if (argmap.hasKey("shipping")) {
|
|
199
|
+
event.shipping(argmap.getDouble("shipping"));
|
|
200
|
+
}
|
|
201
|
+
if (argmap.hasKey("city")) {
|
|
202
|
+
event.city(argmap.getString("city"));
|
|
203
|
+
}
|
|
204
|
+
if (argmap.hasKey("state")) {
|
|
205
|
+
event.state(argmap.getString("state"));
|
|
206
|
+
}
|
|
207
|
+
if (argmap.hasKey("country")) {
|
|
208
|
+
event.country(argmap.getString("country"));
|
|
209
|
+
}
|
|
210
|
+
if (argmap.hasKey("currency")) {
|
|
211
|
+
event.currency(argmap.getString("currency"));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return event;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
public static DeepLinkReceived createDeepLinkReceivedEvent(ReadableMap argmap) {
|
|
218
|
+
DeepLinkReceived event = new DeepLinkReceived(
|
|
219
|
+
Objects.requireNonNull(argmap.getString("url"), "url can't be null")
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
if (argmap.hasKey("referrer")) {
|
|
223
|
+
event.referrer(argmap.getString("referrer"));
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return event;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
public static List<MessageNotificationAttachment> createMessageNotificationAttachments(ReadableArray items) {
|
|
230
|
+
List<MessageNotificationAttachment> attachments = new ArrayList<>();
|
|
231
|
+
for (int i = 0; i < items.size(); i++) {
|
|
232
|
+
ReadableMap argItem = items.getMap(i);
|
|
233
|
+
MessageNotificationAttachment attachment = new MessageNotificationAttachment(
|
|
234
|
+
Objects.requireNonNull(argItem.getString("identifier"), "identifier can't be null"),
|
|
235
|
+
Objects.requireNonNull(argItem.getString("type"), "type can't be null"),
|
|
236
|
+
Objects.requireNonNull(argItem.getString("url"), "url can't be null")
|
|
237
|
+
);
|
|
238
|
+
attachments.add(attachment);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return attachments;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
public static List<String> createStrings(ReadableArray items) {
|
|
245
|
+
List<String> results = new ArrayList<>();
|
|
246
|
+
for (int i = 0; i < items.size(); i++) {
|
|
247
|
+
results.add(items.getString(i));
|
|
248
|
+
}
|
|
249
|
+
return results;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
public static MessageNotification createMessageNotificationEvent(ReadableMap argmap) {
|
|
253
|
+
|
|
254
|
+
MessageNotificationTrigger trigger;
|
|
255
|
+
switch (Objects.requireNonNull(argmap.getString("trigger"), "trigger can't be null")) {
|
|
256
|
+
case "push":
|
|
257
|
+
trigger = MessageNotificationTrigger.push;
|
|
258
|
+
break;
|
|
259
|
+
case "location":
|
|
260
|
+
trigger = MessageNotificationTrigger.location;
|
|
261
|
+
break;
|
|
262
|
+
case "calendar":
|
|
263
|
+
trigger = MessageNotificationTrigger.calendar;
|
|
264
|
+
break;
|
|
265
|
+
case "timeInterval":
|
|
266
|
+
trigger = MessageNotificationTrigger.timeInterval;
|
|
267
|
+
break;
|
|
268
|
+
default:
|
|
269
|
+
trigger = MessageNotificationTrigger.other;
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
MessageNotification event = new MessageNotification(
|
|
274
|
+
Objects.requireNonNull(argmap.getString("title"), "title can't be null"),
|
|
275
|
+
Objects.requireNonNull(argmap.getString("body"), "body can't be null"),
|
|
276
|
+
trigger
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
if (argmap.hasKey("action")) {
|
|
280
|
+
event.action(argmap.getString("action"));
|
|
281
|
+
}
|
|
282
|
+
if (argmap.hasKey("attachments")) {
|
|
283
|
+
ReadableArray attachments = argmap.getArray("attachments");
|
|
284
|
+
if (attachments != null) {
|
|
285
|
+
event.attachments(createMessageNotificationAttachments(attachments));
|
|
105
286
|
}
|
|
106
|
-
|
|
107
|
-
|
|
287
|
+
}
|
|
288
|
+
if (argmap.hasKey("bodyLocArgs")) {
|
|
289
|
+
ReadableArray bodyLocArgs = argmap.getArray("bodyLocArgs");
|
|
290
|
+
if (bodyLocArgs != null) {
|
|
291
|
+
event.bodyLocArgs(createStrings(bodyLocArgs));
|
|
108
292
|
}
|
|
109
|
-
|
|
110
|
-
List<SelfDescribingJson> nativeContexts = EventUtil.getContexts(contexts);
|
|
111
|
-
if (nativeContexts != null) {
|
|
112
|
-
eventBuilder.customContext(nativeContexts);
|
|
113
293
|
}
|
|
114
|
-
|
|
294
|
+
if (argmap.hasKey("bodyLocKey")) {
|
|
295
|
+
event.bodyLocKey(argmap.getString("bodyLocKey"));
|
|
296
|
+
}
|
|
297
|
+
if (argmap.hasKey("category")) {
|
|
298
|
+
event.category(argmap.getString("category"));
|
|
299
|
+
}
|
|
300
|
+
if (argmap.hasKey("contentAvailable")) {
|
|
301
|
+
event.contentAvailable(argmap.getBoolean("contentAvailable"));
|
|
302
|
+
}
|
|
303
|
+
if (argmap.hasKey("group")) {
|
|
304
|
+
event.group(argmap.getString("group"));
|
|
305
|
+
}
|
|
306
|
+
if (argmap.hasKey("icon")) {
|
|
307
|
+
event.icon(argmap.getString("icon"));
|
|
308
|
+
}
|
|
309
|
+
if (argmap.hasKey("notificationCount")) {
|
|
310
|
+
event.notificationCount(argmap.getInt("notificationCount"));
|
|
311
|
+
}
|
|
312
|
+
if (argmap.hasKey("notificationTimestamp")) {
|
|
313
|
+
event.notificationTimestamp(argmap.getString("notificationTimestamp"));
|
|
314
|
+
}
|
|
315
|
+
if (argmap.hasKey("sound")) {
|
|
316
|
+
event.sound(argmap.getString("sound"));
|
|
317
|
+
}
|
|
318
|
+
if (argmap.hasKey("subtitle")) {
|
|
319
|
+
event.subtitle(argmap.getString("subtitle"));
|
|
320
|
+
}
|
|
321
|
+
if (argmap.hasKey("tag")) {
|
|
322
|
+
event.tag(argmap.getString("tag"));
|
|
323
|
+
}
|
|
324
|
+
if (argmap.hasKey("threadIdentifier")) {
|
|
325
|
+
event.threadIdentifier(argmap.getString("threadIdentifier"));
|
|
326
|
+
}
|
|
327
|
+
if (argmap.hasKey("titleLocArgs")) {
|
|
328
|
+
ReadableArray titleLocArgs = argmap.getArray("titleLocArgs");
|
|
329
|
+
if (titleLocArgs != null) {
|
|
330
|
+
event.titleLocArgs(createStrings(titleLocArgs));
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
if (argmap.hasKey("titleLocKey")) {
|
|
334
|
+
event.titleLocKey(argmap.getString("titleLocKey"));
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
return event;
|
|
115
338
|
}
|
|
116
339
|
}
|