@convivainc/conviva-react-native-appanalytics 0.1.0 → 0.1.2
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.md +8 -0
- package/README.md +5 -10
- package/RNConvivaAppAnalytics.podspec +24 -0
- package/android/build.gradle +55 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +6 -0
- package/android/gradle.properties +2 -0
- package/android/gradlew +172 -0
- package/android/gradlew.bat +84 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/com/conviva/react/apptracker/RNConvivaTrackerModule.java +804 -0
- package/android/src/main/java/com/conviva/react/apptracker/RNConvivaTrackerPackage.java +29 -0
- package/android/src/main/java/com/conviva/react/apptracker/util/ConfigUtil.java +346 -0
- package/android/src/main/java/com/conviva/react/apptracker/util/EventUtil.java +339 -0
- package/android/src/main/java/com/conviva/react/apptracker/util/TrackerVersion.java +9 -0
- package/ios/RNConvivaAppAnalytics.h +34 -0
- package/ios/RNConvivaAppAnalytics.m +1051 -0
- package/ios/RNConvivaAppAnalytics.xcodeproj/project.pbxproj +325 -0
- package/ios/RNConvivaAppAnalytics.xcodeproj/xcshareddata/xcschemes/RNSnowplowTracker.xcscheme +76 -0
- package/ios/Util/NSDictionary+RNCAT_TypeMethods.h +33 -0
- package/ios/Util/NSDictionary+RNCAT_TypeMethods.m +40 -0
- package/ios/Util/RNConfigUtils.h +46 -0
- package/ios/Util/RNConfigUtils.m +217 -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 +1 -1
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
package com.conviva.react.apptracker.util;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
import com.conviva.apptracker.event.ConsentGranted;
|
|
6
|
+
import com.conviva.apptracker.event.ConsentWithdrawn;
|
|
7
|
+
import com.conviva.apptracker.event.DeepLinkReceived;
|
|
8
|
+
import com.conviva.apptracker.event.EcommerceTransaction;
|
|
9
|
+
import com.conviva.apptracker.event.EcommerceTransactionItem;
|
|
10
|
+
import com.conviva.apptracker.event.MessageNotification;
|
|
11
|
+
import com.conviva.apptracker.event.MessageNotificationAttachment;
|
|
12
|
+
import com.conviva.apptracker.event.MessageNotificationTrigger;
|
|
13
|
+
import com.conviva.apptracker.event.PageView;
|
|
14
|
+
import com.conviva.apptracker.event.ScreenView;
|
|
15
|
+
import com.conviva.apptracker.event.Structured;
|
|
16
|
+
import com.conviva.apptracker.event.Timing;
|
|
17
|
+
import com.conviva.apptracker.payload.SelfDescribingJson;
|
|
18
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
19
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
20
|
+
|
|
21
|
+
import java.util.ArrayList;
|
|
22
|
+
import java.util.List;
|
|
23
|
+
import java.util.Objects;
|
|
24
|
+
import java.util.UUID;
|
|
25
|
+
|
|
26
|
+
public class EventUtil {
|
|
27
|
+
|
|
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
|
+
}
|
|
34
|
+
|
|
35
|
+
public static List<SelfDescribingJson> createContexts(ReadableArray contexts) {
|
|
36
|
+
List<SelfDescribingJson> nativeContexts = new ArrayList<>();
|
|
37
|
+
for (int i = 0; i < contexts.size(); i++) {
|
|
38
|
+
SelfDescribingJson json = createSelfDescribingJson(contexts.getMap(i));
|
|
39
|
+
nativeContexts.add(json);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return nativeContexts;
|
|
43
|
+
}
|
|
44
|
+
|
|
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
|
+
);
|
|
50
|
+
|
|
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"));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return event;
|
|
63
|
+
}
|
|
64
|
+
|
|
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
|
+
);
|
|
72
|
+
|
|
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"));
|
|
84
|
+
}
|
|
85
|
+
if (argmap.hasKey("transitionType")) {
|
|
86
|
+
event.transitionType(argmap.getString("transitionType"));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return event;
|
|
90
|
+
}
|
|
91
|
+
|
|
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
|
+
}
|
|
106
|
+
|
|
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
|
+
);
|
|
113
|
+
|
|
114
|
+
if (argmap.hasKey("label")) {
|
|
115
|
+
event.label(argmap.getString("label"));
|
|
116
|
+
}
|
|
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"));
|
|
130
|
+
}
|
|
131
|
+
if (argmap.hasKey("documentDescription")) {
|
|
132
|
+
event.documentDescription(argmap.getString("documentDescription"));
|
|
133
|
+
}
|
|
134
|
+
|
|
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"));
|
|
147
|
+
}
|
|
148
|
+
if (argmap.hasKey("documentDescription")) {
|
|
149
|
+
event.documentDescription(argmap.getString("documentDescription"));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return event;
|
|
153
|
+
}
|
|
154
|
+
|
|
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
|
+
);
|
|
164
|
+
|
|
165
|
+
if (argItem.hasKey("name")) {
|
|
166
|
+
item.name(argItem.getString("name"));
|
|
167
|
+
}
|
|
168
|
+
if (argItem.hasKey("category")) {
|
|
169
|
+
item.category(argItem.getString("category"));
|
|
170
|
+
}
|
|
171
|
+
if (argItem.hasKey("currency")) {
|
|
172
|
+
item.currency(argItem.getString("currency"));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
ecomItems.add(item);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return ecomItems;
|
|
179
|
+
}
|
|
180
|
+
|
|
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
|
+
);
|
|
191
|
+
|
|
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));
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (argmap.hasKey("bodyLocArgs")) {
|
|
289
|
+
ReadableArray bodyLocArgs = argmap.getArray("bodyLocArgs");
|
|
290
|
+
if (bodyLocArgs != null) {
|
|
291
|
+
event.bodyLocArgs(createStrings(bodyLocArgs));
|
|
292
|
+
}
|
|
293
|
+
}
|
|
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;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//
|
|
2
|
+
// RNSnowplowTracker.h
|
|
3
|
+
//
|
|
4
|
+
// Copyright (c) 2021-2023 Snowplow Analytics Ltd. All rights reserved.
|
|
5
|
+
//
|
|
6
|
+
// This program is licensed to you under the Apache License Version 2.0,
|
|
7
|
+
// and you may not use this file except in compliance with the Apache License
|
|
8
|
+
// Version 2.0. You may obtain a copy of the Apache License Version 2.0 at
|
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0.
|
|
10
|
+
//
|
|
11
|
+
// Unless required by applicable law or agreed to in writing,
|
|
12
|
+
// software distributed under the Apache License Version 2.0 is distributed on
|
|
13
|
+
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
|
14
|
+
// express or implied. See the Apache License Version 2.0 for the specific
|
|
15
|
+
// language governing permissions and limitations there under.
|
|
16
|
+
//
|
|
17
|
+
// Copyright: Copyright (c) 2023 Snowplow Analytics Ltd
|
|
18
|
+
// License: Apache License Version 2.0
|
|
19
|
+
//
|
|
20
|
+
|
|
21
|
+
#if __has_include("RCTBridgeModule.h")
|
|
22
|
+
#import "RCTBridgeModule.h"
|
|
23
|
+
#else
|
|
24
|
+
#import <React/RCTBridgeModule.h>
|
|
25
|
+
#endif
|
|
26
|
+
|
|
27
|
+
#import <Foundation/Foundation.h>
|
|
28
|
+
@protocol CATTrackerController;
|
|
29
|
+
|
|
30
|
+
@interface RNConvivaTracker : NSObject <RCTBridgeModule>
|
|
31
|
+
|
|
32
|
+
@property (nonatomic, strong) id<CATTrackerController> tracker;
|
|
33
|
+
|
|
34
|
+
@end
|