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.
Files changed (84) hide show
  1. package/README.md +37 -43
  2. package/dist/browser.mjs +513 -357
  3. package/dist/coveoua.browser.js +1 -1
  4. package/dist/coveoua.browser.js.map +1 -1
  5. package/dist/coveoua.debug.js +542 -359
  6. package/dist/coveoua.debug.js.map +1 -1
  7. package/dist/coveoua.js +1 -1
  8. package/dist/coveoua.js.map +1 -1
  9. package/dist/definitions/client/analytics.d.ts +3 -2
  10. package/dist/definitions/client/runtimeEnvironment.d.ts +1 -1
  11. package/dist/definitions/donottrack.d.ts +1 -0
  12. package/dist/definitions/react-native/index.d.ts +1 -2
  13. package/dist/definitions/version.d.ts +1 -1
  14. package/dist/library.cjs +15350 -3699
  15. package/dist/library.es.js +513 -357
  16. package/dist/library.js +15350 -3699
  17. package/dist/library.mjs +15350 -3699
  18. package/dist/react-native.es.js +634 -460
  19. package/modules/package.json +9 -9
  20. package/package.json +60 -91
  21. package/react-native/package.json +7 -7
  22. package/src/caseAssist/caseAssistActions.ts +51 -50
  23. package/src/caseAssist/caseAssistClient.spec.ts +328 -297
  24. package/src/caseAssist/caseAssistClient.ts +201 -185
  25. package/src/client/analytics.spec.ts +724 -703
  26. package/src/client/analytics.ts +677 -602
  27. package/src/client/analyticsBeaconClient.spec.ts +195 -188
  28. package/src/client/analyticsBeaconClient.ts +99 -88
  29. package/src/client/analyticsFetchClient.ts +77 -61
  30. package/src/client/analyticsRequestClient.ts +17 -17
  31. package/src/client/location.ts +3 -3
  32. package/src/client/measurementProtocolMapper.ts +54 -45
  33. package/src/client/measurementProtocolMapping/baseMeasurementProtocolMapper.ts +48 -44
  34. package/src/client/measurementProtocolMapping/commerceMeasurementProtocolMapper.ts +133 -121
  35. package/src/client/measurementProtocolMapping/serviceMeasurementProtocolMapper.ts +17 -17
  36. package/src/client/noopAnalytics.ts +80 -68
  37. package/src/client/runtimeEnvironment.ts +50 -41
  38. package/src/client/utils.spec.ts +112 -97
  39. package/src/client/utils.ts +39 -39
  40. package/src/cookieutils.spec.ts +59 -0
  41. package/src/cookieutils.ts +40 -39
  42. package/src/coveoua/browser.ts +14 -12
  43. package/src/coveoua/library.ts +4 -4
  44. package/src/coveoua/plugins.ts +36 -34
  45. package/src/coveoua/simpleanalytics.spec.ts +467 -452
  46. package/src/coveoua/simpleanalytics.ts +146 -140
  47. package/src/detector.ts +17 -17
  48. package/src/donottrack.spec.ts +199 -121
  49. package/src/donottrack.ts +31 -8
  50. package/src/events.ts +86 -79
  51. package/src/formatting/format-array-for-coveo-custom-data.spec.ts +13 -12
  52. package/src/formatting/format-array-for-coveo-custom-data.ts +18 -18
  53. package/src/formatting/format-omnibox-metadata.ts +16 -12
  54. package/src/history.spec.ts +197 -195
  55. package/src/history.ts +143 -133
  56. package/src/hook/addDefaultValues.ts +13 -8
  57. package/src/hook/enhanceViewEvent.ts +17 -17
  58. package/src/insight/insightClient.spec.ts +1848 -1717
  59. package/src/insight/insightClient.ts +866 -761
  60. package/src/insight/insightEvents.ts +57 -56
  61. package/src/plugins/BasePlugin.ts +125 -121
  62. package/src/plugins/ec.spec.ts +457 -429
  63. package/src/plugins/ec.ts +202 -199
  64. package/src/plugins/link.spec.ts +183 -159
  65. package/src/plugins/link.ts +88 -85
  66. package/src/plugins/svc.spec.ts +161 -155
  67. package/src/plugins/svc.ts +93 -91
  68. package/src/react-native/index.ts +8 -1
  69. package/src/react-native/react-native-runtime.ts +33 -33
  70. package/src/react-native/react-native-utils.ts +1 -1
  71. package/src/react-native/react-native.spec.ts +31 -21
  72. package/src/searchPage/searchPageClient.spec.ts +1944 -1794
  73. package/src/searchPage/searchPageClient.ts +1261 -1040
  74. package/src/searchPage/searchPageEvents.ts +524 -511
  75. package/src/storage.spec.ts +51 -51
  76. package/src/storage.ts +47 -47
  77. package/dist/definitions/bundle/browser-fetch.d.ts +0 -1
  78. package/dist/definitions/src/coveoua/browser.d.ts +0 -6
  79. package/dist/definitions/src/coveoua/headless.d.ts +0 -6
  80. package/dist/definitions/src/coveoua/library.d.ts +0 -17
  81. package/dist/definitions/src/coveoua/plugins.d.ts +0 -10
  82. package/dist/definitions/src/coveoua/simpleanalytics.d.ts +0 -33
  83. package/dist/definitions/src/react-native/index.d.ts +0 -3
  84. package/dist/definitions/src/react-native/react-native-runtime.d.ts +0 -19
@@ -1,31 +1,31 @@
1
1
  function filterConsecutiveRepeatedValues(rawData: string[]) {
2
- let prev = '';
3
- return rawData.filter((value) => {
4
- const isDifferent = value !== prev;
5
- prev = value;
6
- return isDifferent;
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
- return rawData.map((value) => {
12
- return value.replace(/;/g, '');
13
- });
11
+ return rawData.map((value) => {
12
+ return value.replace(/;/g, '');
13
+ });
14
14
  }
15
15
 
16
16
  function getDataString(data: string[]): string {
17
- const ANALYTICS_LENGTH_LIMIT = 256;
17
+ const ANALYTICS_LENGTH_LIMIT = 256;
18
18
 
19
- const formattedData = data.join(';');
20
- if (formattedData.length <= ANALYTICS_LENGTH_LIMIT) {
21
- return formattedData;
22
- }
23
- return getDataString(data.slice(1));
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
- const dataWithoutSemicolons = removeSemicolons(rawData);
28
- const dataWithoutRepeatedValues = filterConsecutiveRepeatedValues(dataWithoutSemicolons);
27
+ const dataWithoutSemicolons = removeSemicolons(rawData);
28
+ const dataWithoutRepeatedValues = filterConsecutiveRepeatedValues(dataWithoutSemicolons);
29
29
 
30
- return getDataString(dataWithoutRepeatedValues);
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(meta: OmniboxSuggestionsMetadata): OmniboxSuggestionsMetadata {
5
- const partialQueries =
6
- typeof meta.partialQueries === 'string'
7
- ? meta.partialQueries
8
- : formatArrayForCoveoCustomData(meta.partialQueries);
9
- const suggestions =
10
- typeof meta.suggestions === 'string' ? meta.suggestions : formatArrayForCoveoCustomData(meta.suggestions);
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
- return {
13
- ...meta,
14
- partialQueries,
15
- suggestions,
16
- };
16
+ return {
17
+ ...meta,
18
+ partialQueries,
19
+ suggestions,
20
+ };
17
21
  }
@@ -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
- let storageMock: jest.Mocked<WebStorage>;
7
- let historyStore: history.HistoryStore;
8
- let data: history.HistoryElement;
9
-
10
- beforeEach(() => {
11
- let storageData: any;
12
- storageMock = {
13
- getItem: jest.fn((key) => storageData),
14
- setItem: jest.fn((key, data) => {
15
- storageData = data;
16
- }),
17
- removeItem: jest.fn(),
18
- };
19
- historyStore = new history.HistoryStore(storageMock);
20
- data = {
21
- name: 'name',
22
- value: 'value',
23
- time: new Date().toISOString(),
24
- };
25
- });
26
-
27
- it('should return the same an element after adding it to the history', () => {
28
- historyStore.addElement(data);
29
-
30
- expect(storageMock.setItem).toHaveBeenCalledTimes(1);
31
- const [setKey, setData] = storageMock.setItem.mock.calls[0];
32
-
33
- expect(setKey).toBe(history.STORE_KEY);
34
- expect(setData).toMatch(/"value":"value"/);
35
- expect(setData).toMatch(/"time"/);
36
- expect(setData).toMatch(/"internalTime"/);
37
- });
38
-
39
- it('should return the same an element after adding it to the history', async () => {
40
- await historyStore.addElementAsync(data);
41
-
42
- expect(storageMock.setItem).toHaveBeenCalledTimes(1);
43
- const [setKey, setData] = storageMock.setItem.mock.calls[0];
44
-
45
- expect(setKey).toBe(history.STORE_KEY);
46
- expect(setData).toMatch(/"value":"value"/);
47
- expect(setData).toMatch(/"time"/);
48
- expect(setData).toMatch(/"internalTime"/);
49
- });
50
-
51
- it('should trim query over > 75 char', async () => {
52
- data.value = '';
53
- let newValue = '';
54
- for (let i = 0; i < 100; i++) {
55
- newValue += i.toString();
56
- }
57
- data.name = 'Query';
58
- data.value = newValue;
59
-
60
- await historyStore.addElementAsync(data);
61
-
62
- expect(storageMock.setItem).toHaveBeenCalledTimes(1);
63
- const [setKey, setData] = storageMock.setItem.mock.calls[0];
64
-
65
- expect(setKey).toBe(history.STORE_KEY);
66
- expect(setData).toMatch(/"value":"01234[0-9]{70}"/);
67
- });
68
-
69
- it("should not trim elements over 75 char if it's not a query", async () => {
70
- data.value = '';
71
- let newValue = '';
72
- for (let i = 0; i < 100; i++) {
73
- newValue += i.toString();
74
- }
75
- data.name = 'Not A Query';
76
- data.value = newValue;
77
-
78
- await historyStore.addElementAsync(data);
79
-
80
- expect(storageMock.setItem).toHaveBeenCalledTimes(1);
81
- const [setKey, setData] = storageMock.setItem.mock.calls[0];
82
-
83
- expect(setKey).toBe(history.STORE_KEY);
84
- expect(setData).toMatch(/"value":"01234[0-9]{185}"/);
85
- });
86
-
87
- it('should not keep more then MAX_ELEMENTS', async () => {
88
- for (let i = 0; i < MAX_NUMBER_OF_HISTORY_ELEMENTS + 5; i++) {
89
- data.value = i.toString();
90
- await historyStore.addElementAsync(data);
91
- }
92
- const history = await historyStore.getHistoryAsync();
93
- expect(history.length).toBe(MAX_NUMBER_OF_HISTORY_ELEMENTS);
94
- });
95
-
96
- it('should be able to remove all internalTime', () => {
97
- const historyElements: history.HistoryElement[] = [];
98
- for (let i = 0; i < 5; i++) {
99
- historyElements.push({
100
- name: 'name' + i,
101
- value: 'value' + i,
102
- time: new Date().toISOString(),
103
- internalTime: new Date().getTime(),
104
- });
105
- }
106
-
107
- for (let elem of historyElements) {
108
- expect(elem).toHaveProperty('internalTime');
109
- }
110
-
111
- const stripedHistoryElements = historyStore['stripInternalTime'](historyElements);
112
-
113
- for (let elem of stripedHistoryElements) {
114
- expect(elem).not.toHaveProperty('internalTime');
115
- }
116
- });
117
-
118
- it('should strip empty query values when calling getHistoryAsync', async () => {
119
- data.name = 'Query';
120
- data.value = '';
121
- const historyElements: history.HistoryElement[] = [data];
122
- historyStore.setHistory(historyElements);
123
-
124
- const history = await historyStore.getHistoryAsync();
125
- expect(history[0].value).toBeUndefined();
126
- });
127
-
128
- it('should strip empty query values when calling getHistory', () => {
129
- data.name = 'Query';
130
- data.value = '';
131
- const historyElements: history.HistoryElement[] = [data];
132
- historyStore.setHistory(historyElements);
133
-
134
- const history = historyStore.getHistory();
135
- expect(history[0].value).toBeUndefined();
136
- });
137
-
138
- it('should strip empty query from new element (addElement)', () => {
139
- data.name = 'Query';
140
- data.value = '';
141
- historyStore.addElement(data);
142
-
143
- const [_, setData] = storageMock.setItem.mock.calls[0];
144
- expect(setData).not.toMatch(/"value"/);
145
- });
146
-
147
- it('should strip empty query from new element (addElementAsync)', async () => {
148
- data.name = 'Query';
149
- data.value = '';
150
- await historyStore.addElementAsync(data);
151
-
152
- const [_, setData] = storageMock.setItem.mock.calls[0];
153
- expect(setData).not.toMatch(/"value"/);
154
- });
155
-
156
- it('should remove item when cleared', () => {
157
- historyStore.clear();
158
-
159
- expect(storageMock.removeItem).toHaveBeenCalledWith(history.STORE_KEY);
160
- });
161
-
162
- it('should be able to set the history', () => {
163
- const historyElements: history.HistoryElement[] = [data];
164
-
165
- historyStore.setHistory(historyElements);
166
-
167
- expect(storageMock.setItem).toHaveBeenCalledWith(
168
- history.STORE_KEY,
169
- expect.stringContaining(JSON.stringify(historyElements)),
170
- );
171
- });
172
-
173
- it('should reject consecutive duplicate values', async () => {
174
- await historyStore.addElementAsync(data);
175
- await historyStore.addElementAsync(data);
176
-
177
- expect(storageMock.setItem).toHaveBeenCalledTimes(1);
178
- });
179
-
180
- it('should accept consecutive values which are not duplicates', async () => {
181
- await historyStore.addElementAsync(data);
182
- data.value = 'something else';
183
- await historyStore.addElementAsync(data);
184
-
185
- expect(storageMock.setItem).toHaveBeenCalledTimes(2);
186
- });
187
-
188
- it('should not throw when the content of localStorage is not an array', async () => {
189
- storageMock.setItem(history.STORE_KEY, '{"foo":"bar"}');
190
- let ex: any;
191
- try {
192
- const mostRecentElement = await historyStore.getMostRecentElement();
193
- expect(mostRecentElement).toBeNull();
194
- const localHistory = await historyStore.getHistoryAsync();
195
- expect(localHistory).toStrictEqual([]);
196
- } catch (err) {
197
- ex = err;
198
- }
199
- expect(ex).toBeUndefined();
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
  });