@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.
@@ -0,0 +1,217 @@
1
+ //
2
+ // RNConfigUtils.m
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
+ #import "RNConfigUtils.h"
22
+ #import "RNTrackerVersion.h"
23
+ #import "RNUtilities.h"
24
+ #import "NSDictionary+RNCAT_TypeMethods.h"
25
+
26
+ #import <Foundation/Foundation.h>
27
+
28
+ #import <ConvivaAppAnalytics/CATAppAnalytics.h>
29
+ #import <ConvivaAppAnalytics/CATTrackerConfiguration.h>
30
+ #import <ConvivaAppAnalytics/CATDevicePlatform.h>
31
+ #import <ConvivaAppAnalytics/CATLoggerDelegate.h>
32
+ #import <ConvivaAppAnalytics/CATSessionConfiguration.h>
33
+ #import <ConvivaAppAnalytics/CATEmitterConfiguration.h>
34
+ #import <ConvivaAppAnalytics/CATSubjectConfiguration.h>
35
+ #import <ConvivaAppAnalytics/CATGDPRConfiguration.h>
36
+ #import <ConvivaAppAnalytics/CATGlobalContextsConfiguration.h>
37
+
38
+ @implementation RNConfigUtils
39
+
40
+ + (CATTrackerConfiguration *) mkDefaultTrackerConfig {
41
+
42
+ CATTrackerConfiguration *trackerConfiguration = [CATTrackerConfiguration new];
43
+ trackerConfiguration.trackerVersionSuffix = kRNTrackerVersion;
44
+
45
+ return trackerConfiguration;
46
+ }
47
+
48
+ + (CATTrackerConfiguration *) mkTrackerConfig:(NSDictionary *) trackerConfig {
49
+ CATTrackerConfiguration *trackerConfiguration = [CATTrackerConfiguration new];
50
+ trackerConfiguration.trackerVersionSuffix = kRNTrackerVersion;
51
+
52
+ NSString *appId = [trackerConfig rncat_stringForKey:@"appId" defaultValue:nil];
53
+ if (appId) {
54
+ trackerConfiguration.appId = appId;
55
+ }
56
+
57
+ NSString *devicePlatform = [trackerConfig rncat_stringForKey:@"devicePlatform" defaultValue:nil];
58
+ if (devicePlatform) {
59
+ trackerConfiguration.devicePlatform = CATStringToDevicePlatform(devicePlatform);
60
+ }
61
+
62
+ trackerConfiguration.base64Encoding = [trackerConfig rncat_boolForKey:@"base64Encoding" defaultValue:YES];
63
+
64
+ NSString *logLevel = [trackerConfig rncat_stringForKey:@"logLevel" defaultValue:nil];
65
+ if (logLevel) {
66
+ NSUInteger index = [@[@"off", @"error", @"debug", @"verbose"] indexOfObject:logLevel];
67
+ trackerConfiguration.logLevel = index != NSNotFound ? index : CATLogLevelOff;
68
+ }
69
+
70
+ trackerConfiguration.sessionContext = [trackerConfig rncat_boolForKey:@"sessionContext" defaultValue:YES];
71
+ trackerConfiguration.applicationContext = [trackerConfig rncat_boolForKey:@"applicationContext" defaultValue:YES];
72
+ trackerConfiguration.platformContext = [trackerConfig rncat_boolForKey:@"platformContext" defaultValue:YES];
73
+ trackerConfiguration.geoLocationContext = [trackerConfig rncat_boolForKey:@"geoLocationContext" defaultValue:NO];
74
+ trackerConfiguration.screenContext = [trackerConfig rncat_boolForKey:@"screenContext" defaultValue:YES];
75
+ trackerConfiguration.deepLinkContext = [trackerConfig rncat_boolForKey:@"deepLinkContext" defaultValue:YES];
76
+ trackerConfiguration.screenViewAutotracking = [trackerConfig rncat_boolForKey:@"screenViewAutotracking" defaultValue:YES];
77
+ trackerConfiguration.lifecycleAutotracking = [trackerConfig rncat_boolForKey:@"lifecycleAutotracking" defaultValue:NO];
78
+ trackerConfiguration.installAutotracking = [trackerConfig rncat_boolForKey:@"installAutotracking" defaultValue:YES];
79
+ trackerConfiguration.exceptionAutotracking = [trackerConfig rncat_boolForKey:@"exceptionAutotracking" defaultValue:YES];
80
+ trackerConfiguration.diagnosticAutotracking = [trackerConfig rncat_boolForKey:@"diagnosticAutotracking" defaultValue:NO];
81
+ // trackerConfiguration.userAnonymisation = [trackerConfig rncat_boolForKey:@"userAnonymisation" defaultValue:NO];
82
+
83
+ return trackerConfiguration;
84
+ }
85
+
86
+ + (CATSessionConfiguration *) mkSessionConfig:(NSDictionary *) sessionConfig {
87
+
88
+ NSInteger foreground = [[sessionConfig rncat_numberForKey:@"foregroundTimeout" defaultValue:@1800] integerValue];
89
+ NSInteger background = [[sessionConfig rncat_numberForKey:@"backgroundTimeout" defaultValue:@1800] integerValue];
90
+ CATSessionConfiguration *sessionConfiguration = [[CATSessionConfiguration alloc] initWithForegroundTimeoutInSeconds:foreground backgroundTimeoutInSeconds:background];
91
+
92
+ return sessionConfiguration;
93
+ }
94
+
95
+ + (CATEmitterConfiguration *) mkEmitterConfig:(NSDictionary *) emitterConfig {
96
+ CATEmitterConfiguration *emitterConfiguration = [[CATEmitterConfiguration alloc] init];
97
+ NSString *bufferOption = [emitterConfig rncat_stringForKey:@"bufferOption" defaultValue:@"single"];
98
+ if ([bufferOption isEqualToString:@"default"]) {
99
+ emitterConfiguration.bufferOption = CATBufferOptionDefaultGroup;
100
+ } else if ([bufferOption isEqualToString:@"large"]) {
101
+ emitterConfiguration.bufferOption = CATBufferOptionLargeGroup;
102
+ } else {
103
+ emitterConfiguration.bufferOption = CATBufferOptionSingle;
104
+ }
105
+
106
+ emitterConfiguration.emitRange = [[emitterConfig rncat_numberForKey:@"emitRange" defaultValue:@150] integerValue];
107
+ emitterConfiguration.threadPoolSize = [[emitterConfig rncat_numberForKey:@"threadPoolSize" defaultValue:@15] integerValue];
108
+ emitterConfiguration.byteLimitGet = [[emitterConfig rncat_numberForKey:@"byteLimitGet" defaultValue:@40000] integerValue];
109
+ emitterConfiguration.byteLimitPost = [[emitterConfig rncat_numberForKey:@"byteLimitPost" defaultValue:@40000] integerValue];
110
+ // emitterConfiguration.serverAnonymisation = [emitterConfig rncat_boolForKey:@"serverAnonymisation" defaultValue:NO];
111
+
112
+ return emitterConfiguration;
113
+ }
114
+
115
+ + (CATSubjectConfiguration *) mkSubjectConfig:(NSDictionary *) subjectConfig {
116
+
117
+ CATSubjectConfiguration *subjectConfiguration = [CATSubjectConfiguration new];
118
+
119
+ NSString *userId = [subjectConfig rncat_stringForKey:@"userId" defaultValue:nil];
120
+ if (userId) {
121
+ subjectConfiguration.userId = userId;
122
+ }
123
+
124
+ NSString *networkUserId = [subjectConfig rncat_stringForKey:@"networkUserId" defaultValue:nil];
125
+ if (networkUserId) {
126
+ subjectConfiguration.networkUserId = networkUserId;
127
+ }
128
+
129
+ NSString *domainUserId = [subjectConfig rncat_stringForKey:@"domainUserId" defaultValue:nil];
130
+ if (domainUserId) {
131
+ subjectConfiguration.domainUserId = domainUserId;
132
+ }
133
+
134
+ NSString *useragent = [subjectConfig rncat_stringForKey:@"useragent" defaultValue:nil];
135
+ if (useragent) {
136
+ subjectConfiguration.useragent = useragent;
137
+ }
138
+
139
+ NSString *ipAddress = [subjectConfig rncat_stringForKey:@"ipAddress" defaultValue:nil];
140
+ if (ipAddress) {
141
+ subjectConfiguration.ipAddress = ipAddress;
142
+ }
143
+
144
+ NSString *timezone = [subjectConfig rncat_stringForKey:@"timezone" defaultValue:nil];
145
+ if (timezone) {
146
+ subjectConfiguration.timezone = timezone;
147
+ }
148
+
149
+ NSString *language = [subjectConfig rncat_stringForKey:@"language" defaultValue:nil];
150
+ if (language) {
151
+ subjectConfiguration.language = language;
152
+ }
153
+
154
+ // screenResolution - type checked RN side
155
+ NSArray *screenRSize = [subjectConfig objectForKey:@"screenResolution"];
156
+ if (screenRSize != nil) {
157
+ NSNumber *resWidth = [screenRSize objectAtIndex:0];
158
+ NSNumber *resHeight = [screenRSize objectAtIndex:1];
159
+ CISSize *resSize = [[CISSize alloc] initWithWidth:[resWidth integerValue] height:[resHeight integerValue]];
160
+ subjectConfiguration.screenResolution = resSize;
161
+ }
162
+
163
+ // screenViewport - type checked RN side
164
+ NSArray *screenVPSize = [subjectConfig objectForKey:@"screenViewport"];
165
+ if (screenVPSize != nil) {
166
+ NSNumber *vpWidth = [screenVPSize objectAtIndex:0];
167
+ NSNumber *vpHeight = [screenVPSize objectAtIndex:1];
168
+ CISSize *vpSize = [[CISSize alloc] initWithWidth:[vpWidth integerValue] height:[vpHeight integerValue]];
169
+ subjectConfiguration.screenViewPort = vpSize;
170
+ }
171
+
172
+ // colorDepth
173
+ NSNumber *colorDepth = [subjectConfig rncat_numberForKey:@"colorDepth" defaultValue: nil];
174
+ if (colorDepth != nil) {
175
+ subjectConfiguration.colorDepth = colorDepth;
176
+ }
177
+
178
+ return subjectConfiguration;
179
+ }
180
+
181
+ + (CATGDPRConfiguration *) mkGdprConfig:(NSDictionary *) gdprConfig {
182
+ NSString *basis = [gdprConfig objectForKey:@"basisForProcessing"];
183
+ NSString *docId = [gdprConfig objectForKey:@"documentId"];
184
+ NSString *docVer = [gdprConfig objectForKey:@"documentVersion"];
185
+ NSString *docDesc = [gdprConfig objectForKey:@"documentDescription"];
186
+
187
+ CATGDPRConfiguration *gdprConfiguration = [[CATGDPRConfiguration alloc] initWithBasis:[RNUtilities getBasis:basis] documentId:docId documentVersion:docVer documentDescription:docDesc];
188
+
189
+ return gdprConfiguration;
190
+ }
191
+
192
+ + (CATGlobalContextsConfiguration *) mkGCConfig:(NSArray *) gcConfig {
193
+
194
+ CATGlobalContextsConfiguration *gcConfiguration = [[CATGlobalContextsConfiguration alloc] init];
195
+ //NSMutableDictionary *contextGens = [NSMutableDictionary dictionary];
196
+
197
+ for (NSDictionary *gcMap in gcConfig) {
198
+ NSString *itag = [gcMap objectForKey:@"tag"];
199
+ NSArray *globalContexts = [gcMap objectForKey:@"globalContexts"];
200
+
201
+ NSMutableArray *staticContexts = [NSMutableArray array];
202
+ for (NSDictionary *sdj in globalContexts) {
203
+ CATSelfDescribingJson *gContext = [[CATSelfDescribingJson alloc] initWithSchema:(NSString *)[sdj objectForKey:@"schema"]
204
+ andDictionary:(NSDictionary *)[sdj objectForKey:@"data"]];
205
+
206
+ [staticContexts addObject:gContext];
207
+ }
208
+
209
+ CATGlobalContext *gcStatic = [[CATGlobalContext alloc] initWithStaticContexts:(NSArray *)[staticContexts copy]];
210
+
211
+ [gcConfiguration addWithTag:itag contextGenerator:gcStatic];
212
+ }
213
+
214
+ return gcConfiguration;
215
+ }
216
+
217
+ @end
@@ -0,0 +1,27 @@
1
+ //
2
+ // RNTrackerVersion.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
+ #import <Foundation/Foundation.h>
22
+
23
+ @interface RNTrackerVersion : NSObject
24
+
25
+ extern NSString * const kRNTrackerVersion;
26
+
27
+ @end
@@ -0,0 +1,27 @@
1
+ //
2
+ // RNTrackerVersion.m
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
+ #import "RNTrackerVersion.h"
22
+
23
+ @implementation RNTrackerVersion
24
+
25
+ NSString * const kRNTrackerVersion = @"rn-0.1.2";
26
+
27
+ @end
@@ -0,0 +1,32 @@
1
+ //
2
+ // RNUtilities.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
+ #import <Foundation/Foundation.h>
22
+ #import <ConvivaAppAnalytics/CATGDPRConfiguration.h>
23
+
24
+ @interface RNUtilities : NSObject
25
+
26
+ + (NSDictionary *) removeNSNullFromDict:(NSDictionary *)trackerConfig;
27
+
28
+ + (CISGdprProcessingBasis) getBasis:(NSString *)basis;
29
+
30
+ + (NSMutableArray *) mkSDJArray:(NSArray<NSDictionary *> *)sdjArray;
31
+
32
+ @end
@@ -0,0 +1,68 @@
1
+ //
2
+ // RNUtilities.m
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 CATecific
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
+ #import "RNUtilities.h"
22
+ #import <Foundation/Foundation.h>
23
+ #import <ConvivaAppAnalytics/CATGDPRConfiguration.h>
24
+ #import <ConvivaAppAnalytics/CATSelfDescribingJson.h>
25
+
26
+ @implementation RNUtilities
27
+
28
+ + (NSDictionary *) removeNSNullFromDict:(NSDictionary *)dictionary {
29
+ const NSMutableDictionary *newDict = [dictionary mutableCopy];
30
+ const id nullPointer = [NSNull null];
31
+
32
+ for (NSString *key in dictionary) {
33
+ id obj = [dictionary objectForKey:key];
34
+ if (obj == nullPointer) {
35
+ [newDict removeObjectForKey:key];
36
+ }
37
+ }
38
+ return [NSDictionary dictionaryWithDictionary:[newDict copy]];
39
+ }
40
+
41
+ + (CISGdprProcessingBasis) getBasis:(NSString *)basis {
42
+ if ([basis isEqualToString:@"consent"]) {
43
+ return CISGdprProcessingBasisConsent;
44
+ } else if ([basis isEqualToString:@"contract"]) {
45
+ return CISGdprProcessingBasisContract;
46
+ } else if ([basis isEqualToString:@"legal_obligation"]) {
47
+ return CISGdprProcessingBasisLegalObligation;
48
+ } else if ([basis isEqualToString:@"legitimate_interests"]) {
49
+ return CISGdprProcessingBasisLegitimateInterests;
50
+ } else if ([basis isEqualToString:@"public_task"]) {
51
+ return CISGdprProcessingBasisPublicTask;
52
+ } else {
53
+ return CISGdprProcessingBasisVitalInterest;;
54
+ }
55
+ }
56
+
57
+ + (NSMutableArray *) mkSDJArray:(NSArray<NSDictionary *> *)sdjArray {
58
+ NSMutableArray *sdjs = [NSMutableArray array];
59
+ for (NSDictionary* sdj in sdjArray) {
60
+ CATSelfDescribingJson *nativeSdj = [[CATSelfDescribingJson alloc] initWithSchema:(NSString *)[sdj objectForKey:@"schema"]
61
+ andDictionary:(NSDictionary *)[sdj objectForKey:@"data"]];
62
+ [sdjs addObject:nativeSdj];
63
+ }
64
+
65
+ return sdjs;
66
+ }
67
+
68
+ @end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@convivainc/conviva-react-native-appanalytics",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Conviva React Native Application Analytics Library",
5
5
  "main": "conviva-react-native-appanalytics.js",
6
6
  "repository": {