@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/src/api.ts
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2020-2021 Snowplow Analytics Ltd. All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* This program is licensed to you under the Apache License Version 2.0,
|
|
5
|
-
* and you may not use this file except in compliance with the Apache License Version 2.0.
|
|
6
|
-
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
|
|
7
|
-
*
|
|
8
|
-
* Unless required by applicable law or agreed to in writing,
|
|
9
|
-
* software distributed under the Apache License Version 2.0 is distributed on an
|
|
10
|
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
'use strict';
|
|
15
|
-
|
|
16
|
-
import { NativeModules } from 'react-native';
|
|
17
|
-
import type {
|
|
18
|
-
InitTrackerConfig,
|
|
19
|
-
OptTrackerConfig,
|
|
20
|
-
SubjectData,
|
|
21
|
-
ScreenViewProps,
|
|
22
|
-
SelfDescribingProps,
|
|
23
|
-
StructuredProps,
|
|
24
|
-
PageViewProps,
|
|
25
|
-
EventContext,
|
|
26
|
-
} from './types';
|
|
27
|
-
|
|
28
|
-
const { RNSnowplowTracker } = NativeModules;
|
|
29
|
-
|
|
30
|
-
/*
|
|
31
|
-
* Initialize a tracker from specified argmap.
|
|
32
|
-
*
|
|
33
|
-
* @param argmap - The configuration to use for the tracker instance
|
|
34
|
-
* @returns - A promise fullfilled if the tracker is initialized
|
|
35
|
-
*/
|
|
36
|
-
function initializeTracker(argmap: InitTrackerConfig): Promise<void> {
|
|
37
|
-
|
|
38
|
-
const defaults: OptTrackerConfig = {// defaults for optional params
|
|
39
|
-
method: 'post',
|
|
40
|
-
protocol: 'https',
|
|
41
|
-
base64Encoded : true,
|
|
42
|
-
platformContext : true,
|
|
43
|
-
applicationContext : false,
|
|
44
|
-
lifecycleEvents : false,
|
|
45
|
-
screenContext : true,
|
|
46
|
-
sessionContext : true,
|
|
47
|
-
foregroundTimeout : 600,
|
|
48
|
-
backgroundTimeout : 300,
|
|
49
|
-
checkInterval : 15,
|
|
50
|
-
installTracking : false
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const ok = typeof argmap.endpoint !== 'undefined' && typeof argmap.appId !== 'undefined' && typeof argmap.namespace !== 'undefined';
|
|
54
|
-
|
|
55
|
-
if (ok) {
|
|
56
|
-
return <Promise<void>>Promise.resolve(
|
|
57
|
-
RNSnowplowTracker.initialize({...defaults, ...argmap})
|
|
58
|
-
);
|
|
59
|
-
} else {
|
|
60
|
-
const initReason = 'SnowplowTracker: initialize() requires endpoint, namespace and appId parameter to be set';
|
|
61
|
-
return Promise.reject(new Error(initReason));
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/*
|
|
66
|
-
* Sets or updates data for the Subject
|
|
67
|
-
*
|
|
68
|
-
* @param argmap - The subject data to be used
|
|
69
|
-
* @returns - A promise that is fullfilled if the Subject data is set
|
|
70
|
-
*/
|
|
71
|
-
function setSubjectData(argmap: SubjectData): Promise<void> {
|
|
72
|
-
return <Promise<void>>Promise.resolve(
|
|
73
|
-
RNSnowplowTracker.setSubjectData(argmap)
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/*
|
|
78
|
-
* Tracks a ScreenView event
|
|
79
|
-
*
|
|
80
|
-
* @param argmap - The ScreenView event's parameters
|
|
81
|
-
* @param ctxt - An array of contexts to be attached to the event
|
|
82
|
-
* @returns - A promise that is fullfilled if the event is tracked successfully
|
|
83
|
-
*/
|
|
84
|
-
function trackScreenViewEvent(
|
|
85
|
-
argmap: ScreenViewProps,
|
|
86
|
-
ctxt: EventContext[] = []
|
|
87
|
-
): Promise<void> {
|
|
88
|
-
if (typeof argmap.screenName !== 'undefined') {
|
|
89
|
-
return <Promise<void>>Promise.resolve(
|
|
90
|
-
RNSnowplowTracker.trackScreenViewEvent(argmap, ctxt)
|
|
91
|
-
);
|
|
92
|
-
} else {
|
|
93
|
-
const reason = 'SnowplowTracker: trackScreenViewEvent() requires screenName parameter to be set';
|
|
94
|
-
return Promise.reject(new Error(reason));
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/*
|
|
99
|
-
* Tracks a SelfDescribing event
|
|
100
|
-
*
|
|
101
|
-
* @param argmap - The SelfDescribing event's parameters
|
|
102
|
-
* @param ctxt - An array of contexts to be attached to the event
|
|
103
|
-
* @returns - A promise that is fullfilled if the event is tracked successfully
|
|
104
|
-
*/
|
|
105
|
-
function trackSelfDescribingEvent(
|
|
106
|
-
argmap: SelfDescribingProps,
|
|
107
|
-
ctxt: EventContext[] = []
|
|
108
|
-
): Promise<void> {
|
|
109
|
-
if (typeof argmap.schema !== 'undefined' && typeof argmap.data !== 'undefined') {
|
|
110
|
-
return <Promise<void>>Promise.resolve(
|
|
111
|
-
RNSnowplowTracker.trackSelfDescribingEvent(argmap, ctxt)
|
|
112
|
-
);
|
|
113
|
-
} else {
|
|
114
|
-
const reason = 'SnowplowTracker: trackSelfDescribingEvent() requires schema and data parameters to be set';
|
|
115
|
-
return Promise.reject(new Error(reason));
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/*
|
|
120
|
-
* Tracks a Structured event
|
|
121
|
-
*
|
|
122
|
-
* @param argmap - The Structured event's parameters
|
|
123
|
-
* @param ctxt - An array of contexts to be attached to the event
|
|
124
|
-
* @returns - A promise that is fullfilled if the event is tracked successfully
|
|
125
|
-
*/
|
|
126
|
-
function trackStructuredEvent(
|
|
127
|
-
argmap: StructuredProps,
|
|
128
|
-
ctxt: EventContext[] = []
|
|
129
|
-
): Promise<void> {
|
|
130
|
-
if (typeof argmap.category !== 'undefined' && typeof argmap.action !== 'undefined') {
|
|
131
|
-
return <Promise<void>>Promise.resolve(
|
|
132
|
-
RNSnowplowTracker.trackStructuredEvent(argmap, ctxt)
|
|
133
|
-
);
|
|
134
|
-
} else {
|
|
135
|
-
const reason = 'SnowplowTracker: trackStructuredEvent() requires category and action parameters to be set';
|
|
136
|
-
return Promise.reject(new Error(reason));
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/*
|
|
141
|
-
* Tracks a PageView event
|
|
142
|
-
*
|
|
143
|
-
* @param argmap - The PageView event's parameters
|
|
144
|
-
* @param ctxt - An array of contexts to be attached to the event
|
|
145
|
-
* @returns - A promise that is fullfilled if the event is tracked successfully
|
|
146
|
-
*/
|
|
147
|
-
function trackPageViewEvent(
|
|
148
|
-
argmap: PageViewProps,
|
|
149
|
-
ctxt: EventContext[] = []
|
|
150
|
-
): Promise<void> {
|
|
151
|
-
if (typeof argmap.pageUrl !== 'undefined') {
|
|
152
|
-
return <Promise<void>>Promise.resolve(
|
|
153
|
-
RNSnowplowTracker.trackPageViewEvent(argmap, ctxt)
|
|
154
|
-
);
|
|
155
|
-
} else {
|
|
156
|
-
const reason = 'SnowplowTracker: trackPageViewEvent() requires pageUrl parameter to be set';
|
|
157
|
-
return Promise.reject(new Error(reason));
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export {
|
|
162
|
-
initializeTracker,
|
|
163
|
-
setSubjectData,
|
|
164
|
-
trackScreenViewEvent,
|
|
165
|
-
trackSelfDescribingEvent,
|
|
166
|
-
trackStructuredEvent,
|
|
167
|
-
trackPageViewEvent,
|
|
168
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2020-2021 Snowplow Analytics Ltd. All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* This program is licensed to you under the Apache License Version 2.0,
|
|
5
|
-
* and you may not use this file except in compliance with the Apache License Version 2.0.
|
|
6
|
-
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
|
|
7
|
-
*
|
|
8
|
-
* Unless required by applicable law or agreed to in writing,
|
|
9
|
-
* software distributed under the Apache License Version 2.0 is distributed on an
|
|
10
|
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
'use strict';
|
|
15
|
-
|
|
16
|
-
import * as api from './api';
|
|
17
|
-
import { safeWait, errorHandler } from './utils';
|
|
18
|
-
|
|
19
|
-
import type { TrackerConfig, ReactNativeTracker } from './types';
|
|
20
|
-
|
|
21
|
-
/*
|
|
22
|
-
* Creates a React Native Tracker object
|
|
23
|
-
*
|
|
24
|
-
* @param namespace - The tracker namespace
|
|
25
|
-
* @param config - The configuration to be used for the tracker
|
|
26
|
-
* @returns The tracker object
|
|
27
|
-
*/
|
|
28
|
-
function createTracker(
|
|
29
|
-
namespace: string,
|
|
30
|
-
config: TrackerConfig
|
|
31
|
-
): ReactNativeTracker {
|
|
32
|
-
// initTrackerPromise
|
|
33
|
-
const initTrackerPromise: Promise<void> = Promise.resolve(
|
|
34
|
-
api.initializeTracker({
|
|
35
|
-
...config,
|
|
36
|
-
namespace,
|
|
37
|
-
})
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
// mkMethod creates methods subscribed to the initTrackerPromise
|
|
41
|
-
const mkMethod = safeWait(initTrackerPromise, errorHandler);
|
|
42
|
-
|
|
43
|
-
// tracker methods
|
|
44
|
-
const setSubjectData = mkMethod(api.setSubjectData);
|
|
45
|
-
const trackScreenViewEvent = mkMethod(api.trackScreenViewEvent);
|
|
46
|
-
const trackSelfDescribingEvent = mkMethod(api.trackSelfDescribingEvent);
|
|
47
|
-
const trackStructuredEvent = mkMethod(api.trackStructuredEvent);
|
|
48
|
-
const trackPageViewEvent = mkMethod(api.trackPageViewEvent);
|
|
49
|
-
|
|
50
|
-
return Object.freeze({
|
|
51
|
-
setSubjectData,
|
|
52
|
-
trackScreenViewEvent,
|
|
53
|
-
trackSelfDescribingEvent,
|
|
54
|
-
trackStructuredEvent,
|
|
55
|
-
trackPageViewEvent,
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export { createTracker };
|
|
60
|
-
export type {
|
|
61
|
-
ReactNativeTracker,
|
|
62
|
-
TrackerConfig,
|
|
63
|
-
HttpMethod,
|
|
64
|
-
HttpProtocol,
|
|
65
|
-
SubjectData,
|
|
66
|
-
ScreenViewProps,
|
|
67
|
-
SelfDescribingProps,
|
|
68
|
-
StructuredProps,
|
|
69
|
-
PageViewProps,
|
|
70
|
-
EventContext
|
|
71
|
-
} from './types';
|
package/src/types.ts
DELETED
|
@@ -1,325 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2020-2021 Snowplow Analytics Ltd. All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* This program is licensed to you under the Apache License Version 2.0,
|
|
5
|
-
* and you may not use this file except in compliance with the Apache License Version 2.0.
|
|
6
|
-
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
|
|
7
|
-
*
|
|
8
|
-
* Unless required by applicable law or agreed to in writing,
|
|
9
|
-
* software distributed under the Apache License Version 2.0 is distributed on an
|
|
10
|
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* HttpMethod type
|
|
16
|
-
*/
|
|
17
|
-
export type HttpMethod = 'post' | 'get';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* HttpProtocol type
|
|
21
|
-
*/
|
|
22
|
-
export type HttpProtocol = 'https' | 'http';
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* The Subject Data
|
|
26
|
-
*/
|
|
27
|
-
export type SubjectData = {
|
|
28
|
-
/**
|
|
29
|
-
* user id
|
|
30
|
-
*/
|
|
31
|
-
userId?: string;
|
|
32
|
-
/**
|
|
33
|
-
* screen width (integer)
|
|
34
|
-
*/
|
|
35
|
-
screenWidth?: number;
|
|
36
|
-
/**
|
|
37
|
-
* screen height (integer)
|
|
38
|
-
*/
|
|
39
|
-
screenHeight?: number;
|
|
40
|
-
/**
|
|
41
|
-
* color depth (integer)
|
|
42
|
-
*/
|
|
43
|
-
colorDepth?: number;
|
|
44
|
-
/**
|
|
45
|
-
* timezone
|
|
46
|
-
*/
|
|
47
|
-
timezone?: string;
|
|
48
|
-
/**
|
|
49
|
-
* language
|
|
50
|
-
*/
|
|
51
|
-
language?: string;
|
|
52
|
-
/**
|
|
53
|
-
* IP address
|
|
54
|
-
*/
|
|
55
|
-
ipAddress?: string;
|
|
56
|
-
/**
|
|
57
|
-
* user agent
|
|
58
|
-
*/
|
|
59
|
-
useragent?: string;
|
|
60
|
-
/**
|
|
61
|
-
* network user id (UUIDv4)
|
|
62
|
-
*/
|
|
63
|
-
networkUserId?: string;
|
|
64
|
-
/**
|
|
65
|
-
* domain user id
|
|
66
|
-
*/
|
|
67
|
-
domainUserId?: string;
|
|
68
|
-
/**
|
|
69
|
-
* viewport width (integer)
|
|
70
|
-
*/
|
|
71
|
-
viewportWidth?: number;
|
|
72
|
-
/**
|
|
73
|
-
* viewport height (integer)
|
|
74
|
-
*/
|
|
75
|
-
viewportHeight?: number;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* ScreenView event properties
|
|
80
|
-
* schema: iglu:com.snowplowanalytics.mobile/screen_view/jsonschema/1-0-0
|
|
81
|
-
*/
|
|
82
|
-
export type ScreenViewProps = {
|
|
83
|
-
/**
|
|
84
|
-
* The name of the screen viewed
|
|
85
|
-
*/
|
|
86
|
-
screenName: string;
|
|
87
|
-
/**
|
|
88
|
-
* The type of screen that was viewed
|
|
89
|
-
*/
|
|
90
|
-
screenType?: string;
|
|
91
|
-
/**
|
|
92
|
-
* The type of transition that led to the screen being viewed
|
|
93
|
-
*/
|
|
94
|
-
transitionType?: string;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* SelfDescribing event properties
|
|
99
|
-
*/
|
|
100
|
-
export type SelfDescribingProps = {
|
|
101
|
-
/**
|
|
102
|
-
* The schema of the event
|
|
103
|
-
*/
|
|
104
|
-
schema: string;
|
|
105
|
-
/**
|
|
106
|
-
* The event data
|
|
107
|
-
*/
|
|
108
|
-
data: Record<string, unknown>;
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Structured event properties
|
|
113
|
-
*/
|
|
114
|
-
export type StructuredProps = {
|
|
115
|
-
/**
|
|
116
|
-
* The category of the event
|
|
117
|
-
*/
|
|
118
|
-
category: string;
|
|
119
|
-
/**
|
|
120
|
-
* The action the event represents
|
|
121
|
-
*/
|
|
122
|
-
action: string;
|
|
123
|
-
/**
|
|
124
|
-
* The label the action refers to
|
|
125
|
-
*/
|
|
126
|
-
label?: string;
|
|
127
|
-
/**
|
|
128
|
-
* The property associated with the user action
|
|
129
|
-
*/
|
|
130
|
-
property?: string;
|
|
131
|
-
/**
|
|
132
|
-
* The value associated with the user action
|
|
133
|
-
*/
|
|
134
|
-
value?: number;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* PageView event properties
|
|
139
|
-
*/
|
|
140
|
-
export type PageViewProps = {
|
|
141
|
-
/**
|
|
142
|
-
* The page URL
|
|
143
|
-
*/
|
|
144
|
-
pageUrl: string;
|
|
145
|
-
/**
|
|
146
|
-
* The page title
|
|
147
|
-
*/
|
|
148
|
-
pageTitle?: string;
|
|
149
|
-
/**
|
|
150
|
-
* The referrer URL
|
|
151
|
-
*/
|
|
152
|
-
pageReferrer?: string;
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Context type
|
|
157
|
-
*/
|
|
158
|
-
export type EventContext = {
|
|
159
|
-
/**
|
|
160
|
-
* The context schema
|
|
161
|
-
*/
|
|
162
|
-
schema: string;
|
|
163
|
-
/**
|
|
164
|
-
* The context data
|
|
165
|
-
*/
|
|
166
|
-
data: Record<string, unknown>;
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* The ReactNativeTracker type
|
|
171
|
-
*/
|
|
172
|
-
export type ReactNativeTracker = {
|
|
173
|
-
/**
|
|
174
|
-
* Sets or updates subject data
|
|
175
|
-
*
|
|
176
|
-
* @param argmap - The subject data to be set or updated
|
|
177
|
-
*/
|
|
178
|
-
readonly setSubjectData: (argmap: SubjectData) => Promise<void>;
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Tracks a screen-view event
|
|
182
|
-
*
|
|
183
|
-
* @param argmap - The screen-view event's properties
|
|
184
|
-
* @param ctxt - The array of event contexts
|
|
185
|
-
*/
|
|
186
|
-
readonly trackScreenViewEvent: (
|
|
187
|
-
argmap: ScreenViewProps,
|
|
188
|
-
ctxt?: EventContext[]
|
|
189
|
-
) => Promise<void>;
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Tracks a self-descibing event
|
|
193
|
-
*
|
|
194
|
-
* @param argmap - The self-describing event properties
|
|
195
|
-
* @param ctxt - The array of event contexts
|
|
196
|
-
*/
|
|
197
|
-
readonly trackSelfDescribingEvent: (
|
|
198
|
-
argmap: SelfDescribingProps,
|
|
199
|
-
ctxt: EventContext[]
|
|
200
|
-
) => Promise<void>;
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Tracks a structured event
|
|
204
|
-
*
|
|
205
|
-
* @param argmap - The structured event properties
|
|
206
|
-
* @param ctxt - The array of event contexts
|
|
207
|
-
*/
|
|
208
|
-
readonly trackStructuredEvent: (
|
|
209
|
-
argmap: StructuredProps,
|
|
210
|
-
ctxt: EventContext[]
|
|
211
|
-
) => Promise<void>;
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Tracks a page-view event
|
|
215
|
-
*
|
|
216
|
-
* @param argmap - The page-view event properties
|
|
217
|
-
* @param ctxt - The array of event contexts
|
|
218
|
-
*/
|
|
219
|
-
readonly trackPageViewEvent: (
|
|
220
|
-
argmap: PageViewProps,
|
|
221
|
-
ctxt: EventContext[]
|
|
222
|
-
) => Promise<void>;
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* The optional configuration parameters of the tracker
|
|
227
|
-
*/
|
|
228
|
-
export interface OptTrackerConfig {
|
|
229
|
-
/**
|
|
230
|
-
* The HTTP method used
|
|
231
|
-
* @defaultValue 'post'
|
|
232
|
-
*/
|
|
233
|
-
method?: HttpMethod;
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* The HTTP protocol used
|
|
237
|
-
* @defaultValue 'https'
|
|
238
|
-
*/
|
|
239
|
-
protocol?: HttpProtocol;
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Should event properties be base64 encoded where supported
|
|
243
|
-
* @defaultValue true
|
|
244
|
-
*/
|
|
245
|
-
base64Encoded?: boolean;
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Whether platform context are sent with all events
|
|
249
|
-
* @defaultValue true
|
|
250
|
-
*/
|
|
251
|
-
platformContext?: boolean;
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Whether application context are sent with all events
|
|
255
|
-
* @defaultValue false
|
|
256
|
-
*/
|
|
257
|
-
applicationContext?: boolean;
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Whether to automatically track transition from foreground to background
|
|
261
|
-
* @defaultValue false
|
|
262
|
-
*/
|
|
263
|
-
lifecycleEvents?: boolean;
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* Whether to send a screen context (info for current screen) to events
|
|
267
|
-
* @defaultValue true
|
|
268
|
-
*/
|
|
269
|
-
screenContext?: boolean;
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* whether to add a session context to events
|
|
273
|
-
* @defaultValue true
|
|
274
|
-
*/
|
|
275
|
-
sessionContext?: boolean;
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* The session foreground timeout
|
|
279
|
-
* @defaultValue 600
|
|
280
|
-
*/
|
|
281
|
-
foregroundTimeout?: number;
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* The session background timeout
|
|
285
|
-
* @defaultValue 300
|
|
286
|
-
*/
|
|
287
|
-
backgroundTimeout?: number;
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* The session check interval
|
|
291
|
-
* @defaultValue 15
|
|
292
|
-
*/
|
|
293
|
-
checkInterval?: number;
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* Whether install events will be tracked
|
|
297
|
-
* @defaultValue false
|
|
298
|
-
*/
|
|
299
|
-
installTracking?: boolean;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* The configuration used for creating the tracker
|
|
304
|
-
*/
|
|
305
|
-
export interface TrackerConfig extends OptTrackerConfig {
|
|
306
|
-
/**
|
|
307
|
-
* The collector endpoint
|
|
308
|
-
*/
|
|
309
|
-
endpoint: string;
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
* The app ID
|
|
313
|
-
*/
|
|
314
|
-
appId: string;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* The tracker configuration
|
|
319
|
-
*/
|
|
320
|
-
export interface InitTrackerConfig extends TrackerConfig {
|
|
321
|
-
/**
|
|
322
|
-
* The tracker namespace
|
|
323
|
-
*/
|
|
324
|
-
namespace: string;
|
|
325
|
-
}
|
package/src/utils.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2020-2021 Snowplow Analytics Ltd. All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* This program is licensed to you under the Apache License Version 2.0,
|
|
5
|
-
* and you may not use this file except in compliance with the Apache License Version 2.0.
|
|
6
|
-
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
|
|
7
|
-
*
|
|
8
|
-
* Unless required by applicable law or agreed to in writing,
|
|
9
|
-
* software distributed under the Apache License Version 2.0 is distributed on an
|
|
10
|
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
'use strict';
|
|
15
|
-
|
|
16
|
-
/*
|
|
17
|
-
* Returns a function that accepts a function as its argument and subscribes
|
|
18
|
-
* that function to aPromise's fullfillment,
|
|
19
|
-
* and errHandle to aPromise's rejection.
|
|
20
|
-
*
|
|
21
|
-
* @param aPromise - A Promise
|
|
22
|
-
* @param errHandle - A function to handle the promise being rejected
|
|
23
|
-
* @returns - A function subscribed to the Promise's fullfillment
|
|
24
|
-
*/
|
|
25
|
-
function safeWait(aPromise: Promise<void>, errHandle: ((err: Error) => void)) {
|
|
26
|
-
return (<F extends ((...args: never[]) => Promise<void>)>(func: F) => {
|
|
27
|
-
return (...args: Parameters<F>): Promise<void> => {
|
|
28
|
-
return aPromise.then(() => func(...args)).catch((err) => errHandle(err));
|
|
29
|
-
};
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/*
|
|
34
|
-
* Handles an error.
|
|
35
|
-
*
|
|
36
|
-
* @param err - The error to be handled.
|
|
37
|
-
*/
|
|
38
|
-
function errorHandler(err: Error): void {
|
|
39
|
-
if (__DEV__) {
|
|
40
|
-
console.warn(err.message);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export {
|
|
45
|
-
safeWait,
|
|
46
|
-
errorHandler,
|
|
47
|
-
};
|