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
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
function filterConsecutiveRepeatedValues(rawData: string[]) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
let prev = '';
|
|
3
|
+
return rawData.filter((value) => {
|
|
4
|
+
const isDifferent = value !== prev;
|
|
5
|
+
prev = value;
|
|
6
|
+
return isDifferent;
|
|
7
|
+
});
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
function removeSemicolons(rawData: string[]) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
return rawData.map((value) => {
|
|
12
|
+
return value.replace(/;/g, '');
|
|
13
|
+
});
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
function getDataString(data: string[]): string {
|
|
17
|
-
|
|
17
|
+
const ANALYTICS_LENGTH_LIMIT = 256;
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
const formattedData = data.join(';');
|
|
20
|
+
if (formattedData.length <= ANALYTICS_LENGTH_LIMIT) {
|
|
21
|
+
return formattedData;
|
|
22
|
+
}
|
|
23
|
+
return getDataString(data.slice(1));
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export const formatArrayForCoveoCustomData = (rawData: string[]): string => {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
const dataWithoutSemicolons = removeSemicolons(rawData);
|
|
28
|
+
const dataWithoutRepeatedValues = filterConsecutiveRepeatedValues(dataWithoutSemicolons);
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
return getDataString(dataWithoutRepeatedValues);
|
|
31
31
|
};
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import {OmniboxSuggestionsMetadata} from '../searchPage/searchPageEvents';
|
|
2
2
|
import {formatArrayForCoveoCustomData} from './format-array-for-coveo-custom-data';
|
|
3
3
|
|
|
4
|
-
export function formatOmniboxMetadata(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
export function formatOmniboxMetadata(
|
|
5
|
+
meta: OmniboxSuggestionsMetadata
|
|
6
|
+
): OmniboxSuggestionsMetadata {
|
|
7
|
+
const partialQueries =
|
|
8
|
+
typeof meta.partialQueries === 'string'
|
|
9
|
+
? meta.partialQueries
|
|
10
|
+
: formatArrayForCoveoCustomData(meta.partialQueries);
|
|
11
|
+
const suggestions =
|
|
12
|
+
typeof meta.suggestions === 'string'
|
|
13
|
+
? meta.suggestions
|
|
14
|
+
: formatArrayForCoveoCustomData(meta.suggestions);
|
|
11
15
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
return {
|
|
17
|
+
...meta,
|
|
18
|
+
partialQueries,
|
|
19
|
+
suggestions,
|
|
20
|
+
};
|
|
17
21
|
}
|
package/src/history.spec.ts
CHANGED
|
@@ -1,201 +1,203 @@
|
|
|
1
|
+
import {vi} from 'vitest';
|
|
2
|
+
import type {Mocked} from 'vitest';
|
|
1
3
|
import * as history from './history';
|
|
2
4
|
import {MAX_NUMBER_OF_HISTORY_ELEMENTS} from './history';
|
|
3
5
|
import {WebStorage} from './storage';
|
|
4
6
|
|
|
5
7
|
describe('history', () => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
8
|
+
let storageMock: Mocked<WebStorage>;
|
|
9
|
+
let historyStore: history.HistoryStore;
|
|
10
|
+
let data: history.HistoryElement;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
let storageData: any;
|
|
14
|
+
storageMock = {
|
|
15
|
+
getItem: vi.fn((key) => storageData),
|
|
16
|
+
setItem: vi.fn((key, data) => {
|
|
17
|
+
storageData = data;
|
|
18
|
+
}),
|
|
19
|
+
removeItem: vi.fn(),
|
|
20
|
+
};
|
|
21
|
+
historyStore = new history.HistoryStore(storageMock);
|
|
22
|
+
data = {
|
|
23
|
+
name: 'name',
|
|
24
|
+
value: 'value',
|
|
25
|
+
time: new Date().toISOString(),
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should return the same an element after adding it to the history', () => {
|
|
30
|
+
historyStore.addElement(data);
|
|
31
|
+
|
|
32
|
+
expect(storageMock.setItem).toHaveBeenCalledTimes(1);
|
|
33
|
+
const [setKey, setData] = storageMock.setItem.mock.calls[0];
|
|
34
|
+
|
|
35
|
+
expect(setKey).toBe(history.STORE_KEY);
|
|
36
|
+
expect(setData).toMatch(/"value":"value"/);
|
|
37
|
+
expect(setData).toMatch(/"time"/);
|
|
38
|
+
expect(setData).toMatch(/"internalTime"/);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should return the same an element after adding it to the history', async () => {
|
|
42
|
+
await historyStore.addElementAsync(data);
|
|
43
|
+
|
|
44
|
+
expect(storageMock.setItem).toHaveBeenCalledTimes(1);
|
|
45
|
+
const [setKey, setData] = storageMock.setItem.mock.calls[0];
|
|
46
|
+
|
|
47
|
+
expect(setKey).toBe(history.STORE_KEY);
|
|
48
|
+
expect(setData).toMatch(/"value":"value"/);
|
|
49
|
+
expect(setData).toMatch(/"time"/);
|
|
50
|
+
expect(setData).toMatch(/"internalTime"/);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('should trim query over > 75 char', async () => {
|
|
54
|
+
data.value = '';
|
|
55
|
+
let newValue = '';
|
|
56
|
+
for (let i = 0; i < 100; i++) {
|
|
57
|
+
newValue += i.toString();
|
|
58
|
+
}
|
|
59
|
+
data.name = 'Query';
|
|
60
|
+
data.value = newValue;
|
|
61
|
+
|
|
62
|
+
await historyStore.addElementAsync(data);
|
|
63
|
+
|
|
64
|
+
expect(storageMock.setItem).toHaveBeenCalledTimes(1);
|
|
65
|
+
const [setKey, setData] = storageMock.setItem.mock.calls[0];
|
|
66
|
+
|
|
67
|
+
expect(setKey).toBe(history.STORE_KEY);
|
|
68
|
+
expect(setData).toMatch(/"value":"01234[0-9]{70}"/);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("should not trim elements over 75 char if it's not a query", async () => {
|
|
72
|
+
data.value = '';
|
|
73
|
+
let newValue = '';
|
|
74
|
+
for (let i = 0; i < 100; i++) {
|
|
75
|
+
newValue += i.toString();
|
|
76
|
+
}
|
|
77
|
+
data.name = 'Not A Query';
|
|
78
|
+
data.value = newValue;
|
|
79
|
+
|
|
80
|
+
await historyStore.addElementAsync(data);
|
|
81
|
+
|
|
82
|
+
expect(storageMock.setItem).toHaveBeenCalledTimes(1);
|
|
83
|
+
const [setKey, setData] = storageMock.setItem.mock.calls[0];
|
|
84
|
+
|
|
85
|
+
expect(setKey).toBe(history.STORE_KEY);
|
|
86
|
+
expect(setData).toMatch(/"value":"01234[0-9]{185}"/);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('should not keep more then MAX_ELEMENTS', async () => {
|
|
90
|
+
for (let i = 0; i < MAX_NUMBER_OF_HISTORY_ELEMENTS + 5; i++) {
|
|
91
|
+
data.value = i.toString();
|
|
92
|
+
await historyStore.addElementAsync(data);
|
|
93
|
+
}
|
|
94
|
+
const history = await historyStore.getHistoryAsync();
|
|
95
|
+
expect(history.length).toBe(MAX_NUMBER_OF_HISTORY_ELEMENTS);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('should be able to remove all internalTime', () => {
|
|
99
|
+
const historyElements: history.HistoryElement[] = [];
|
|
100
|
+
for (let i = 0; i < 5; i++) {
|
|
101
|
+
historyElements.push({
|
|
102
|
+
name: 'name' + i,
|
|
103
|
+
value: 'value' + i,
|
|
104
|
+
time: new Date().toISOString(),
|
|
105
|
+
internalTime: new Date().getTime(),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
for (let elem of historyElements) {
|
|
110
|
+
expect(elem).toHaveProperty('internalTime');
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const stripedHistoryElements = historyStore['stripInternalTime'](historyElements);
|
|
114
|
+
|
|
115
|
+
for (let elem of stripedHistoryElements) {
|
|
116
|
+
expect(elem).not.toHaveProperty('internalTime');
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('should strip empty query values when calling getHistoryAsync', async () => {
|
|
121
|
+
data.name = 'Query';
|
|
122
|
+
data.value = '';
|
|
123
|
+
const historyElements: history.HistoryElement[] = [data];
|
|
124
|
+
historyStore.setHistory(historyElements);
|
|
125
|
+
|
|
126
|
+
const history = await historyStore.getHistoryAsync();
|
|
127
|
+
expect(history[0].value).toBeUndefined();
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('should strip empty query values when calling getHistory', () => {
|
|
131
|
+
data.name = 'Query';
|
|
132
|
+
data.value = '';
|
|
133
|
+
const historyElements: history.HistoryElement[] = [data];
|
|
134
|
+
historyStore.setHistory(historyElements);
|
|
135
|
+
|
|
136
|
+
const history = historyStore.getHistory();
|
|
137
|
+
expect(history[0].value).toBeUndefined();
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('should strip empty query from new element (addElement)', () => {
|
|
141
|
+
data.name = 'Query';
|
|
142
|
+
data.value = '';
|
|
143
|
+
historyStore.addElement(data);
|
|
144
|
+
|
|
145
|
+
const [_, setData] = storageMock.setItem.mock.calls[0];
|
|
146
|
+
expect(setData).not.toMatch(/"value"/);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('should strip empty query from new element (addElementAsync)', async () => {
|
|
150
|
+
data.name = 'Query';
|
|
151
|
+
data.value = '';
|
|
152
|
+
await historyStore.addElementAsync(data);
|
|
153
|
+
|
|
154
|
+
const [_, setData] = storageMock.setItem.mock.calls[0];
|
|
155
|
+
expect(setData).not.toMatch(/"value"/);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('should remove item when cleared', () => {
|
|
159
|
+
historyStore.clear();
|
|
160
|
+
|
|
161
|
+
expect(storageMock.removeItem).toHaveBeenCalledWith(history.STORE_KEY);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('should be able to set the history', () => {
|
|
165
|
+
const historyElements: history.HistoryElement[] = [data];
|
|
166
|
+
|
|
167
|
+
historyStore.setHistory(historyElements);
|
|
168
|
+
|
|
169
|
+
expect(storageMock.setItem).toHaveBeenCalledWith(
|
|
170
|
+
history.STORE_KEY,
|
|
171
|
+
expect.stringContaining(JSON.stringify(historyElements))
|
|
172
|
+
);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('should reject consecutive duplicate values', async () => {
|
|
176
|
+
await historyStore.addElementAsync(data);
|
|
177
|
+
await historyStore.addElementAsync(data);
|
|
178
|
+
|
|
179
|
+
expect(storageMock.setItem).toHaveBeenCalledTimes(1);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('should accept consecutive values which are not duplicates', async () => {
|
|
183
|
+
await historyStore.addElementAsync(data);
|
|
184
|
+
data.value = 'something else';
|
|
185
|
+
await historyStore.addElementAsync(data);
|
|
186
|
+
|
|
187
|
+
expect(storageMock.setItem).toHaveBeenCalledTimes(2);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('should not throw when the content of localStorage is not an array', async () => {
|
|
191
|
+
storageMock.setItem(history.STORE_KEY, '{"foo":"bar"}');
|
|
192
|
+
let ex: any;
|
|
193
|
+
try {
|
|
194
|
+
const mostRecentElement = await historyStore.getMostRecentElement();
|
|
195
|
+
expect(mostRecentElement).toBeNull();
|
|
196
|
+
const localHistory = await historyStore.getHistoryAsync();
|
|
197
|
+
expect(localHistory).toStrictEqual([]);
|
|
198
|
+
} catch (err) {
|
|
199
|
+
ex = err;
|
|
200
|
+
}
|
|
201
|
+
expect(ex).toBeUndefined();
|
|
202
|
+
});
|
|
201
203
|
});
|