coveo.analytics 2.30.56 → 2.32.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/README.md +37 -43
- package/dist/browser.mjs +513 -357
- package/dist/coveoua.browser.js +1 -1
- package/dist/coveoua.browser.js.map +1 -1
- package/dist/coveoua.debug.js +542 -359
- package/dist/coveoua.debug.js.map +1 -1
- package/dist/coveoua.js +1 -1
- package/dist/coveoua.js.map +1 -1
- package/dist/definitions/client/analytics.d.ts +3 -2
- package/dist/definitions/client/runtimeEnvironment.d.ts +1 -1
- package/dist/definitions/donottrack.d.ts +1 -0
- package/dist/definitions/react-native/index.d.ts +1 -2
- package/dist/definitions/version.d.ts +1 -1
- package/dist/library.cjs +15350 -3699
- package/dist/library.es.js +513 -357
- package/dist/library.js +15350 -3699
- package/dist/library.mjs +15350 -3699
- package/dist/react-native.es.js +634 -460
- package/modules/package.json +9 -9
- package/package.json +60 -91
- package/react-native/package.json +7 -7
- package/src/caseAssist/caseAssistActions.ts +51 -50
- package/src/caseAssist/caseAssistClient.spec.ts +328 -297
- package/src/caseAssist/caseAssistClient.ts +201 -185
- package/src/client/analytics.spec.ts +724 -703
- package/src/client/analytics.ts +677 -602
- package/src/client/analyticsBeaconClient.spec.ts +195 -188
- package/src/client/analyticsBeaconClient.ts +99 -88
- package/src/client/analyticsFetchClient.ts +77 -61
- package/src/client/analyticsRequestClient.ts +17 -17
- package/src/client/location.ts +3 -3
- package/src/client/measurementProtocolMapper.ts +54 -45
- package/src/client/measurementProtocolMapping/baseMeasurementProtocolMapper.ts +48 -44
- package/src/client/measurementProtocolMapping/commerceMeasurementProtocolMapper.ts +133 -121
- package/src/client/measurementProtocolMapping/serviceMeasurementProtocolMapper.ts +17 -17
- package/src/client/noopAnalytics.ts +80 -68
- package/src/client/runtimeEnvironment.ts +50 -41
- package/src/client/utils.spec.ts +112 -97
- package/src/client/utils.ts +39 -39
- package/src/cookieutils.spec.ts +59 -0
- package/src/cookieutils.ts +40 -39
- package/src/coveoua/browser.ts +14 -12
- package/src/coveoua/library.ts +4 -4
- package/src/coveoua/plugins.ts +36 -34
- package/src/coveoua/simpleanalytics.spec.ts +467 -452
- package/src/coveoua/simpleanalytics.ts +146 -140
- package/src/detector.ts +17 -17
- package/src/donottrack.spec.ts +199 -121
- package/src/donottrack.ts +31 -8
- package/src/events.ts +86 -79
- package/src/formatting/format-array-for-coveo-custom-data.spec.ts +13 -12
- package/src/formatting/format-array-for-coveo-custom-data.ts +18 -18
- package/src/formatting/format-omnibox-metadata.ts +16 -12
- package/src/history.spec.ts +197 -195
- package/src/history.ts +143 -133
- package/src/hook/addDefaultValues.ts +13 -8
- package/src/hook/enhanceViewEvent.ts +17 -17
- package/src/insight/insightClient.spec.ts +1848 -1717
- package/src/insight/insightClient.ts +866 -761
- package/src/insight/insightEvents.ts +57 -56
- package/src/plugins/BasePlugin.ts +125 -121
- package/src/plugins/ec.spec.ts +457 -429
- package/src/plugins/ec.ts +202 -199
- package/src/plugins/link.spec.ts +183 -159
- package/src/plugins/link.ts +88 -85
- package/src/plugins/svc.spec.ts +161 -155
- package/src/plugins/svc.ts +93 -91
- package/src/react-native/index.ts +8 -1
- package/src/react-native/react-native-runtime.ts +33 -33
- package/src/react-native/react-native-utils.ts +1 -1
- package/src/react-native/react-native.spec.ts +31 -21
- package/src/searchPage/searchPageClient.spec.ts +1944 -1794
- package/src/searchPage/searchPageClient.ts +1261 -1040
- package/src/searchPage/searchPageEvents.ts +524 -511
- package/src/storage.spec.ts +51 -51
- package/src/storage.ts +47 -47
- package/dist/definitions/bundle/browser-fetch.d.ts +0 -1
- package/dist/definitions/src/coveoua/browser.d.ts +0 -6
- package/dist/definitions/src/coveoua/headless.d.ts +0 -6
- package/dist/definitions/src/coveoua/library.d.ts +0 -17
- package/dist/definitions/src/coveoua/plugins.d.ts +0 -10
- package/dist/definitions/src/coveoua/simpleanalytics.d.ts +0 -33
- package/dist/definitions/src/react-native/index.d.ts +0 -3
- package/dist/definitions/src/react-native/react-native-runtime.d.ts +0 -19
|
@@ -3,170 +3,182 @@ import {keysOf} from '../utils';
|
|
|
3
3
|
|
|
4
4
|
// Based off: https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#enhanced-ecomm
|
|
5
5
|
const productKeysMapping: {[key in keyof Product]: string} = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
id: 'id',
|
|
7
|
+
name: 'nm',
|
|
8
|
+
brand: 'br',
|
|
9
|
+
category: 'ca',
|
|
10
|
+
variant: 'va',
|
|
11
|
+
price: 'pr',
|
|
12
|
+
quantity: 'qt',
|
|
13
|
+
coupon: 'cc',
|
|
14
|
+
position: 'ps',
|
|
15
|
+
// Below are keys that were extended for Coveo
|
|
16
|
+
group: 'group',
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
const impressionKeysMapping: {[key in keyof BaseImpression]: string} = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
id: 'id',
|
|
21
|
+
name: 'nm',
|
|
22
|
+
brand: 'br',
|
|
23
|
+
category: 'ca',
|
|
24
|
+
variant: 'va',
|
|
25
|
+
position: 'ps',
|
|
26
|
+
price: 'pr',
|
|
27
|
+
// Below are keys that were extended for Coveo
|
|
28
|
+
group: 'group',
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
const productActionsKeysMapping: {[name: string]: string} = {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
action: 'pa',
|
|
33
|
+
list: 'pal',
|
|
34
|
+
listSource: 'pls',
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
const transactionActionsKeysMapping: {[name: string]: string} = {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
id: 'ti',
|
|
39
|
+
revenue: 'tr',
|
|
40
|
+
tax: 'tt',
|
|
41
|
+
shipping: 'ts',
|
|
42
|
+
coupon: 'tcc',
|
|
43
|
+
affiliation: 'ta',
|
|
44
|
+
step: 'cos',
|
|
45
|
+
option: 'col',
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
// These extension keys do not have direct mappings, we are sending them as-is, thus only requiring an array.
|
|
49
49
|
const coveoCommerceExtensionKeys: string[] = [
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
50
|
+
'loyaltyCardId',
|
|
51
|
+
'loyaltyTier',
|
|
52
|
+
'thirdPartyPersona',
|
|
53
|
+
'companyName',
|
|
54
|
+
'favoriteStore',
|
|
55
|
+
'storeName',
|
|
56
|
+
'userIndustry',
|
|
57
|
+
'userRole',
|
|
58
|
+
'userDepartment',
|
|
59
|
+
'businessUnit',
|
|
60
60
|
];
|
|
61
61
|
|
|
62
62
|
const quoteActionsKeysMapping: {[name: string]: string} = {
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
id: 'quoteId',
|
|
64
|
+
affiliation: 'quoteAffiliation',
|
|
65
65
|
};
|
|
66
66
|
|
|
67
67
|
const reviewActionsKeysMapping: {[name: string]: string} = {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
id: 'reviewId',
|
|
69
|
+
rating: 'reviewRating',
|
|
70
|
+
comment: 'reviewComment',
|
|
71
71
|
};
|
|
72
72
|
|
|
73
73
|
export const commerceActionKeysMappingPerAction: Record<string, {[name: string]: string}> = {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
74
|
+
add: productActionsKeysMapping,
|
|
75
|
+
bookmark_add: productActionsKeysMapping,
|
|
76
|
+
bookmark_remove: productActionsKeysMapping,
|
|
77
|
+
click: productActionsKeysMapping,
|
|
78
|
+
checkout: productActionsKeysMapping,
|
|
79
|
+
checkout_option: productActionsKeysMapping,
|
|
80
|
+
detail: productActionsKeysMapping,
|
|
81
|
+
impression: productActionsKeysMapping,
|
|
82
|
+
remove: productActionsKeysMapping,
|
|
83
|
+
refund: {
|
|
84
|
+
...productActionsKeysMapping,
|
|
85
|
+
...transactionActionsKeysMapping,
|
|
86
|
+
},
|
|
87
|
+
purchase: {
|
|
88
|
+
...productActionsKeysMapping,
|
|
89
|
+
...transactionActionsKeysMapping,
|
|
90
|
+
},
|
|
91
|
+
quickview: productActionsKeysMapping,
|
|
92
|
+
quote: {
|
|
93
|
+
...productActionsKeysMapping,
|
|
94
|
+
...quoteActionsKeysMapping,
|
|
95
|
+
},
|
|
96
|
+
review: {
|
|
97
|
+
...productActionsKeysMapping,
|
|
98
|
+
...reviewActionsKeysMapping,
|
|
99
|
+
},
|
|
100
100
|
};
|
|
101
101
|
|
|
102
102
|
export const convertProductToMeasurementProtocol = (product: Product, index: number) => {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
103
|
+
return keysOf(product).reduce((mappedProduct, key) => {
|
|
104
|
+
const newKey = `pr${index + 1}${productKeysMapping[key] || key}`;
|
|
105
|
+
return {
|
|
106
|
+
...mappedProduct,
|
|
107
|
+
[newKey]: product[key],
|
|
108
|
+
};
|
|
109
|
+
}, {});
|
|
110
110
|
};
|
|
111
111
|
|
|
112
112
|
export const convertImpressionListToMeasurementProtocol = (
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
impressionList: ImpressionList,
|
|
114
|
+
listIndex: number,
|
|
115
|
+
prefix: string
|
|
116
116
|
) => {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
117
|
+
const payload: {[name: string]: any} = impressionList.impressions.reduce(
|
|
118
|
+
(mappedImpressions, impression, productIndex) => {
|
|
119
|
+
return {
|
|
120
|
+
...mappedImpressions,
|
|
121
|
+
...convertImpressionToMeasurementProtocol(impression, listIndex, productIndex, prefix),
|
|
122
|
+
};
|
|
123
|
+
},
|
|
124
|
+
{}
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
if (impressionList.listName) {
|
|
128
|
+
const listNameKey = `il${listIndex + 1}nm`;
|
|
129
|
+
payload[listNameKey] = impressionList.listName;
|
|
130
|
+
}
|
|
131
|
+
return payload;
|
|
132
132
|
};
|
|
133
133
|
|
|
134
134
|
const convertImpressionToMeasurementProtocol = (
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
135
|
+
impression: BaseImpression,
|
|
136
|
+
listIndex: number,
|
|
137
|
+
productIndex: number,
|
|
138
|
+
prefix: string
|
|
139
139
|
) => {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
140
|
+
return keysOf(impression).reduce((mappedImpression, key) => {
|
|
141
|
+
const newKey = `il${listIndex + 1}${prefix}${productIndex + 1}${impressionKeysMapping[key] || key}`;
|
|
142
|
+
return {
|
|
143
|
+
...mappedImpression,
|
|
144
|
+
[newKey]: impression[key],
|
|
145
|
+
};
|
|
146
|
+
}, {});
|
|
147
147
|
};
|
|
148
148
|
|
|
149
149
|
const productKeysMappingValues = keysOf(productKeysMapping).map((key) => productKeysMapping[key]);
|
|
150
|
-
const impressionKeysMappingValues = keysOf(impressionKeysMapping).map(
|
|
151
|
-
|
|
150
|
+
const impressionKeysMappingValues = keysOf(impressionKeysMapping).map(
|
|
151
|
+
(key) => impressionKeysMapping[key]
|
|
152
|
+
);
|
|
153
|
+
const productActionsKeysMappingValues = keysOf(productActionsKeysMapping).map(
|
|
154
|
+
(key) => productActionsKeysMapping[key]
|
|
155
|
+
);
|
|
152
156
|
const transactionActionsKeysMappingValues = keysOf(transactionActionsKeysMapping).map(
|
|
153
|
-
|
|
157
|
+
(key) => transactionActionsKeysMapping[key]
|
|
158
|
+
);
|
|
159
|
+
const reviewKeysMappingValues = keysOf(reviewActionsKeysMapping).map(
|
|
160
|
+
(key) => reviewActionsKeysMapping[key]
|
|
161
|
+
);
|
|
162
|
+
const quoteKeysMappingValues = keysOf(quoteActionsKeysMapping).map(
|
|
163
|
+
(key) => quoteActionsKeysMapping[key]
|
|
154
164
|
);
|
|
155
|
-
const reviewKeysMappingValues = keysOf(reviewActionsKeysMapping).map((key) => reviewActionsKeysMapping[key]);
|
|
156
|
-
const quoteKeysMappingValues = keysOf(quoteActionsKeysMapping).map((key) => quoteActionsKeysMapping[key]);
|
|
157
165
|
|
|
158
166
|
const productSubKeysMatchGroup = [...productKeysMappingValues, 'custom'].join('|');
|
|
159
167
|
const impressionSubKeysMatchGroup = [...impressionKeysMappingValues, 'custom'].join('|');
|
|
160
168
|
const productPrefixMatchGroup = '(pr[0-9]+)';
|
|
161
169
|
const impressionPrefixMatchGroup = '(il[0-9]+pi[0-9]+)';
|
|
162
170
|
const productKeyRegex = new RegExp(`^${productPrefixMatchGroup}(${productSubKeysMatchGroup})$`);
|
|
163
|
-
const impressionKeyRegex = new RegExp(
|
|
171
|
+
const impressionKeyRegex = new RegExp(
|
|
172
|
+
`^(${impressionPrefixMatchGroup}(${impressionSubKeysMatchGroup}))|(il[0-9]+nm)$`
|
|
173
|
+
);
|
|
164
174
|
const productActionsKeyRegex = new RegExp(`^(${productActionsKeysMappingValues.join('|')})$`);
|
|
165
|
-
const transactionActionsKeyRegex = new RegExp(
|
|
175
|
+
const transactionActionsKeyRegex = new RegExp(
|
|
176
|
+
`^(${transactionActionsKeysMappingValues.join('|')})$`
|
|
177
|
+
);
|
|
166
178
|
const customProductKeyRegex = new RegExp(`^${productPrefixMatchGroup}custom$`);
|
|
167
179
|
const customImpressionKeyRegex = new RegExp(`^${impressionPrefixMatchGroup}custom$`);
|
|
168
180
|
const coveoCommerceExtensionKeysRegex = new RegExp(
|
|
169
|
-
|
|
181
|
+
`^(${[...coveoCommerceExtensionKeys, ...reviewKeysMappingValues, ...quoteKeysMappingValues].join('|')})$`
|
|
170
182
|
);
|
|
171
183
|
|
|
172
184
|
const isProductKey = (key: string) => productKeyRegex.test(key);
|
|
@@ -176,10 +188,10 @@ const isTransactionActionsKeyRegex = (key: string) => transactionActionsKeyRegex
|
|
|
176
188
|
const isCoveoCommerceExtensionKey = (key: string) => coveoCommerceExtensionKeysRegex.test(key);
|
|
177
189
|
|
|
178
190
|
export const isCommerceKey = [
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
191
|
+
isImpressionKey,
|
|
192
|
+
isProductKey,
|
|
193
|
+
isProductActionsKey,
|
|
194
|
+
isTransactionActionsKeyRegex,
|
|
195
|
+
isCoveoCommerceExtensionKey,
|
|
184
196
|
];
|
|
185
197
|
export const isCustomCommerceKey = [customProductKeyRegex, customImpressionKeyRegex];
|
|
@@ -2,32 +2,32 @@ import {Ticket} from '../../plugins/svc';
|
|
|
2
2
|
import {keysOf} from '../utils';
|
|
3
3
|
|
|
4
4
|
const ticketKeysMapping: {[key in keyof Ticket]: string} = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
id: 'svc_ticket_id',
|
|
6
|
+
subject: 'svc_ticket_subject',
|
|
7
|
+
description: 'svc_ticket_description',
|
|
8
|
+
category: 'svc_ticket_category',
|
|
9
|
+
productId: 'svc_ticket_product_id',
|
|
10
|
+
custom: 'svc_ticket_custom',
|
|
11
11
|
};
|
|
12
12
|
const ticketKeysMappingValues = keysOf(ticketKeysMapping).map((key) => ticketKeysMapping[key]);
|
|
13
13
|
const ticketSubKeysMatchGroup = [...ticketKeysMappingValues].join('|');
|
|
14
14
|
const ticketKeyRegex = new RegExp(`^(${ticketSubKeysMatchGroup}$)`);
|
|
15
15
|
|
|
16
16
|
export const serviceActionsKeysMapping: {[name: string]: string} = {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
svcAction: 'svc_action',
|
|
18
|
+
svcActionData: 'svc_action_data',
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
export const convertTicketToMeasurementProtocol = (ticket: Ticket) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
return keysOf(ticket)
|
|
23
|
+
.filter((key) => ticket[key] !== undefined)
|
|
24
|
+
.reduce((mappedTicket, key) => {
|
|
25
|
+
const newKey = ticketKeysMapping[key] || key;
|
|
26
|
+
return {
|
|
27
|
+
...mappedTicket,
|
|
28
|
+
[newKey]: ticket[key],
|
|
29
|
+
};
|
|
30
|
+
}, {});
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
const isTicketKey = (key: string) => ticketKeyRegex.test(key);
|
|
@@ -1,76 +1,88 @@
|
|
|
1
1
|
import {AnalyticsClient, PreparedEvent} from './analytics';
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
3
|
+
AnyEventResponse,
|
|
4
|
+
SearchEventResponse,
|
|
5
|
+
ClickEventResponse,
|
|
6
|
+
CustomEventResponse,
|
|
7
|
+
VisitResponse,
|
|
8
|
+
HealthResponse,
|
|
9
|
+
ViewEventResponse,
|
|
10
|
+
EventType,
|
|
11
|
+
PreparedSearchEventRequest,
|
|
12
|
+
SearchEventRequest,
|
|
13
|
+
ClickEventRequest,
|
|
14
|
+
CustomEventRequest,
|
|
15
|
+
PreparedClickEventRequest,
|
|
16
|
+
PreparedCustomEventRequest,
|
|
17
|
+
PreparedViewEventRequest,
|
|
18
|
+
ViewEventRequest,
|
|
19
19
|
} from '../events';
|
|
20
20
|
import {libVersion} from '../version';
|
|
21
21
|
import {NoopRuntime} from './runtimeEnvironment';
|
|
22
22
|
|
|
23
23
|
export class NoopAnalytics implements AnalyticsClient {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
24
|
+
getPayload(): Promise<any> {
|
|
25
|
+
return Promise.resolve();
|
|
26
|
+
}
|
|
27
|
+
getParameters(): Promise<any> {
|
|
28
|
+
return Promise.resolve();
|
|
29
|
+
}
|
|
30
|
+
makeEvent<TPreparedRequest, TCompleteRequest, TResponse extends AnyEventResponse>(
|
|
31
|
+
eventType: EventType | string
|
|
32
|
+
): Promise<PreparedEvent<TPreparedRequest, TCompleteRequest, TResponse>> {
|
|
33
|
+
return Promise.resolve({
|
|
34
|
+
eventType: eventType as EventType,
|
|
35
|
+
payload: null,
|
|
36
|
+
log: () => Promise.resolve(),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
sendEvent(): Promise<AnyEventResponse | void> {
|
|
40
|
+
return Promise.resolve();
|
|
41
|
+
}
|
|
42
|
+
makeSearchEvent() {
|
|
43
|
+
return this.makeEvent<PreparedSearchEventRequest, SearchEventRequest, SearchEventResponse>(
|
|
44
|
+
EventType.search
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
sendSearchEvent(): Promise<SearchEventResponse | void> {
|
|
48
|
+
return Promise.resolve();
|
|
49
|
+
}
|
|
50
|
+
makeClickEvent() {
|
|
51
|
+
return this.makeEvent<PreparedClickEventRequest, ClickEventRequest, ClickEventResponse>(
|
|
52
|
+
EventType.click
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
sendClickEvent(): Promise<ClickEventResponse | void> {
|
|
56
|
+
return Promise.resolve();
|
|
57
|
+
}
|
|
58
|
+
makeCustomEvent() {
|
|
59
|
+
return this.makeEvent<PreparedCustomEventRequest, CustomEventRequest, CustomEventResponse>(
|
|
60
|
+
EventType.custom
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
sendCustomEvent(): Promise<CustomEventResponse | void> {
|
|
64
|
+
return Promise.resolve();
|
|
65
|
+
}
|
|
66
|
+
makeViewEvent() {
|
|
67
|
+
return this.makeEvent<PreparedViewEventRequest, ViewEventRequest, ViewEventResponse>(
|
|
68
|
+
EventType.view
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
sendViewEvent(): Promise<ViewEventResponse | void> {
|
|
72
|
+
return Promise.resolve();
|
|
73
|
+
}
|
|
74
|
+
getVisit(): Promise<VisitResponse> {
|
|
75
|
+
return Promise.resolve({id: '', visitorId: ''});
|
|
76
|
+
}
|
|
77
|
+
getHealth(): Promise<HealthResponse> {
|
|
78
|
+
return Promise.resolve({status: ''});
|
|
79
|
+
}
|
|
80
|
+
registerBeforeSendEventHook(): void {}
|
|
81
|
+
registerAfterSendEventHook(): void {}
|
|
82
|
+
addEventTypeMapping(): void {}
|
|
83
|
+
runtime = new NoopRuntime();
|
|
84
|
+
public get version(): string {
|
|
85
|
+
return libVersion;
|
|
86
|
+
}
|
|
87
|
+
currentVisitorId = '';
|
|
76
88
|
}
|
|
@@ -1,65 +1,74 @@
|
|
|
1
1
|
import {WebStorage, NullStorage, CookieAndLocalStorage} from '../storage';
|
|
2
2
|
import {AnalyticsBeaconClient} from './analyticsBeaconClient';
|
|
3
3
|
import {hasLocalStorage, hasCookieStorage} from '../detector';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
AnalyticsRequestClient,
|
|
6
|
+
IAnalyticsClientOptions,
|
|
7
|
+
NoopAnalyticsClient,
|
|
8
|
+
} from './analyticsRequestClient';
|
|
5
9
|
import {AnalyticsFetchClient} from './analyticsFetchClient';
|
|
6
10
|
import {BufferedRequest} from './analytics';
|
|
7
11
|
import {EventType} from '../events';
|
|
8
12
|
|
|
9
13
|
export interface IRuntimeEnvironment {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
storage: WebStorage;
|
|
15
|
+
client: AnalyticsRequestClient;
|
|
16
|
+
getClientDependingOnEventType(eventType: EventType): AnalyticsRequestClient;
|
|
13
17
|
}
|
|
14
18
|
|
|
15
19
|
export class BrowserRuntime implements IRuntimeEnvironment {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
public storage: WebStorage;
|
|
21
|
+
public client: AnalyticsFetchClient;
|
|
22
|
+
private beaconClient: AnalyticsBeaconClient;
|
|
19
23
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
window.addEventListener('beforeunload', () => {
|
|
32
|
-
const requests = getUnprocessedRequests();
|
|
33
|
-
for (let {eventType, payload} of requests) {
|
|
34
|
-
this.beaconClient.sendEvent(eventType, payload);
|
|
35
|
-
}
|
|
36
|
-
});
|
|
24
|
+
constructor(
|
|
25
|
+
clientOptions: IAnalyticsClientOptions,
|
|
26
|
+
getUnprocessedRequests: () => Array<BufferedRequest>
|
|
27
|
+
) {
|
|
28
|
+
if (hasLocalStorage() && hasCookieStorage()) {
|
|
29
|
+
this.storage = new CookieAndLocalStorage();
|
|
30
|
+
} else if (hasLocalStorage()) {
|
|
31
|
+
this.storage = localStorage;
|
|
32
|
+
} else {
|
|
33
|
+
console.warn('BrowserRuntime detected no valid storage available.', this);
|
|
34
|
+
this.storage = new NullStorage();
|
|
37
35
|
}
|
|
36
|
+
this.client = new AnalyticsFetchClient(clientOptions);
|
|
37
|
+
this.beaconClient = new AnalyticsBeaconClient(clientOptions);
|
|
38
|
+
window.addEventListener('beforeunload', () => {
|
|
39
|
+
const requests = getUnprocessedRequests();
|
|
40
|
+
for (let {eventType, payload} of requests) {
|
|
41
|
+
this.beaconClient.sendEvent(eventType, payload);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
38
45
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
public getClientDependingOnEventType(eventType: EventType) {
|
|
47
|
+
return eventType === 'click' && this.beaconClient.isAvailable()
|
|
48
|
+
? this.beaconClient
|
|
49
|
+
: this.client;
|
|
50
|
+
}
|
|
42
51
|
}
|
|
43
52
|
|
|
44
53
|
export class NodeJSRuntime implements IRuntimeEnvironment {
|
|
45
|
-
|
|
46
|
-
|
|
54
|
+
public storage: WebStorage;
|
|
55
|
+
public client: AnalyticsFetchClient;
|
|
47
56
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
57
|
+
constructor(clientOptions: IAnalyticsClientOptions, storage?: WebStorage) {
|
|
58
|
+
this.storage = storage || new NullStorage();
|
|
59
|
+
this.client = new AnalyticsFetchClient(clientOptions);
|
|
60
|
+
}
|
|
52
61
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
getClientDependingOnEventType(eventType: EventType): AnalyticsRequestClient {
|
|
63
|
+
return this.client;
|
|
64
|
+
}
|
|
56
65
|
}
|
|
57
66
|
|
|
58
67
|
export class NoopRuntime implements IRuntimeEnvironment {
|
|
59
|
-
|
|
60
|
-
|
|
68
|
+
public storage = new NullStorage();
|
|
69
|
+
public client = new NoopAnalyticsClient();
|
|
61
70
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
71
|
+
getClientDependingOnEventType(eventType: EventType): AnalyticsRequestClient {
|
|
72
|
+
return this.client;
|
|
73
|
+
}
|
|
65
74
|
}
|