@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
package/ios/RNSnowplowTracker.m
CHANGED
|
@@ -1,228 +1,900 @@
|
|
|
1
|
+
//
|
|
2
|
+
// RNSnowplowTracker.m
|
|
3
|
+
//
|
|
4
|
+
// Copyright (c) 2020-2022 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) 2022 Snowplow Analytics Ltd
|
|
18
|
+
// License: Apache License Version 2.0
|
|
19
|
+
//
|
|
20
|
+
|
|
1
21
|
#import "RNSnowplowTracker.h"
|
|
2
|
-
#import
|
|
3
|
-
#import
|
|
4
|
-
|
|
22
|
+
#import "RNConfigUtils.h"
|
|
23
|
+
#import "RNUtilities.h"
|
|
24
|
+
|
|
25
|
+
#import <SnowplowTracker/SPSnowplow.h>
|
|
26
|
+
#import <SnowplowTracker/NSDictionary+SP_TypeMethods.h>
|
|
27
|
+
#import <SnowplowTracker/SPUtilities.h>
|
|
28
|
+
#import <SnowplowTracker/SPNetworkConfiguration.h>
|
|
29
|
+
#import <SnowplowTracker/SPNetworkConnection.h>
|
|
30
|
+
#import <SnowplowTracker/SPTrackerConfiguration.h>
|
|
31
|
+
#import <SnowplowTracker/SPSessionConfiguration.h>
|
|
32
|
+
#import <SnowplowTracker/SPEmitterConfiguration.h>
|
|
33
|
+
#import <SnowplowTracker/SPSubjectConfiguration.h>
|
|
34
|
+
#import <SnowplowTracker/SPGDPRConfiguration.h>
|
|
35
|
+
#import <SnowplowTracker/SPGlobalContextsConfiguration.h>
|
|
36
|
+
#import <SnowplowTracker/SPGlobalContext.h>
|
|
5
37
|
#import <SnowplowTracker/SPSelfDescribingJson.h>
|
|
6
|
-
#import <SnowplowTracker/
|
|
38
|
+
#import <SnowplowTracker/SPSelfDescribing.h>
|
|
39
|
+
#import <SnowplowTracker/SPScreenView.h>
|
|
40
|
+
#import <SnowplowTracker/SPPageView.h>
|
|
41
|
+
#import <SnowplowTracker/SPTiming.h>
|
|
42
|
+
#import <SnowplowTracker/SPConsentGranted.h>
|
|
43
|
+
#import <SnowplowTracker/SPConsentWithdrawn.h>
|
|
44
|
+
#import <SnowplowTracker/SPStructured.h>
|
|
45
|
+
#import <SnowplowTracker/SPEcommerceItem.h>
|
|
46
|
+
#import <SnowplowTracker/SPEcommerce.h>
|
|
47
|
+
#import <SnowplowTracker/SPDeepLinkReceived.h>
|
|
48
|
+
#import <SnowplowTracker/SPMessageNotification.h>
|
|
7
49
|
|
|
8
|
-
@implementation RNSnowplowTracker
|
|
9
50
|
|
|
10
|
-
|
|
11
|
-
{
|
|
12
|
-
return dispatch_get_main_queue();
|
|
13
|
-
}
|
|
51
|
+
@implementation RNSnowplowTracker
|
|
14
52
|
|
|
15
53
|
RCT_EXPORT_MODULE()
|
|
16
54
|
|
|
17
|
-
RCT_EXPORT_METHOD(
|
|
18
|
-
(NSDictionary *)
|
|
55
|
+
RCT_EXPORT_METHOD(createTracker:
|
|
56
|
+
(NSDictionary *)argmap
|
|
19
57
|
resolver:(RCTPromiseResolveBlock)resolve
|
|
20
58
|
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
21
59
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
60
|
+
NSString *trackerNs = [argmap objectForKey:@"namespace"];
|
|
61
|
+
NSDictionary *networkConfig =[argmap objectForKey:@"networkConfig"];
|
|
62
|
+
|
|
63
|
+
// NetworkConfiguration
|
|
64
|
+
NSString *method = [networkConfig sp_stringForKey:@"method" defaultValue:nil];
|
|
65
|
+
SPHttpMethod httpMethod = [@"get" isEqualToString:method] ? SPHttpMethodGet : SPHttpMethodPost;
|
|
66
|
+
SPNetworkConfiguration *networkConfiguration = [[SPNetworkConfiguration alloc] initWithEndpoint:networkConfig[@"endpoint"] method:httpMethod];
|
|
67
|
+
|
|
68
|
+
// Configurations
|
|
69
|
+
NSMutableArray *controllers = [NSMutableArray array];
|
|
70
|
+
|
|
71
|
+
// TrackerConfiguration
|
|
72
|
+
NSObject *trackerArg = [argmap objectForKey:@"trackerConfig"];
|
|
73
|
+
if (trackerArg !=nil && [trackerArg isKindOfClass:NSDictionary.class]) {
|
|
74
|
+
SPTrackerConfiguration *trackerConfiguration = [RNConfigUtils mkTrackerConfig:(NSDictionary *)trackerArg];
|
|
75
|
+
[controllers addObject:trackerConfiguration];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// SessionConfiguration
|
|
79
|
+
NSObject *sessionArg = [argmap objectForKey:@"sessionConfig"];
|
|
80
|
+
if (sessionArg !=nil && [sessionArg isKindOfClass:NSDictionary.class]) {
|
|
81
|
+
SPSessionConfiguration *sessionConfiguration = [RNConfigUtils mkSessionConfig:(NSDictionary *)sessionArg];
|
|
82
|
+
[controllers addObject:sessionConfiguration];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// EmitterConfiguration
|
|
86
|
+
NSObject *emitterArg = [argmap objectForKey:@"emitterConfig"];
|
|
87
|
+
if (emitterArg !=nil && [emitterArg isKindOfClass:NSDictionary.class]) {
|
|
88
|
+
SPEmitterConfiguration *emitterConfiguration = [RNConfigUtils mkEmitterConfig:(NSDictionary *)emitterArg];
|
|
89
|
+
[controllers addObject:emitterConfiguration];
|
|
90
|
+
}
|
|
38
91
|
|
|
39
|
-
|
|
40
|
-
|
|
92
|
+
// SubjectConfiguration
|
|
93
|
+
NSObject *subjectArg = [argmap objectForKey:@"subjectConfig"];
|
|
94
|
+
if (subjectArg != nil && [subjectArg isKindOfClass:NSDictionary.class]) {
|
|
95
|
+
SPSubjectConfiguration *subjectConfiguration = [RNConfigUtils mkSubjectConfig:(NSDictionary *)subjectArg];
|
|
96
|
+
[controllers addObject:subjectConfiguration];
|
|
41
97
|
}
|
|
42
98
|
|
|
43
|
-
|
|
99
|
+
// GdprConfiguration
|
|
100
|
+
NSObject *gdprArg = [argmap objectForKey:@"gdprConfig"];
|
|
101
|
+
if (gdprArg != nil && [gdprArg isKindOfClass:NSDictionary.class]) {
|
|
102
|
+
SPGDPRConfiguration *gdprConfiguration = [RNConfigUtils mkGdprConfig:(NSDictionary *)gdprArg];
|
|
103
|
+
[controllers addObject:gdprConfiguration];
|
|
104
|
+
}
|
|
44
105
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
[
|
|
49
|
-
|
|
106
|
+
// GConfiguration
|
|
107
|
+
NSObject *gcArg = [argmap objectForKey:@"gcConfig"];
|
|
108
|
+
if (gcArg != nil && [gcArg isKindOfClass:NSArray.class]) {
|
|
109
|
+
SPGlobalContextsConfiguration *gcConfiguration = [RNConfigUtils mkGCConfig:(NSArray *)gcArg];
|
|
110
|
+
[controllers addObject:gcConfiguration];
|
|
111
|
+
}
|
|
50
112
|
|
|
51
|
-
|
|
52
|
-
[builder setEmitter:emitter];
|
|
53
|
-
[builder setAppId:options[@"appId"]];
|
|
54
|
-
[builder setBase64Encoded:[options[@"base64Encoded"] boolValue]];
|
|
55
|
-
[builder setTrackerNamespace:options[@"namespace"]];
|
|
56
|
-
[builder setApplicationContext:[options[@"applicationContext"] boolValue]];
|
|
57
|
-
[builder setLifecycleEvents:[options[@"lifecycleEvents"] boolValue]];
|
|
58
|
-
[builder setScreenContext:[options[@"screenContext"] boolValue]];
|
|
59
|
-
[builder setInstallEvent:[options[@"installTracking"] boolValue]];
|
|
60
|
-
[builder setSubject:subject];
|
|
61
|
-
[builder setSessionContext:[options[@"sessionContext"] boolValue]];
|
|
62
|
-
[builder setCheckInterval:[options[@"checkInterval"] integerValue]];
|
|
63
|
-
[builder setForegroundTimeout:[options[@"foregroundTimeout"] integerValue]];
|
|
64
|
-
[builder setBackgroundTimeout:[options[@"backgroundTimeout"] integerValue]];
|
|
65
|
-
}];
|
|
113
|
+
id<SPTrackerController> tracker = [SPSnowplow createTrackerWithNamespace:trackerNs network:networkConfiguration configurations:controllers];
|
|
66
114
|
|
|
67
|
-
if (
|
|
115
|
+
if (tracker) {
|
|
68
116
|
resolve(@YES);
|
|
69
117
|
} else {
|
|
70
|
-
NSError
|
|
71
|
-
|
|
118
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
119
|
+
reject(@"ERROR", @"tracker initialization failed", error);
|
|
72
120
|
}
|
|
73
121
|
}
|
|
74
122
|
|
|
75
|
-
RCT_EXPORT_METHOD(
|
|
76
|
-
|
|
123
|
+
RCT_EXPORT_METHOD(removeTracker: (NSDictionary *)details
|
|
124
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
125
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
126
|
+
NSString *namespace = [details objectForKey:@"tracker"];
|
|
127
|
+
id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
|
|
128
|
+
BOOL removed = [SPSnowplow removeTracker:trackerController];
|
|
129
|
+
resolve(@(removed));
|
|
130
|
+
}
|
|
77
131
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
NSString *ipAddress = options[@"ipAddress"];
|
|
83
|
-
NSString *useragent = options[@"useragent"];
|
|
84
|
-
NSString *networkUserId = options[@"networkUserId"];
|
|
85
|
-
NSString *domainUserId = options[@"domainUserId"];
|
|
132
|
+
RCT_EXPORT_METHOD(removeAllTrackers: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
|
133
|
+
[SPSnowplow removeAllTrackers];
|
|
134
|
+
resolve(@YES);
|
|
135
|
+
}
|
|
86
136
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
137
|
+
RCT_EXPORT_METHOD(trackSelfDescribingEvent:
|
|
138
|
+
(NSDictionary *)details
|
|
139
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
140
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
141
|
+
NSString *namespace = [details objectForKey:@"tracker"];
|
|
142
|
+
id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
|
|
92
143
|
|
|
93
|
-
if (
|
|
94
|
-
|
|
95
|
-
[
|
|
96
|
-
}
|
|
144
|
+
if (trackerController != nil) {
|
|
145
|
+
NSDictionary *argmap = [details objectForKey:@"eventData"];
|
|
146
|
+
NSArray<NSDictionary *> *contexts = [details objectForKey:@"contexts"];
|
|
97
147
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
[self.tracker.subject setTimezone:newTimezone];
|
|
101
|
-
}
|
|
148
|
+
SPSelfDescribingJson *eventData = [[SPSelfDescribingJson alloc] initWithSchema:(NSString *)[argmap objectForKey:@"schema"]
|
|
149
|
+
andDictionary:(NSDictionary *)[argmap objectForKey:@"data"]];
|
|
102
150
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
[
|
|
151
|
+
SPSelfDescribing *event = [[SPSelfDescribing alloc] initWithEventData:eventData];
|
|
152
|
+
[event contexts:[RNUtilities mkSDJArray:contexts]];
|
|
153
|
+
[trackerController track:event];
|
|
154
|
+
resolve(@YES);
|
|
155
|
+
} else {
|
|
156
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
157
|
+
reject(@"ERROR", @"tracker with given namespace not found", error);
|
|
106
158
|
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
RCT_EXPORT_METHOD(trackStructuredEvent:
|
|
162
|
+
(NSDictionary *)details
|
|
163
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
164
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
165
|
+
NSString *namespace = [details objectForKey:@"tracker"];
|
|
166
|
+
id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
|
|
167
|
+
|
|
168
|
+
if (trackerController != nil) {
|
|
169
|
+
NSDictionary *argmap = [details objectForKey:@"eventData"];
|
|
170
|
+
NSArray<NSDictionary *> *contexts = [details objectForKey:@"contexts"];
|
|
171
|
+
|
|
172
|
+
NSString *category = [argmap sp_stringForKey:@"category" defaultValue:nil];
|
|
173
|
+
NSString *action = [argmap sp_stringForKey:@"action" defaultValue:nil];
|
|
174
|
+
SPStructured *event = [[SPStructured alloc] initWithCategory:category
|
|
175
|
+
action:action];
|
|
176
|
+
NSString *label = [argmap sp_stringForKey:@"label" defaultValue:nil];
|
|
177
|
+
if (label) {
|
|
178
|
+
event.label = label;
|
|
179
|
+
}
|
|
180
|
+
NSString *property = [argmap sp_stringForKey:@"property" defaultValue:nil];
|
|
181
|
+
if (property) {
|
|
182
|
+
event.property = property;
|
|
183
|
+
}
|
|
184
|
+
NSNumber *value = [argmap sp_numberForKey:@"value" defaultValue:nil];
|
|
185
|
+
if (label) {
|
|
186
|
+
event.value = value;
|
|
187
|
+
}
|
|
107
188
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
189
|
+
[event contexts:[RNUtilities mkSDJArray:contexts]];
|
|
190
|
+
[trackerController track:event];
|
|
191
|
+
resolve(@YES);
|
|
192
|
+
} else {
|
|
193
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
194
|
+
reject(@"ERROR", @"tracker with given namespace not found", error);
|
|
111
195
|
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
RCT_EXPORT_METHOD(trackScreenViewEvent:
|
|
199
|
+
(NSDictionary *)details
|
|
200
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
201
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
202
|
+
NSString *namespace = [details objectForKey:@"tracker"];
|
|
203
|
+
id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
|
|
204
|
+
|
|
205
|
+
if (trackerController != nil) {
|
|
206
|
+
NSDictionary *argmap = [details objectForKey:@"eventData"];
|
|
207
|
+
NSArray<NSDictionary *> *contexts = [details objectForKey:@"contexts"];
|
|
208
|
+
|
|
209
|
+
NSString *screenName = [argmap sp_stringForKey:@"name" defaultValue:nil];
|
|
210
|
+
NSString *screenId = [argmap sp_stringForKey:@"id" defaultValue:nil];
|
|
211
|
+
NSUUID *screenUuid = [[NSUUID alloc] initWithUUIDString:screenId];
|
|
212
|
+
if (screenId != nil && screenUuid == nil) {
|
|
213
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
214
|
+
reject(@"ERROR", @"screenId has to be a valid UUID string", error);
|
|
215
|
+
}
|
|
216
|
+
SPScreenView *event = [[SPScreenView alloc] initWithName:screenName
|
|
217
|
+
screenId:screenUuid];
|
|
218
|
+
|
|
219
|
+
NSString *type = [argmap sp_stringForKey:@"type" defaultValue:nil];
|
|
220
|
+
if (type) {
|
|
221
|
+
event.type = type;
|
|
222
|
+
}
|
|
223
|
+
NSString *previousName = [argmap sp_stringForKey:@"previousName" defaultValue:nil];
|
|
224
|
+
if (previousName) {
|
|
225
|
+
event.previousName = previousName;
|
|
226
|
+
}
|
|
227
|
+
NSString *previousId = [argmap sp_stringForKey:@"previousId" defaultValue:nil];
|
|
228
|
+
if (previousId) {
|
|
229
|
+
event.previousId = previousId;
|
|
230
|
+
}
|
|
231
|
+
NSString *previousType = [argmap sp_stringForKey:@"previousType" defaultValue:nil];
|
|
232
|
+
if (previousType) {
|
|
233
|
+
event.previousType = previousType;
|
|
234
|
+
}
|
|
235
|
+
NSString *transitionType = [argmap sp_stringForKey:@"transitionType" defaultValue:nil];
|
|
236
|
+
if (transitionType) {
|
|
237
|
+
event.transitionType = transitionType;
|
|
238
|
+
}
|
|
112
239
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
240
|
+
[event contexts:[RNUtilities mkSDJArray:contexts]];
|
|
241
|
+
[trackerController track:event];
|
|
242
|
+
resolve(@YES);
|
|
243
|
+
} else {
|
|
244
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
245
|
+
reject(@"ERROR", @"tracker with given namespace not found", error);
|
|
116
246
|
}
|
|
247
|
+
}
|
|
117
248
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
249
|
+
RCT_EXPORT_METHOD(trackPageViewEvent:
|
|
250
|
+
(NSDictionary *)details
|
|
251
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
252
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
253
|
+
NSString *namespace = [details objectForKey:@"tracker"];
|
|
254
|
+
id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
|
|
255
|
+
|
|
256
|
+
if (trackerController != nil) {
|
|
257
|
+
NSDictionary *argmap = [details objectForKey:@"eventData"];
|
|
258
|
+
NSArray<NSDictionary *> *contexts = [details objectForKey:@"contexts"];
|
|
259
|
+
|
|
260
|
+
NSString *pageUrl = [argmap sp_stringForKey:@"pageUrl" defaultValue:nil];
|
|
261
|
+
SPPageView *event = [[SPPageView alloc] initWithPageUrl:pageUrl];
|
|
262
|
+
|
|
263
|
+
NSString *pageTitle = [argmap sp_stringForKey:@"pageTitle" defaultValue:nil];
|
|
264
|
+
if (pageTitle) {
|
|
265
|
+
event.pageTitle = pageTitle;
|
|
266
|
+
}
|
|
267
|
+
NSString *referrer = [argmap sp_stringForKey:@"referrer" defaultValue:nil];
|
|
268
|
+
if (referrer) {
|
|
269
|
+
event.referrer = referrer;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
[event contexts:[RNUtilities mkSDJArray:contexts]];
|
|
273
|
+
[trackerController track:event];
|
|
274
|
+
resolve(@YES);
|
|
275
|
+
} else {
|
|
276
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
277
|
+
reject(@"ERROR", @"tracker with given namespace not found", error);
|
|
121
278
|
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
RCT_EXPORT_METHOD(trackTimingEvent:
|
|
282
|
+
(NSDictionary *)details
|
|
283
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
284
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
285
|
+
NSString *namespace = [details objectForKey:@"tracker"];
|
|
286
|
+
id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
|
|
287
|
+
|
|
288
|
+
if (trackerController != nil) {
|
|
289
|
+
NSDictionary *argmap = [details objectForKey:@"eventData"];
|
|
290
|
+
NSArray<NSDictionary *> *contexts = [details objectForKey:@"contexts"];
|
|
291
|
+
|
|
292
|
+
NSString *category = [argmap sp_stringForKey:@"category" defaultValue:nil];
|
|
293
|
+
NSString *variable = [argmap sp_stringForKey:@"variable" defaultValue:nil];
|
|
294
|
+
NSNumber *timing = [argmap sp_numberForKey:@"timing" defaultValue:nil];
|
|
295
|
+
SPTiming *event = [[SPTiming alloc] initWithCategory:category
|
|
296
|
+
variable:variable
|
|
297
|
+
timing:timing];
|
|
298
|
+
NSString *label = [argmap sp_stringForKey:@"label" defaultValue:nil];
|
|
299
|
+
if (label) {
|
|
300
|
+
event.label = label;
|
|
301
|
+
}
|
|
122
302
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
303
|
+
[event contexts:[RNUtilities mkSDJArray:contexts]];
|
|
304
|
+
[trackerController track:event];
|
|
305
|
+
resolve(@YES);
|
|
306
|
+
} else {
|
|
307
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
308
|
+
reject(@"ERROR", @"tracker with given namespace not found", error);
|
|
126
309
|
}
|
|
310
|
+
}
|
|
127
311
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
312
|
+
RCT_EXPORT_METHOD(trackConsentGrantedEvent:
|
|
313
|
+
(NSDictionary *)details
|
|
314
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
315
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
316
|
+
NSString *namespace = [details objectForKey:@"tracker"];
|
|
317
|
+
id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
|
|
318
|
+
|
|
319
|
+
if (trackerController != nil) {
|
|
320
|
+
NSDictionary *argmap = [details objectForKey:@"eventData"];
|
|
321
|
+
NSArray<NSDictionary *> *contexts = [details objectForKey:@"contexts"];
|
|
322
|
+
|
|
323
|
+
NSString *expiry = [argmap sp_stringForKey:@"expiry" defaultValue:nil];
|
|
324
|
+
NSString *documentId = [argmap sp_stringForKey:@"documentId" defaultValue:nil];
|
|
325
|
+
NSString *version = [argmap sp_stringForKey:@"version" defaultValue:nil];
|
|
326
|
+
SPConsentGranted *event = [[SPConsentGranted alloc] initWithExpiry:expiry
|
|
327
|
+
documentId:documentId
|
|
328
|
+
version:version];
|
|
329
|
+
|
|
330
|
+
NSString *name = [argmap sp_stringForKey:@"name" defaultValue:nil];
|
|
331
|
+
if (name) {
|
|
332
|
+
event.name = name;
|
|
134
333
|
}
|
|
334
|
+
NSString *documentDescription = [argmap sp_stringForKey:@"documentDescription" defaultValue:nil];
|
|
335
|
+
if (documentDescription) {
|
|
336
|
+
event.documentDescription = documentDescription;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
[event contexts:[RNUtilities mkSDJArray:contexts]];
|
|
340
|
+
[trackerController track:event];
|
|
341
|
+
resolve(@YES);
|
|
342
|
+
} else {
|
|
343
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
344
|
+
reject(@"ERROR", @"tracker with given namespace not found", error);
|
|
135
345
|
}
|
|
346
|
+
}
|
|
136
347
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
348
|
+
RCT_EXPORT_METHOD(trackConsentWithdrawnEvent:
|
|
349
|
+
(NSDictionary *)details
|
|
350
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
351
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
352
|
+
NSString *namespace = [details objectForKey:@"tracker"];
|
|
353
|
+
id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
|
|
354
|
+
|
|
355
|
+
if (trackerController != nil) {
|
|
356
|
+
NSDictionary *argmap = [details objectForKey:@"eventData"];
|
|
357
|
+
NSArray<NSDictionary *> *contexts = [details objectForKey:@"contexts"];
|
|
358
|
+
|
|
359
|
+
SPConsentWithdrawn *event = [SPConsentWithdrawn new];
|
|
360
|
+
|
|
361
|
+
BOOL all = [argmap sp_boolForKey:@"all" defaultValue:nil];
|
|
362
|
+
event.all = all;
|
|
363
|
+
NSString *documentId = [argmap sp_stringForKey:@"documentId" defaultValue:nil];
|
|
364
|
+
event.documentId = documentId;
|
|
365
|
+
NSString *version = [argmap sp_stringForKey:@"version" defaultValue:nil];
|
|
366
|
+
event.version = version;
|
|
367
|
+
NSString *name = [argmap sp_stringForKey:@"name" defaultValue:nil];
|
|
368
|
+
if (name) {
|
|
369
|
+
event.name = name;
|
|
143
370
|
}
|
|
371
|
+
NSString *documentDescription = [argmap sp_stringForKey:@"documentDescription" defaultValue:nil];
|
|
372
|
+
if (documentDescription) {
|
|
373
|
+
event.documentDescription = documentDescription;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
[event contexts:[RNUtilities mkSDJArray:contexts]];
|
|
377
|
+
[trackerController track:event];
|
|
378
|
+
resolve(@YES);
|
|
379
|
+
} else {
|
|
380
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
381
|
+
reject(@"ERROR", @"tracker with given namespace not found", error);
|
|
144
382
|
}
|
|
383
|
+
}
|
|
145
384
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
385
|
+
RCT_EXPORT_METHOD(trackEcommerceTransactionEvent:
|
|
386
|
+
(NSDictionary *)details
|
|
387
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
388
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
389
|
+
NSString *namespace = [details objectForKey:@"tracker"];
|
|
390
|
+
id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
|
|
391
|
+
|
|
392
|
+
if (trackerController != nil) {
|
|
393
|
+
NSDictionary *argmap = [details objectForKey:@"eventData"];
|
|
394
|
+
NSArray<NSDictionary *> *contexts = [details objectForKey:@"contexts"];
|
|
395
|
+
|
|
396
|
+
NSString *orderId = [argmap sp_stringForKey:@"orderId" defaultValue:nil];
|
|
397
|
+
NSNumber *totalValue = [argmap sp_numberForKey:@"totalValue" defaultValue:nil];
|
|
398
|
+
NSArray *items = [argmap objectForKey:@"items"];
|
|
399
|
+
|
|
400
|
+
NSMutableArray *transItems = [NSMutableArray new];
|
|
401
|
+
for (NSDictionary* item in items) {
|
|
402
|
+
NSString *sku = [item sp_stringForKey:@"sku" defaultValue:nil];
|
|
403
|
+
NSNumber *price = [item sp_numberForKey:@"price" defaultValue:nil];
|
|
404
|
+
NSNumber *quantity = [item sp_numberForKey:@"quantity" defaultValue:nil];
|
|
405
|
+
SPEcommerceItem *ecomItem = [[SPEcommerceItem alloc] initWithSku:sku
|
|
406
|
+
price:price
|
|
407
|
+
quantity:quantity];
|
|
408
|
+
|
|
409
|
+
NSString *name = [argmap sp_stringForKey:@"name" defaultValue:nil];
|
|
410
|
+
if (name) {
|
|
411
|
+
ecomItem.name = name;
|
|
412
|
+
}
|
|
413
|
+
NSString *category = [argmap sp_stringForKey:@"category" defaultValue:nil];
|
|
414
|
+
if (category) {
|
|
415
|
+
ecomItem.category = category;
|
|
416
|
+
}
|
|
417
|
+
NSString *currency = [argmap sp_stringForKey:@"currency" defaultValue:nil];
|
|
418
|
+
if (currency) {
|
|
419
|
+
ecomItem.currency = currency;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
[transItems addObject:ecomItem];
|
|
152
423
|
}
|
|
424
|
+
|
|
425
|
+
SPEcommerce *event = [[SPEcommerce alloc] initWithOrderId:orderId
|
|
426
|
+
totalValue:totalValue
|
|
427
|
+
items:(NSArray<SPEcommerceItem *> *)transItems];
|
|
428
|
+
[event contexts:[RNUtilities mkSDJArray:contexts]];
|
|
429
|
+
[trackerController track:event];
|
|
430
|
+
resolve(@YES);
|
|
431
|
+
|
|
432
|
+
} else {
|
|
433
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
434
|
+
reject(@"ERROR", @"tracker with given namespace not found", error);
|
|
153
435
|
}
|
|
154
436
|
}
|
|
155
437
|
|
|
156
|
-
RCT_EXPORT_METHOD(
|
|
157
|
-
|
|
158
|
-
|
|
438
|
+
RCT_EXPORT_METHOD(trackDeepLinkReceivedEvent:
|
|
439
|
+
(NSDictionary *)details
|
|
440
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
441
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
442
|
+
NSString *namespace = [details objectForKey:@"tracker"];
|
|
443
|
+
id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
|
|
444
|
+
|
|
445
|
+
if (trackerController != nil) {
|
|
446
|
+
NSDictionary *argmap = [details objectForKey:@"eventData"];
|
|
447
|
+
NSArray<NSDictionary *> *contexts = [details objectForKey:@"contexts"];
|
|
448
|
+
|
|
449
|
+
NSString *url = [argmap sp_stringForKey:@"url" defaultValue:nil];
|
|
450
|
+
SPDeepLinkReceived *event = [[SPDeepLinkReceived alloc] initWithUrl:url];
|
|
159
451
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
[builder setContexts:[[NSMutableArray alloc] initWithArray:contexts]];
|
|
452
|
+
NSString *referrer = [argmap sp_stringForKey:@"referrer" defaultValue:nil];
|
|
453
|
+
if (referrer) {
|
|
454
|
+
event.referrer = referrer;
|
|
164
455
|
}
|
|
165
|
-
}];
|
|
166
456
|
|
|
167
|
-
|
|
457
|
+
[event contexts:[RNUtilities mkSDJArray:contexts]];
|
|
458
|
+
[trackerController track:event];
|
|
459
|
+
resolve(@YES);
|
|
460
|
+
} else {
|
|
461
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
462
|
+
reject(@"ERROR", @"tracker with given namespace not found", error);
|
|
463
|
+
}
|
|
168
464
|
}
|
|
169
465
|
|
|
170
|
-
RCT_EXPORT_METHOD(
|
|
171
|
-
|
|
172
|
-
|
|
466
|
+
RCT_EXPORT_METHOD(trackMessageNotificationEvent:
|
|
467
|
+
(NSDictionary *)details
|
|
468
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
469
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
470
|
+
NSString *namespace = [details objectForKey:@"tracker"];
|
|
471
|
+
id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
|
|
472
|
+
|
|
473
|
+
if (trackerController != nil) {
|
|
474
|
+
NSDictionary *argmap = [details objectForKey:@"eventData"];
|
|
475
|
+
NSArray<NSDictionary *> *contexts = [details objectForKey:@"contexts"];
|
|
476
|
+
|
|
477
|
+
NSString *title = [argmap sp_stringForKey:@"title" defaultValue:nil];
|
|
478
|
+
NSString *body = [argmap sp_stringForKey:@"body" defaultValue:nil];
|
|
479
|
+
NSString *triggerStr = [argmap sp_stringForKey:@"trigger" defaultValue:nil];
|
|
480
|
+
SPMessageNotificationTrigger trigger;
|
|
481
|
+
if ([triggerStr isEqualToString:@"push"]) {
|
|
482
|
+
trigger = SPMessageNotificationTriggerPush;
|
|
483
|
+
} else if ([triggerStr isEqualToString:@"location"]) {
|
|
484
|
+
trigger = SPMessageNotificationTriggerLocation;
|
|
485
|
+
} else if ([triggerStr isEqualToString:@"calendar"]) {
|
|
486
|
+
trigger = SPMessageNotificationTriggerCalendar;
|
|
487
|
+
} else if ([triggerStr isEqualToString:@"timeInterval"]) {
|
|
488
|
+
trigger = SPMessageNotificationTriggerTimeInterval;
|
|
489
|
+
} else {
|
|
490
|
+
trigger = SPMessageNotificationTriggerOther;
|
|
491
|
+
}
|
|
492
|
+
SPMessageNotification *event = [[SPMessageNotification alloc] initWithTitle: title
|
|
493
|
+
body: body
|
|
494
|
+
trigger: trigger];
|
|
173
495
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
496
|
+
NSString *action = [argmap sp_stringForKey:@"action" defaultValue:nil];
|
|
497
|
+
if (action) {
|
|
498
|
+
event.action = action;
|
|
499
|
+
}
|
|
500
|
+
NSArray *attachmentsMap = [argmap objectForKey:@"attachments"];
|
|
501
|
+
if (attachmentsMap) {
|
|
502
|
+
NSMutableArray *attachments = [NSMutableArray new];
|
|
503
|
+
for (NSDictionary* attachmentMap in attachmentsMap) {
|
|
504
|
+
NSString *identifier = [attachmentMap sp_stringForKey:@"identifier" defaultValue:nil];
|
|
505
|
+
NSString *type = [attachmentMap sp_stringForKey:@"type" defaultValue:nil];
|
|
506
|
+
NSString *url = [attachmentMap sp_stringForKey:@"url" defaultValue:nil];
|
|
507
|
+
SPMessageNotificationAttachment *attachment = [[SPMessageNotificationAttachment alloc] initWithIdentifier:identifier
|
|
508
|
+
type:type
|
|
509
|
+
url:url];
|
|
510
|
+
[attachments addObject:attachment];
|
|
511
|
+
}
|
|
512
|
+
event.attachments = attachments;
|
|
513
|
+
}
|
|
514
|
+
NSArray<NSString *> *bodyLocArgs = [argmap objectForKey:@"bodyLocArgs"];
|
|
515
|
+
if (bodyLocArgs) {
|
|
516
|
+
event.bodyLocArgs = bodyLocArgs;
|
|
517
|
+
}
|
|
518
|
+
NSString *bodyLocKey = [argmap sp_stringForKey:@"bodyLocKey" defaultValue:nil];
|
|
519
|
+
if (bodyLocKey) {
|
|
520
|
+
event.bodyLocKey = bodyLocKey;
|
|
521
|
+
}
|
|
522
|
+
NSString *category = [argmap sp_stringForKey:@"category" defaultValue:nil];
|
|
523
|
+
if (category) {
|
|
524
|
+
event.category = category;
|
|
525
|
+
}
|
|
526
|
+
NSNumber *contentAvailable = [argmap sp_numberForKey:@"contentAvailable" defaultValue:nil];
|
|
527
|
+
if (contentAvailable != nil) {
|
|
528
|
+
event.contentAvailable = contentAvailable;
|
|
529
|
+
}
|
|
530
|
+
NSString *group = [argmap sp_stringForKey:@"group" defaultValue:nil];
|
|
531
|
+
if (group) {
|
|
532
|
+
event.group = group;
|
|
179
533
|
}
|
|
180
|
-
|
|
181
|
-
|
|
534
|
+
NSString *icon = [argmap sp_stringForKey:@"icon" defaultValue:nil];
|
|
535
|
+
if (icon) {
|
|
536
|
+
event.icon = icon;
|
|
182
537
|
}
|
|
183
|
-
|
|
184
|
-
if (
|
|
185
|
-
|
|
538
|
+
NSNumber *notificationCount = [argmap sp_numberForKey:@"notificationCount" defaultValue:nil];
|
|
539
|
+
if (notificationCount) {
|
|
540
|
+
event.notificationCount = notificationCount;
|
|
186
541
|
}
|
|
187
|
-
|
|
188
|
-
|
|
542
|
+
NSString *notificationTimestamp = [argmap sp_stringForKey:@"notificationTimestamp" defaultValue:nil];
|
|
543
|
+
if (notificationTimestamp) {
|
|
544
|
+
event.notificationTimestamp = notificationTimestamp;
|
|
189
545
|
}
|
|
190
|
-
|
|
546
|
+
NSString *sound = [argmap sp_stringForKey:@"sound" defaultValue:nil];
|
|
547
|
+
if (sound) {
|
|
548
|
+
event.sound = sound;
|
|
549
|
+
}
|
|
550
|
+
NSString *subtitle = [argmap sp_stringForKey:@"subtitle" defaultValue:nil];
|
|
551
|
+
if (subtitle) {
|
|
552
|
+
event.subtitle = subtitle;
|
|
553
|
+
}
|
|
554
|
+
NSString *tag = [argmap sp_stringForKey:@"tag" defaultValue:nil];
|
|
555
|
+
if (tag) {
|
|
556
|
+
event.tag = tag;
|
|
557
|
+
}
|
|
558
|
+
NSString *threadIdentifier = [argmap sp_stringForKey:@"threadIdentifier" defaultValue:nil];
|
|
559
|
+
if (threadIdentifier) {
|
|
560
|
+
event.threadIdentifier = threadIdentifier;
|
|
561
|
+
}
|
|
562
|
+
NSArray<NSString *> *titleLocArgs = [argmap objectForKey:@"titleLocArgs"];
|
|
563
|
+
if (titleLocArgs) {
|
|
564
|
+
event.titleLocArgs = titleLocArgs;
|
|
565
|
+
}
|
|
566
|
+
NSString *titleLocKey = [argmap sp_stringForKey:@"titleLocKey" defaultValue:nil];
|
|
567
|
+
if (titleLocKey) {
|
|
568
|
+
event.titleLocKey = titleLocKey;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
[event contexts:[RNUtilities mkSDJArray:contexts]];
|
|
572
|
+
[trackerController track:event];
|
|
573
|
+
resolve(@YES);
|
|
574
|
+
} else {
|
|
575
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
576
|
+
reject(@"ERROR", @"tracker with given namespace not found", error);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
191
579
|
|
|
192
|
-
|
|
580
|
+
RCT_EXPORT_METHOD(removeGlobalContexts:
|
|
581
|
+
(NSDictionary *)details
|
|
582
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
583
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
584
|
+
NSString *namespace = [details objectForKey:@"tracker"];
|
|
585
|
+
id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
|
|
586
|
+
|
|
587
|
+
if (trackerController != nil) {
|
|
588
|
+
NSString *tag = [details objectForKey:@"removeTag"];
|
|
589
|
+
[[trackerController globalContexts] removeWithTag:tag];
|
|
590
|
+
resolve(@YES);
|
|
591
|
+
} else {
|
|
592
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
593
|
+
reject(@"ERROR", @"tracker with given namespace not found", error);
|
|
594
|
+
}
|
|
193
595
|
}
|
|
194
596
|
|
|
195
|
-
RCT_EXPORT_METHOD(
|
|
196
|
-
|
|
197
|
-
:(
|
|
597
|
+
RCT_EXPORT_METHOD(addGlobalContexts:
|
|
598
|
+
(NSDictionary *)details
|
|
599
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
600
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
601
|
+
NSString *namespace = [details objectForKey:@"tracker"];
|
|
602
|
+
id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
|
|
198
603
|
|
|
199
|
-
|
|
200
|
-
[
|
|
604
|
+
if (trackerController != nil) {
|
|
605
|
+
NSDictionary *gcArg = [details objectForKey:@"addGlobalContext"];
|
|
606
|
+
NSString *tag = [gcArg objectForKey:@"tag"];
|
|
607
|
+
NSArray *globalContexts = [gcArg objectForKey:@"globalContexts"];
|
|
201
608
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
609
|
+
NSArray *staticContexts = [[RNUtilities mkSDJArray:globalContexts] mutableCopy];
|
|
610
|
+
SPGlobalContext *gcStatic = [[SPGlobalContext alloc] initWithStaticContexts:staticContexts];
|
|
611
|
+
|
|
612
|
+
[[trackerController globalContexts] addWithTag:tag contextGenerator:gcStatic];
|
|
613
|
+
resolve(@YES);
|
|
614
|
+
} else {
|
|
615
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
616
|
+
reject(@"ERROR", @"tracker with given namespace not found", error);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
RCT_EXPORT_METHOD(setUserId:
|
|
621
|
+
(NSDictionary *)details
|
|
622
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
623
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
624
|
+
NSString *namespace = [details objectForKey:@"tracker"];
|
|
625
|
+
id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
|
|
626
|
+
|
|
627
|
+
if (trackerController != nil) {
|
|
628
|
+
NSString *newUid = [details sp_stringForKey:@"userId" defaultValue:nil];
|
|
629
|
+
[trackerController.subject setUserId:newUid];
|
|
630
|
+
resolve(@YES);
|
|
631
|
+
} else {
|
|
632
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
633
|
+
reject(@"ERROR", @"tracker with given namespace not found", error);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
RCT_EXPORT_METHOD(setNetworkUserId:
|
|
638
|
+
(NSDictionary *)details
|
|
639
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
640
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
641
|
+
NSString *namespace = [details objectForKey:@"tracker"];
|
|
642
|
+
id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
|
|
643
|
+
|
|
644
|
+
if (trackerController != nil) {
|
|
645
|
+
NSString *newNuid = [details sp_stringForKey:@"networkUserId" defaultValue:nil];
|
|
646
|
+
[trackerController.subject setNetworkUserId:newNuid];
|
|
647
|
+
resolve(@YES);
|
|
648
|
+
} else {
|
|
649
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
650
|
+
reject(@"ERROR", @"tracker with given namespace not found", error);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
RCT_EXPORT_METHOD(setDomainUserId:
|
|
655
|
+
(NSDictionary *)details
|
|
656
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
657
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
658
|
+
NSString *namespace = [details objectForKey:@"tracker"];
|
|
659
|
+
id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
|
|
660
|
+
|
|
661
|
+
if (trackerController != nil) {
|
|
662
|
+
NSString *newDuid = [details sp_stringForKey:@"domainUserId" defaultValue:nil];
|
|
663
|
+
[trackerController.subject setDomainUserId:newDuid];
|
|
664
|
+
resolve(@YES);
|
|
665
|
+
} else {
|
|
666
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
667
|
+
reject(@"ERROR", @"tracker with given namespace not found", error);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
RCT_EXPORT_METHOD(setIpAddress:
|
|
672
|
+
(NSDictionary *)details
|
|
673
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
674
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
675
|
+
NSString *namespace = [details objectForKey:@"tracker"];
|
|
676
|
+
id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
|
|
677
|
+
|
|
678
|
+
if (trackerController != nil) {
|
|
679
|
+
NSString *newIp = [details sp_stringForKey:@"ipAddress" defaultValue:nil];
|
|
680
|
+
[trackerController.subject setIpAddress:newIp];
|
|
681
|
+
resolve(@YES);
|
|
682
|
+
} else {
|
|
683
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
684
|
+
reject(@"ERROR", @"tracker with given namespace not found", error);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
209
687
|
|
|
210
|
-
|
|
688
|
+
RCT_EXPORT_METHOD(setUseragent:
|
|
689
|
+
(NSDictionary *)details
|
|
690
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
691
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
692
|
+
NSString *namespace = [details objectForKey:@"tracker"];
|
|
693
|
+
id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
|
|
694
|
+
|
|
695
|
+
if (trackerController != nil) {
|
|
696
|
+
NSString *newUagent = [details sp_stringForKey:@"useragent" defaultValue:nil];
|
|
697
|
+
[trackerController.subject setUseragent:newUagent];
|
|
698
|
+
resolve(@YES);
|
|
699
|
+
} else {
|
|
700
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
701
|
+
reject(@"ERROR", @"tracker with given namespace not found", error);
|
|
702
|
+
}
|
|
211
703
|
}
|
|
212
704
|
|
|
213
|
-
RCT_EXPORT_METHOD(
|
|
214
|
-
|
|
215
|
-
:(
|
|
705
|
+
RCT_EXPORT_METHOD(setTimezone:
|
|
706
|
+
(NSDictionary *)details
|
|
707
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
708
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
709
|
+
NSString *namespace = [details objectForKey:@"tracker"];
|
|
710
|
+
id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
|
|
216
711
|
|
|
217
|
-
|
|
218
|
-
[
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
712
|
+
if (trackerController != nil) {
|
|
713
|
+
NSString *newTz = [details sp_stringForKey:@"timezone" defaultValue:nil];
|
|
714
|
+
[trackerController.subject setTimezone:newTz];
|
|
715
|
+
resolve(@YES);
|
|
716
|
+
} else {
|
|
717
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
718
|
+
reject(@"ERROR", @"tracker with given namespace not found", error);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
RCT_EXPORT_METHOD(setLanguage:
|
|
723
|
+
(NSDictionary *)details
|
|
724
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
725
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
726
|
+
NSString *namespace = [details objectForKey:@"tracker"];
|
|
727
|
+
id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
|
|
728
|
+
|
|
729
|
+
if (trackerController != nil) {
|
|
730
|
+
NSString *newLang = [details sp_stringForKey:@"language" defaultValue:nil];
|
|
731
|
+
[trackerController.subject setLanguage:newLang];
|
|
732
|
+
resolve(@YES);
|
|
733
|
+
} else {
|
|
734
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
735
|
+
reject(@"ERROR", @"tracker with given namespace not found", error);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
RCT_EXPORT_METHOD(setScreenResolution:
|
|
740
|
+
(NSDictionary *)details
|
|
741
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
742
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
743
|
+
NSString *namespace = [details objectForKey:@"tracker"];
|
|
744
|
+
id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
|
|
745
|
+
|
|
746
|
+
if (trackerController != nil) {
|
|
747
|
+
NSObject *newRes = [details objectForKey:@"screenResolution"];
|
|
748
|
+
if (newRes == [NSNull null]) {
|
|
749
|
+
[trackerController.subject setScreenResolution:nil];
|
|
750
|
+
} else {
|
|
751
|
+
NSNumber *resWidth = [(NSArray *)newRes objectAtIndex:0];
|
|
752
|
+
NSNumber *resHeight = [(NSArray *)newRes objectAtIndex:1];
|
|
753
|
+
SPSize *resSize = [[SPSize alloc] initWithWidth:[resWidth integerValue] height:[resHeight integerValue]];
|
|
754
|
+
[trackerController.subject setScreenResolution:resSize];
|
|
223
755
|
}
|
|
224
|
-
|
|
225
|
-
|
|
756
|
+
resolve(@YES);
|
|
757
|
+
} else {
|
|
758
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
759
|
+
reject(@"ERROR", @"tracker with given namespace not found", error);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
RCT_EXPORT_METHOD(setScreenViewport:
|
|
764
|
+
(NSDictionary *)details
|
|
765
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
766
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
767
|
+
NSString *namespace = [details objectForKey:@"tracker"];
|
|
768
|
+
id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
|
|
769
|
+
|
|
770
|
+
if (trackerController != nil) {
|
|
771
|
+
NSObject *newView = [details objectForKey:@"screenViewport"];
|
|
772
|
+
if (newView == [NSNull null]) {
|
|
773
|
+
[trackerController.subject setScreenViewPort:nil];
|
|
774
|
+
} else {
|
|
775
|
+
NSNumber *vpWidth = [(NSArray *)newView objectAtIndex:0];
|
|
776
|
+
NSNumber *vpHeight = [(NSArray *)newView objectAtIndex:1];
|
|
777
|
+
SPSize *vpSize = [[SPSize alloc] initWithWidth:[vpWidth integerValue] height:[vpHeight integerValue]];
|
|
778
|
+
[trackerController.subject setScreenViewPort:vpSize];
|
|
779
|
+
}
|
|
780
|
+
resolve(@YES);
|
|
781
|
+
} else {
|
|
782
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
783
|
+
reject(@"ERROR", @"tracker with given namespace not found", error);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
RCT_EXPORT_METHOD(setColorDepth:
|
|
788
|
+
(NSDictionary *)details
|
|
789
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
790
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
791
|
+
NSString *namespace = [details objectForKey:@"tracker"];
|
|
792
|
+
id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
|
|
793
|
+
|
|
794
|
+
if (trackerController != nil) {
|
|
795
|
+
NSNumber *newColorD = [details sp_numberForKey:@"colorDepth" defaultValue:nil];
|
|
796
|
+
[trackerController.subject setColorDepth:newColorD];
|
|
797
|
+
resolve(@YES);
|
|
798
|
+
} else {
|
|
799
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
800
|
+
reject(@"ERROR", @"tracker with given namespace not found", error);
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
RCT_EXPORT_METHOD(getSessionUserId:
|
|
805
|
+
(NSDictionary *)details
|
|
806
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
807
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
808
|
+
NSString *namespace = [details objectForKey:@"tracker"];
|
|
809
|
+
id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
|
|
810
|
+
|
|
811
|
+
if (trackerController != nil) {
|
|
812
|
+
NSString *suid = [trackerController.session userId];
|
|
813
|
+
resolve(suid);
|
|
814
|
+
} else {
|
|
815
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
816
|
+
reject(@"ERROR", @"tracker with given namespace not found", error);
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
RCT_EXPORT_METHOD(getSessionId:
|
|
821
|
+
(NSDictionary *)details
|
|
822
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
823
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
824
|
+
NSString *namespace = [details objectForKey:@"tracker"];
|
|
825
|
+
id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
|
|
826
|
+
|
|
827
|
+
if (trackerController != nil) {
|
|
828
|
+
NSString *sid = [trackerController.session sessionId];
|
|
829
|
+
resolve(sid);
|
|
830
|
+
} else {
|
|
831
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
832
|
+
reject(@"ERROR", @"tracker with given namespace not found", error);
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
RCT_EXPORT_METHOD(getSessionIndex:
|
|
837
|
+
(NSDictionary *)details
|
|
838
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
839
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
840
|
+
NSString *namespace = [details objectForKey:@"tracker"];
|
|
841
|
+
id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
|
|
842
|
+
|
|
843
|
+
if (trackerController != nil) {
|
|
844
|
+
NSInteger sidx = [trackerController.session sessionIndex];
|
|
845
|
+
resolve(@(sidx));
|
|
846
|
+
} else {
|
|
847
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
848
|
+
reject(@"ERROR", @"tracker with given namespace not found", error);
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
RCT_EXPORT_METHOD(getIsInBackground:
|
|
853
|
+
(NSDictionary *)details
|
|
854
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
855
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
856
|
+
NSString *namespace = [details objectForKey:@"tracker"];
|
|
857
|
+
id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
|
|
858
|
+
|
|
859
|
+
if (trackerController != nil) {
|
|
860
|
+
BOOL isInBg = [trackerController.session isInBackground];
|
|
861
|
+
resolve(@(isInBg));
|
|
862
|
+
} else {
|
|
863
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
864
|
+
reject(@"ERROR", @"tracker with given namespace not found", error);
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
RCT_EXPORT_METHOD(getBackgroundIndex:
|
|
869
|
+
(NSDictionary *)details
|
|
870
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
871
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
872
|
+
NSString *namespace = [details objectForKey:@"tracker"];
|
|
873
|
+
id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
|
|
874
|
+
|
|
875
|
+
if (trackerController != nil) {
|
|
876
|
+
NSInteger bgIdx = [trackerController.session backgroundIndex];
|
|
877
|
+
resolve(@(bgIdx));
|
|
878
|
+
} else {
|
|
879
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
880
|
+
reject(@"ERROR", @"tracker with given namespace not found", error);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
RCT_EXPORT_METHOD(getForegroundIndex:
|
|
885
|
+
(NSDictionary *)details
|
|
886
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
887
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
888
|
+
NSString *namespace = [details objectForKey:@"tracker"];
|
|
889
|
+
id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
|
|
890
|
+
|
|
891
|
+
if (trackerController != nil) {
|
|
892
|
+
NSInteger fgIdx = [trackerController.session foregroundIndex];
|
|
893
|
+
resolve(@(fgIdx));
|
|
894
|
+
} else {
|
|
895
|
+
NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
|
|
896
|
+
reject(@"ERROR", @"tracker with given namespace not found", error);
|
|
897
|
+
}
|
|
226
898
|
}
|
|
227
899
|
|
|
228
900
|
@end
|