coveo.analytics 2.23.7 → 2.23.9
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/dist/coveoua.browser.js +1 -1
- package/dist/coveoua.browser.js.map +1 -1
- package/dist/coveoua.debug.js +42 -9
- 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 +1 -0
- package/dist/definitions/client/utils.d.ts +1 -0
- package/dist/definitions/insight/insightClient.d.ts +2 -0
- package/dist/definitions/searchPage/searchPageEvents.d.ts +3 -1
- package/dist/library.es.js +41 -5
- package/dist/library.js +42 -9
- package/dist/react-native.es.js +41 -5
- package/package.json +1 -1
- package/src/client/analytics.ts +24 -12
- package/src/client/utils.ts +3 -0
- package/src/coveoua/plugins.ts +1 -1
- package/src/coveoua/simpleanalytics.spec.ts +207 -125
- package/src/insight/insightClient.spec.ts +44 -0
- package/src/insight/insightClient.ts +26 -0
- package/src/searchPage/searchPageEvents.ts +9 -0
|
@@ -1,28 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import coveoua from './simpleanalytics';
|
|
2
2
|
import {createAnalyticsClientMock, visitorIdMock} from '../../tests/analyticsClientMock';
|
|
3
|
-
import {EC} from '../plugins/ec';
|
|
4
|
-
import {SVC} from '../plugins/svc';
|
|
5
3
|
import {TestPlugin} from '../../tests/pluginMock';
|
|
6
4
|
import {uuidv4} from '../client/crypto';
|
|
7
5
|
import {PluginOptions} from '../plugins/BasePlugin';
|
|
8
6
|
import {mockFetch} from '../../tests/fetchMock';
|
|
9
7
|
import {CookieStorage} from '../storage';
|
|
10
8
|
|
|
11
|
-
jest.mock('../plugins/svc', () => {
|
|
12
|
-
const SVC = jest.fn().mockImplementation(() => {});
|
|
13
|
-
(SVC as any)['Id'] = 'svc';
|
|
14
|
-
return {
|
|
15
|
-
SVC: SVC,
|
|
16
|
-
};
|
|
17
|
-
});
|
|
18
|
-
jest.mock('../plugins/ec', () => {
|
|
19
|
-
const EC = jest.fn().mockImplementation(() => {});
|
|
20
|
-
(EC as any)['Id'] = 'ec';
|
|
21
|
-
return {
|
|
22
|
-
EC: EC,
|
|
23
|
-
};
|
|
24
|
-
});
|
|
25
|
-
|
|
26
9
|
const uuidv4Mock = jest.fn();
|
|
27
10
|
jest.mock('../client/crypto', () => ({
|
|
28
11
|
uuidv4: () => uuidv4Mock(),
|
|
@@ -40,7 +23,7 @@ class TestPluginWithSpy extends TestPlugin {
|
|
|
40
23
|
testMethod(...args: any[]) {
|
|
41
24
|
TestPluginWithSpy.spy(args);
|
|
42
25
|
}
|
|
43
|
-
someProperty: 'foo';
|
|
26
|
+
someProperty: string = 'foo';
|
|
44
27
|
}
|
|
45
28
|
|
|
46
29
|
describe('simpleanalytics', () => {
|
|
@@ -56,7 +39,7 @@ describe('simpleanalytics', () => {
|
|
|
56
39
|
localStorage.clear();
|
|
57
40
|
fetchMock.mock('*', {});
|
|
58
41
|
uuidv4Mock.mockImplementationOnce(() => visitorIdMock);
|
|
59
|
-
|
|
42
|
+
coveoua('reset');
|
|
60
43
|
});
|
|
61
44
|
|
|
62
45
|
afterEach(() => {
|
|
@@ -67,27 +50,27 @@ describe('simpleanalytics', () => {
|
|
|
67
50
|
|
|
68
51
|
describe('init', () => {
|
|
69
52
|
it('throws when initializing without a token', () => {
|
|
70
|
-
expect(() =>
|
|
53
|
+
expect(() => coveoua('init')).toThrow(`You must pass your token when you call 'init'`);
|
|
71
54
|
});
|
|
72
55
|
|
|
73
56
|
it('throws when initializing with a token that is not a string nor a AnalyticClient', () => {
|
|
74
|
-
expect(() =>
|
|
57
|
+
expect(() => coveoua('init', {})).toThrow(
|
|
75
58
|
`You must pass either your token or a valid object when you call 'init'`
|
|
76
59
|
);
|
|
77
60
|
});
|
|
78
61
|
|
|
79
62
|
it('can initialize with analyticsClient', () => {
|
|
80
|
-
expect(() =>
|
|
63
|
+
expect(() => coveoua('init', analyticsClientMock)).not.toThrow();
|
|
81
64
|
});
|
|
82
65
|
|
|
83
66
|
it('can initialize with a token', () => {
|
|
84
|
-
expect(() =>
|
|
67
|
+
expect(() => coveoua('init', 'SOME TOKEN')).not.toThrow();
|
|
85
68
|
});
|
|
86
69
|
|
|
87
70
|
it('default to analytics.cloud.coveo.com when no endpoint is given', async () => {
|
|
88
|
-
|
|
71
|
+
coveoua('init', 'SOME TOKEN');
|
|
89
72
|
|
|
90
|
-
await
|
|
73
|
+
await coveoua('send', 'pageview');
|
|
91
74
|
|
|
92
75
|
expect(fetchMock.calls().length).toBe(1);
|
|
93
76
|
const foo = fetchMock.lastUrl();
|
|
@@ -95,9 +78,9 @@ describe('simpleanalytics', () => {
|
|
|
95
78
|
});
|
|
96
79
|
|
|
97
80
|
it('default to analytics.cloud.coveo.com when the endpoint is an empty string', async () => {
|
|
98
|
-
|
|
81
|
+
coveoua('init', 'SOME TOKEN', '');
|
|
99
82
|
|
|
100
|
-
await
|
|
83
|
+
await coveoua('send', 'pageview');
|
|
101
84
|
|
|
102
85
|
expect(fetchMock.calls().length).toBe(1);
|
|
103
86
|
const foo = fetchMock.lastUrl();
|
|
@@ -105,78 +88,72 @@ describe('simpleanalytics', () => {
|
|
|
105
88
|
});
|
|
106
89
|
|
|
107
90
|
it('default to analytics.cloud.coveo.com when an options object is given but does not include an endpoint', async () => {
|
|
108
|
-
|
|
91
|
+
coveoua('init', 'SOME TOKEN', {});
|
|
109
92
|
|
|
110
|
-
await
|
|
93
|
+
await coveoua('send', 'pageview');
|
|
111
94
|
|
|
112
95
|
expect(fetchMock.calls().length).toBe(1);
|
|
113
96
|
expect(fetchMock.lastUrl()).toMatch(/^https:\/\/analytics\.cloud\.coveo\.com\/rest\/ua/);
|
|
114
97
|
});
|
|
115
98
|
|
|
116
99
|
it('default to analytics.cloud.coveo.com when an options object is given but the endpoint property is falsy', async () => {
|
|
117
|
-
|
|
100
|
+
coveoua('init', 'SOME TOKEN', {endpoint: ''});
|
|
118
101
|
|
|
119
|
-
await
|
|
102
|
+
await coveoua('send', 'pageview');
|
|
120
103
|
|
|
121
104
|
expect(fetchMock.calls().length).toBe(1);
|
|
122
105
|
expect(fetchMock.lastUrl()).toMatch(/^https:\/\/analytics\.cloud\.coveo\.com\/rest\/ua/);
|
|
123
106
|
});
|
|
124
107
|
|
|
125
108
|
it('uses the endpoint given if its a non-empty string', async () => {
|
|
126
|
-
|
|
109
|
+
coveoua('init', 'SOME TOKEN', 'https://someendpoint.com');
|
|
127
110
|
|
|
128
|
-
await
|
|
111
|
+
await coveoua('send', 'pageview');
|
|
129
112
|
|
|
130
113
|
expect(fetchMock.calls().length).toBe(1);
|
|
131
114
|
expect(fetchMock.lastUrl()).toMatch(/^https:\/\/someendpoint\.com/);
|
|
132
115
|
});
|
|
133
116
|
|
|
134
117
|
it('uses the endpoint given if the options object include a non-empty string', async () => {
|
|
135
|
-
|
|
118
|
+
coveoua('init', 'SOME TOKEN', {endpoint: 'https://someendpoint.com'});
|
|
136
119
|
|
|
137
|
-
await
|
|
120
|
+
await coveoua('send', 'pageview');
|
|
138
121
|
|
|
139
122
|
expect(fetchMock.calls().length).toBe(1);
|
|
140
123
|
expect(fetchMock.lastUrl()).toMatch(/^https:\/\/someendpoint\.com/);
|
|
141
124
|
});
|
|
142
125
|
|
|
143
126
|
it('uses EC and SVC plugins by default', () => {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
expect(
|
|
147
|
-
expect(EC).toHaveBeenCalled();
|
|
127
|
+
coveoua('init', 'SOME TOKEN');
|
|
128
|
+
expect(() => coveoua('callPlugin', 'ec', 'nosuchfunction')).toThrow(/does not exist/);
|
|
129
|
+
expect(() => coveoua('callPlugin', 'svc', 'nosuchfunction')).toThrow(/does not exist/);
|
|
148
130
|
});
|
|
149
131
|
|
|
150
|
-
it('can
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
expect(
|
|
154
|
-
expect(EC).not.toHaveBeenCalled();
|
|
132
|
+
it('can accept no plugins', () => {
|
|
133
|
+
coveoua('init', 'SOME TOKEN', {plugins: []});
|
|
134
|
+
expect(() => coveoua('callPlugin', 'ec', 'nosuchfunction')).toThrow(/is not required/);
|
|
135
|
+
expect(() => coveoua('callPlugin', 'svc', 'nosuchfunction')).toThrow(/is not required/);
|
|
155
136
|
});
|
|
156
137
|
|
|
157
|
-
it('can
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
expect(
|
|
161
|
-
expect(EC).not.toHaveBeenCalled();
|
|
138
|
+
it('can accept one plugin', () => {
|
|
139
|
+
coveoua('init', 'SOME TOKEN', {plugins: ['svc']});
|
|
140
|
+
expect(() => coveoua('callPlugin', 'ec', 'nosuchfunction')).toThrow(/is not required/);
|
|
141
|
+
expect(() => coveoua('callPlugin', 'svc', 'nosuchfunction')).toThrow(/does not exist/);
|
|
162
142
|
});
|
|
163
143
|
|
|
164
144
|
it('can send pageview with analyticsClient', () => {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
expect(() => handleOneAnalyticsEvent('send', 'pageview')).not.toThrow();
|
|
145
|
+
coveoua('init', analyticsClientMock);
|
|
146
|
+
expect(() => coveoua('send', 'pageview')).not.toThrow();
|
|
168
147
|
});
|
|
169
148
|
});
|
|
170
149
|
|
|
171
150
|
describe('initForProxy', () => {
|
|
172
151
|
it(`throw if the initForProxy don't receive an endpoint`, () => {
|
|
173
|
-
expect(() =>
|
|
174
|
-
`You must pass your endpoint when you call 'initForProxy'`
|
|
175
|
-
);
|
|
152
|
+
expect(() => coveoua('initForProxy')).toThrow(`You must pass your endpoint when you call 'initForProxy'`);
|
|
176
153
|
});
|
|
177
154
|
|
|
178
155
|
it(`throw if the initForProxy receive an endpoint that's is not a string`, () => {
|
|
179
|
-
expect(() =>
|
|
156
|
+
expect(() => coveoua('initForProxy', {})).toThrow(
|
|
180
157
|
`You must pass a string as the endpoint parameter when you call 'initForProxy'`
|
|
181
158
|
);
|
|
182
159
|
});
|
|
@@ -184,27 +161,25 @@ describe('simpleanalytics', () => {
|
|
|
184
161
|
|
|
185
162
|
describe('send', () => {
|
|
186
163
|
it('throws when not initialized', () => {
|
|
187
|
-
expect(() =>
|
|
164
|
+
expect(() => coveoua('send')).toThrow(`You must call init before sending an event`);
|
|
188
165
|
});
|
|
189
166
|
|
|
190
167
|
it('throws when send is called without any other arguments', () => {
|
|
191
|
-
|
|
192
|
-
expect(() =>
|
|
193
|
-
`You must provide an event type when calling "send".`
|
|
194
|
-
);
|
|
168
|
+
coveoua('init', 'MYTOKEN');
|
|
169
|
+
expect(() => coveoua('send')).toThrow(`You must provide an event type when calling "send".`);
|
|
195
170
|
});
|
|
196
171
|
|
|
197
172
|
it('can send pageview', async () => {
|
|
198
|
-
|
|
199
|
-
await
|
|
173
|
+
coveoua('init', 'MYTOKEN', {plugins: []});
|
|
174
|
+
await coveoua('send', 'pageview');
|
|
200
175
|
|
|
201
176
|
expect(fetchMock.calls().length).toBe(1);
|
|
202
177
|
expect(fetchMock.lastUrl()).toBe(`${analyticsEndpoint}/pageview`);
|
|
203
178
|
});
|
|
204
179
|
|
|
205
180
|
it('can send pageview with customdata', async () => {
|
|
206
|
-
|
|
207
|
-
await
|
|
181
|
+
coveoua('init', 'MYTOKEN', {plugins: []});
|
|
182
|
+
await coveoua('send', 'pageview', {somedata: 'asd'});
|
|
208
183
|
|
|
209
184
|
expect(fetchMock.calls().length).toBe(1);
|
|
210
185
|
expect(fetchMock.lastUrl()).toBe(`${analyticsEndpoint}/pageview`);
|
|
@@ -212,8 +187,8 @@ describe('simpleanalytics', () => {
|
|
|
212
187
|
});
|
|
213
188
|
|
|
214
189
|
it('can send view event with clientId', async () => {
|
|
215
|
-
|
|
216
|
-
await
|
|
190
|
+
coveoua('init', 'MYTOKEN', {plugins: []});
|
|
191
|
+
await coveoua('send', 'view');
|
|
217
192
|
|
|
218
193
|
expect(fetchMock.calls().length).toBe(1);
|
|
219
194
|
expect(fetchMock.lastUrl()).toBe(`${analyticsEndpoint}/view?visitor=${visitorIdMock}`);
|
|
@@ -221,16 +196,16 @@ describe('simpleanalytics', () => {
|
|
|
221
196
|
});
|
|
222
197
|
|
|
223
198
|
it('can send any event to the endpoint', async () => {
|
|
224
|
-
|
|
225
|
-
await
|
|
199
|
+
coveoua('init', 'MYTOKEN');
|
|
200
|
+
await coveoua('send', someRandomEventName);
|
|
226
201
|
|
|
227
202
|
expect(fetchMock.calls().length).toBe(1);
|
|
228
203
|
expect(fetchMock.lastUrl()).toBe(`${analyticsEndpoint}/${someRandomEventName}`);
|
|
229
204
|
});
|
|
230
205
|
|
|
231
206
|
it('can send an event with a proxy endpoint', async () => {
|
|
232
|
-
|
|
233
|
-
await
|
|
207
|
+
coveoua('initForProxy', 'https://myProxyEndpoint.com');
|
|
208
|
+
await coveoua('send', someRandomEventName);
|
|
234
209
|
|
|
235
210
|
expect(fetchMock.calls().length).toBe(1);
|
|
236
211
|
expect(fetchMock.lastUrl()).toBe(`https://myproxyendpoint.com/rest/v15/analytics/${someRandomEventName}`);
|
|
@@ -239,9 +214,9 @@ describe('simpleanalytics', () => {
|
|
|
239
214
|
|
|
240
215
|
describe('set', () => {
|
|
241
216
|
it('can set a new parameter', async () => {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
await
|
|
217
|
+
coveoua('init', 'MYTOKEN');
|
|
218
|
+
coveoua('set', 'userId', 'something');
|
|
219
|
+
await coveoua('send', someRandomEventName);
|
|
245
220
|
|
|
246
221
|
expect(fetchMock.calls().length).toBe(1);
|
|
247
222
|
expect(fetchMock.lastUrl()).toBe(`${analyticsEndpoint}/${someRandomEventName}`);
|
|
@@ -249,98 +224,205 @@ describe('simpleanalytics', () => {
|
|
|
249
224
|
});
|
|
250
225
|
|
|
251
226
|
it('can set parameters using an object', async () => {
|
|
252
|
-
|
|
253
|
-
|
|
227
|
+
coveoua('init', 'MYTOKEN');
|
|
228
|
+
coveoua('set', {
|
|
254
229
|
userId: 'something',
|
|
255
230
|
});
|
|
256
|
-
await
|
|
231
|
+
await coveoua('send', someRandomEventName);
|
|
257
232
|
|
|
258
233
|
expect(fetchMock.calls().length).toBe(1);
|
|
259
234
|
expect(fetchMock.lastUrl()).toBe(`${analyticsEndpoint}/${someRandomEventName}`);
|
|
260
235
|
expect(JSON.parse(fetchMock.lastCall()![1]!.body!.toString())).toEqual({userId: 'something'});
|
|
261
236
|
});
|
|
237
|
+
|
|
238
|
+
it('can set a custom_website parameter on a collect event', async () => {
|
|
239
|
+
coveoua('init', 'MYTOKEN', {plugins: ['ec']});
|
|
240
|
+
coveoua('set', 'custom', {context_website: 'MY_WEBSITE'});
|
|
241
|
+
await coveoua('send', 'pageview');
|
|
242
|
+
|
|
243
|
+
expect(fetchMock.calls().length).toBe(1);
|
|
244
|
+
let result = JSON.parse(fetchMock.lastCall()![1]!.body!.toString());
|
|
245
|
+
expect(result).toHaveProperty('context_website', 'MY_WEBSITE');
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it('does not set custom parameters which are strings', async () => {
|
|
249
|
+
coveoua('init', 'MYTOKEN', {plugins: ['ec']});
|
|
250
|
+
coveoua('set', 'custom', 'test');
|
|
251
|
+
await coveoua('send', 'pageview');
|
|
252
|
+
|
|
253
|
+
expect(fetchMock.calls().length).toBe(1);
|
|
254
|
+
let result = JSON.parse(fetchMock.lastCall()![1]!.body!.toString());
|
|
255
|
+
expect(Object.keys(result).length).toBe(11);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it('does not set custom parameters which are arrays', async () => {
|
|
259
|
+
coveoua('init', 'MYTOKEN', {plugins: ['ec']});
|
|
260
|
+
coveoua('set', 'custom', ['test']);
|
|
261
|
+
await coveoua('send', 'pageview');
|
|
262
|
+
|
|
263
|
+
expect(fetchMock.calls().length).toBe(1);
|
|
264
|
+
let result = JSON.parse(fetchMock.lastCall()![1]!.body!.toString());
|
|
265
|
+
expect(Object.keys(result).length).toBe(11);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it('does not set custom parameters which are null', async () => {
|
|
269
|
+
coveoua('init', 'MYTOKEN', {plugins: ['ec']});
|
|
270
|
+
coveoua('set', 'custom', null);
|
|
271
|
+
await coveoua('send', 'pageview');
|
|
272
|
+
|
|
273
|
+
expect(fetchMock.calls().length).toBe(1);
|
|
274
|
+
let result = JSON.parse(fetchMock.lastCall()![1]!.body!.toString());
|
|
275
|
+
expect(Object.keys(result).length).toBe(11);
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it('does not set custom parameters which are undefined', async () => {
|
|
279
|
+
coveoua('init', 'MYTOKEN', {plugins: ['ec']});
|
|
280
|
+
coveoua('set', 'custom', undefined);
|
|
281
|
+
await coveoua('send', 'pageview');
|
|
282
|
+
|
|
283
|
+
expect(fetchMock.calls().length).toBe(1);
|
|
284
|
+
let result = JSON.parse(fetchMock.lastCall()![1]!.body!.toString());
|
|
285
|
+
expect(Object.keys(result).length).toBe(11);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it('can set a custom_website parameter on a non-collect event', async () => {
|
|
289
|
+
coveoua('init', 'MYTOKEN', {plugins: []});
|
|
290
|
+
coveoua('set', 'custom', {context_website: 'MY_WEBSITE'});
|
|
291
|
+
await coveoua('send', 'view', {somedata: 'something'});
|
|
292
|
+
|
|
293
|
+
expect(fetchMock.calls().length).toBe(1);
|
|
294
|
+
let result = JSON.parse(fetchMock.lastCall()![1]!.body!.toString());
|
|
295
|
+
expect(result).toHaveProperty('somedata', 'something');
|
|
296
|
+
expect(result).toHaveProperty('customData.context_website', 'MY_WEBSITE');
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it('does not add a customData entry for custom params which are null', async () => {
|
|
300
|
+
coveoua('init', 'MYTOKEN', {plugins: []});
|
|
301
|
+
coveoua('set', 'custom', null);
|
|
302
|
+
await coveoua('send', 'view', {somedata: 'something'});
|
|
303
|
+
|
|
304
|
+
expect(fetchMock.calls().length).toBe(1);
|
|
305
|
+
let result = JSON.parse(fetchMock.lastCall()![1]!.body!.toString());
|
|
306
|
+
expect(result).toHaveProperty('somedata', 'something');
|
|
307
|
+
expect(result).not.toHaveProperty('customData');
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
it('does not add a customData entry for custom params which are undefined', async () => {
|
|
311
|
+
coveoua('init', 'MYTOKEN', {plugins: []});
|
|
312
|
+
coveoua('set', 'custom', undefined);
|
|
313
|
+
await coveoua('send', 'view', {somedata: 'something'});
|
|
314
|
+
|
|
315
|
+
expect(fetchMock.calls().length).toBe(1);
|
|
316
|
+
let result = JSON.parse(fetchMock.lastCall()![1]!.body!.toString());
|
|
317
|
+
expect(result).toHaveProperty('somedata', 'something');
|
|
318
|
+
expect(result).not.toHaveProperty('customData');
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it('does not add a customData entry for customData params which are strings', async () => {
|
|
322
|
+
coveoua('init', 'MYTOKEN', {plugins: []});
|
|
323
|
+
coveoua('set', 'custom', 'test');
|
|
324
|
+
await coveoua('send', 'view', {somedata: 'something'});
|
|
325
|
+
|
|
326
|
+
expect(fetchMock.calls().length).toBe(1);
|
|
327
|
+
let result = JSON.parse(fetchMock.lastCall()![1]!.body!.toString());
|
|
328
|
+
expect(result).toHaveProperty('somedata', 'something');
|
|
329
|
+
expect(result).not.toHaveProperty('customData');
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it('does not add a customData entry for customData params which are arrays', async () => {
|
|
333
|
+
coveoua('init', 'MYTOKEN', [{plugins: []}]);
|
|
334
|
+
coveoua('set', 'custom', [test]);
|
|
335
|
+
await coveoua('send', 'view', {somedata: 'something'});
|
|
336
|
+
|
|
337
|
+
expect(fetchMock.calls().length).toBe(1);
|
|
338
|
+
let result = JSON.parse(fetchMock.lastCall()![1]!.body!.toString());
|
|
339
|
+
expect(result).toHaveProperty('somedata', 'something');
|
|
340
|
+
expect(result).not.toHaveProperty('customData');
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it('will not override hardcoded customData parameters', async () => {
|
|
344
|
+
coveoua('init', 'MYTOKEN', {plugins: []});
|
|
345
|
+
coveoua('set', 'custom', {context_website: 'MY_WEBSITE'});
|
|
346
|
+
await coveoua('send', 'view', {somedata: 'something', customData: {context_website: 'MY_OTHER_WEBSITE'}});
|
|
347
|
+
|
|
348
|
+
expect(fetchMock.calls().length).toBe(1);
|
|
349
|
+
let result = JSON.parse(fetchMock.lastCall()![1]!.body!.toString());
|
|
350
|
+
expect(result).toHaveProperty('somedata', 'something');
|
|
351
|
+
expect(result).toHaveProperty('customData.context_website', 'MY_OTHER_WEBSITE');
|
|
352
|
+
});
|
|
262
353
|
});
|
|
263
354
|
|
|
264
355
|
describe('onLoad', () => {
|
|
265
356
|
it('can execute callback with onLoad event', () => {
|
|
266
357
|
var callback = jest.fn();
|
|
267
358
|
|
|
268
|
-
|
|
359
|
+
coveoua('onLoad', callback);
|
|
269
360
|
|
|
270
361
|
expect(callback).toHaveBeenCalledTimes(1);
|
|
271
362
|
});
|
|
272
363
|
|
|
273
364
|
it('throws when registering an invalid onLoad event', () => {
|
|
274
|
-
expect(() =>
|
|
365
|
+
expect(() => coveoua('onLoad', undefined)).toThrow();
|
|
275
366
|
});
|
|
276
367
|
});
|
|
277
368
|
|
|
278
369
|
describe('provide', () => {
|
|
279
370
|
it('register properly', () => {
|
|
280
|
-
|
|
371
|
+
coveoua('provide', 'test', TestPlugin);
|
|
281
372
|
|
|
282
|
-
|
|
373
|
+
coveoua('init', 'MYTOKEN');
|
|
283
374
|
|
|
284
|
-
expect(() =>
|
|
375
|
+
expect(() => coveoua('require', 'test')).not.toThrow();
|
|
285
376
|
});
|
|
286
377
|
});
|
|
287
378
|
|
|
288
379
|
describe('callPlugin', () => {
|
|
289
380
|
it('resolves properly plugin actions', () => {
|
|
290
|
-
|
|
291
|
-
|
|
381
|
+
coveoua('provide', 'test', TestPluginWithSpy);
|
|
382
|
+
coveoua('init', 'MYTOKEN', {plugins: ['test']});
|
|
292
383
|
|
|
293
|
-
|
|
384
|
+
coveoua('callPlugin', 'test', 'testMethod', 'foo', 'bar');
|
|
294
385
|
|
|
295
386
|
expect(TestPluginWithSpy.spy).toHaveBeenCalledTimes(1);
|
|
296
387
|
expect(TestPluginWithSpy.spy).toHaveBeenCalledWith(['foo', 'bar']);
|
|
297
388
|
});
|
|
298
389
|
|
|
299
390
|
it('throws when a namespaced action is called and that the namespace/plugin is not required', () => {
|
|
300
|
-
|
|
391
|
+
coveoua('init', 'SOME TOKEN', {plugins: ['ec']});
|
|
301
392
|
|
|
302
|
-
expect(() =>
|
|
303
|
-
`The plugin "svc" is not required. Check that you required it on initialization.`
|
|
304
|
-
);
|
|
393
|
+
expect(() => coveoua('callPlugin', 'svc', 'setTicket')).toThrow(/is not required/);
|
|
305
394
|
});
|
|
306
395
|
|
|
307
396
|
it('throws when a namespaced action is called and that this action does not exists on the plugin', () => {
|
|
308
|
-
|
|
397
|
+
coveoua('init', 'SOME TOKEN', {plugins: ['svc']});
|
|
309
398
|
|
|
310
|
-
expect(() =>
|
|
311
|
-
`The function "fooBarBaz" does not exists on the plugin "svc".`
|
|
312
|
-
);
|
|
399
|
+
expect(() => coveoua('callPlugin', 'svc', 'fooBarBaz')).toThrow(/does not exist/);
|
|
313
400
|
});
|
|
314
401
|
|
|
315
402
|
it('throws when a namespaced action is called and that this action is not a function on the plugin', () => {
|
|
316
|
-
|
|
403
|
+
coveoua('provide', 'test', TestPluginWithSpy);
|
|
317
404
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
expect(() => handleOneAnalyticsEvent('callPlugin', 'test', 'someProperty')).toThrow(
|
|
321
|
-
`The function "someProperty" does not exists on the plugin "test".`
|
|
322
|
-
);
|
|
405
|
+
coveoua('init', 'SOME TOKEN', {plugins: ['test']});
|
|
406
|
+
expect(() => coveoua('callPlugin', 'test', 'someProperty')).toThrow(/is not a function/);
|
|
323
407
|
});
|
|
324
408
|
});
|
|
325
409
|
|
|
326
410
|
describe('require', () => {
|
|
327
411
|
it('can require a plugin', () => {
|
|
328
|
-
|
|
329
|
-
|
|
412
|
+
coveoua('provide', 'test', TestPlugin);
|
|
413
|
+
coveoua('init', 'MYTOKEN', {plugins: []});
|
|
330
414
|
|
|
331
|
-
expect(() =>
|
|
415
|
+
expect(() => coveoua('require', 'test')).not.toThrow();
|
|
332
416
|
});
|
|
333
417
|
|
|
334
418
|
it('throws if not initialized', () => {
|
|
335
|
-
expect(() =>
|
|
336
|
-
`You must call init before requiring a plugin`
|
|
337
|
-
);
|
|
419
|
+
expect(() => coveoua('require', 'test')).toThrow(`You must call init before requiring a plugin`);
|
|
338
420
|
});
|
|
339
421
|
|
|
340
422
|
it('throws if the plugin is not registered first', () => {
|
|
341
|
-
|
|
423
|
+
coveoua('init', 'MYTOKEN', {plugins: []});
|
|
342
424
|
|
|
343
|
-
expect(() =>
|
|
425
|
+
expect(() => coveoua('require', 'test')).toThrow(
|
|
344
426
|
`No plugin named "test" is currently registered. If you use a custom plugin, use 'provide' first.`
|
|
345
427
|
);
|
|
346
428
|
});
|
|
@@ -348,33 +430,33 @@ describe('simpleanalytics', () => {
|
|
|
348
430
|
|
|
349
431
|
describe('reset', () => {
|
|
350
432
|
it('reset the client', () => {
|
|
351
|
-
|
|
433
|
+
coveoua('init', 'MYTOKEN');
|
|
352
434
|
|
|
353
|
-
|
|
435
|
+
coveoua('reset');
|
|
354
436
|
|
|
355
|
-
expect(() =>
|
|
437
|
+
expect(() => coveoua('send')).toThrow(`You must call init before sending an event`);
|
|
356
438
|
});
|
|
357
439
|
|
|
358
440
|
it('reset the plugins', () => {
|
|
359
441
|
const fakePlugin = TestPlugin;
|
|
360
|
-
|
|
361
|
-
|
|
442
|
+
coveoua('provide', 'test', fakePlugin);
|
|
443
|
+
coveoua('init', 'MYTOKEN', {plugins: ['test']});
|
|
362
444
|
|
|
363
|
-
|
|
445
|
+
coveoua('reset');
|
|
364
446
|
|
|
365
|
-
expect(() =>
|
|
447
|
+
expect(() => coveoua('init', 'MYTOKEN', {plugins: ['test']})).toThrow(
|
|
366
448
|
`No plugin named "test" is currently registered. If you use a custom plugin, use 'provide' first.`
|
|
367
449
|
);
|
|
368
450
|
});
|
|
369
451
|
|
|
370
452
|
it('reset the params', async () => {
|
|
371
|
-
|
|
372
|
-
|
|
453
|
+
coveoua('init', 'MYTOKEN');
|
|
454
|
+
coveoua('set', 'userId', 'something');
|
|
373
455
|
|
|
374
|
-
|
|
456
|
+
coveoua('reset');
|
|
375
457
|
|
|
376
|
-
|
|
377
|
-
await
|
|
458
|
+
coveoua('init', 'MYTOKEN');
|
|
459
|
+
await coveoua('send', someRandomEventName);
|
|
378
460
|
|
|
379
461
|
expect(fetchMock.calls().length).toBe(1);
|
|
380
462
|
expect(fetchMock.lastUrl()).toBe(`${analyticsEndpoint}/${someRandomEventName}`);
|
|
@@ -383,18 +465,18 @@ describe('simpleanalytics', () => {
|
|
|
383
465
|
});
|
|
384
466
|
|
|
385
467
|
it('throws when called with an unknown action', () => {
|
|
386
|
-
|
|
468
|
+
coveoua('init', 'SOME TOKEN', {plugins: ['svc']});
|
|
387
469
|
|
|
388
|
-
expect(() =>
|
|
470
|
+
expect(() => coveoua('potato')).toThrow(
|
|
389
471
|
`The action "potato" does not exist. Available actions: init, set, send, onLoad, callPlugin, reset, require, provide.`
|
|
390
472
|
);
|
|
391
473
|
});
|
|
392
474
|
|
|
393
475
|
it('resolves properly plugin actions', () => {
|
|
394
|
-
|
|
395
|
-
|
|
476
|
+
coveoua('provide', 'test', TestPluginWithSpy);
|
|
477
|
+
coveoua('init', 'MYTOKEN', {plugins: ['test']});
|
|
396
478
|
|
|
397
|
-
|
|
479
|
+
coveoua('test:testMethod', 'foo', 'bar');
|
|
398
480
|
|
|
399
481
|
expect(TestPluginWithSpy.spy).toHaveBeenCalledTimes(1);
|
|
400
482
|
expect(TestPluginWithSpy.spy).toHaveBeenCalledWith(['foo', 'bar']);
|
|
@@ -333,6 +333,25 @@ describe('InsightClient', () => {
|
|
|
333
333
|
await client.logDocumentQuickview(fakeDocInfo, fakeDocID);
|
|
334
334
|
expectMatchDocumentPayload(SearchPageEvents.documentQuickview, fakeDocInfo, expectedMetadata);
|
|
335
335
|
});
|
|
336
|
+
|
|
337
|
+
it('should send proper payload for #caseAttach', async () => {
|
|
338
|
+
const expectedMetadata = {
|
|
339
|
+
...fakeDocID,
|
|
340
|
+
documentTitle: fakeDocInfo.documentTitle,
|
|
341
|
+
documentURL: fakeDocInfo.documentUrl,
|
|
342
|
+
resultUriHash: fakeDocInfo.documentUriHash,
|
|
343
|
+
};
|
|
344
|
+
await client.logCaseAttach(fakeDocInfo, fakeDocID);
|
|
345
|
+
expectMatchDocumentPayload(SearchPageEvents.caseAttach, fakeDocInfo, expectedMetadata);
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it('should send proper payload for #caseDetach', async () => {
|
|
349
|
+
const expectedMetadata = {
|
|
350
|
+
resultUriHash: fakeDocInfo.documentUriHash,
|
|
351
|
+
};
|
|
352
|
+
await client.logCaseDetach(fakeDocInfo.documentUriHash);
|
|
353
|
+
expectMatchCustomEventPayload(SearchPageEvents.caseDetach, expectedMetadata);
|
|
354
|
+
});
|
|
336
355
|
});
|
|
337
356
|
|
|
338
357
|
describe('when the case metadata is included', () => {
|
|
@@ -714,6 +733,31 @@ describe('InsightClient', () => {
|
|
|
714
733
|
await client.logDocumentQuickview(fakeDocInfo, fakeDocID, metadata);
|
|
715
734
|
expectMatchDocumentPayload(SearchPageEvents.documentQuickview, fakeDocInfo, expectedMetadata);
|
|
716
735
|
});
|
|
736
|
+
|
|
737
|
+
it('should send proper payload for #caseAttach', async () => {
|
|
738
|
+
const metadata = baseCaseMetadata;
|
|
739
|
+
|
|
740
|
+
const expectedMetadata = {
|
|
741
|
+
...fakeDocID,
|
|
742
|
+
...expectedBaseCaseMetadata,
|
|
743
|
+
documentTitle: fakeDocInfo.documentTitle,
|
|
744
|
+
documentURL: fakeDocInfo.documentUrl,
|
|
745
|
+
resultUriHash: fakeDocInfo.documentUriHash,
|
|
746
|
+
};
|
|
747
|
+
await client.logCaseAttach(fakeDocInfo, fakeDocID, metadata);
|
|
748
|
+
expectMatchDocumentPayload(SearchPageEvents.caseAttach, fakeDocInfo, expectedMetadata);
|
|
749
|
+
});
|
|
750
|
+
|
|
751
|
+
it('should send proper payload for #caseDetach', async () => {
|
|
752
|
+
const metadata = baseCaseMetadata;
|
|
753
|
+
|
|
754
|
+
const expectedMetadata = {
|
|
755
|
+
...expectedBaseCaseMetadata,
|
|
756
|
+
resultUriHash: fakeDocInfo.documentUriHash,
|
|
757
|
+
};
|
|
758
|
+
await client.logCaseDetach(fakeDocInfo.documentUriHash, metadata);
|
|
759
|
+
expectMatchCustomEventPayload(SearchPageEvents.caseDetach, expectedMetadata);
|
|
760
|
+
});
|
|
717
761
|
});
|
|
718
762
|
|
|
719
763
|
it('should enable analytics tracking by default', () => {
|