coveo.analytics 2.30.44 → 2.30.45
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/browser.mjs +41 -5
- package/dist/coveoua.browser.js +1 -1
- package/dist/coveoua.browser.js.map +1 -1
- package/dist/coveoua.debug.js +60 -5
- package/dist/coveoua.debug.js.map +1 -1
- package/dist/coveoua.js +1 -1
- package/dist/coveoua.js.map +1 -1
- package/dist/definitions/caseAssist/caseAssistActions.d.ts +4 -1
- package/dist/definitions/caseAssist/caseAssistClient.d.ts +12 -1
- package/dist/definitions/version.d.ts +1 -1
- package/dist/library.cjs +60 -5
- package/dist/library.es.js +41 -5
- package/dist/library.js +60 -5
- package/dist/library.mjs +60 -5
- package/dist/react-native.es.js +41 -5
- package/package.json +1 -1
- package/src/caseAssist/caseAssistActions.ts +4 -1
- package/src/caseAssist/caseAssistClient.spec.ts +59 -35
- package/src/caseAssist/caseAssistClient.ts +61 -3
|
@@ -11,6 +11,7 @@ import {TicketProperties} from '../plugins/svc';
|
|
|
11
11
|
const {fetchMock, fetchMockBeforeEach} = mockFetch();
|
|
12
12
|
import doNotTrack from '../donottrack';
|
|
13
13
|
import {Cookie} from '../cookieutils';
|
|
14
|
+
import {PartialDocumentInformation} from '../searchPage/searchPageEvents';
|
|
14
15
|
jest.mock('../donottrack', () => {
|
|
15
16
|
return {
|
|
16
17
|
default: jest.fn(),
|
|
@@ -19,17 +20,31 @@ jest.mock('../donottrack', () => {
|
|
|
19
20
|
});
|
|
20
21
|
|
|
21
22
|
describe('CaseAssistClient', () => {
|
|
22
|
-
const
|
|
23
|
+
const exampleSearchHub = 'example origin-level-1';
|
|
24
|
+
const exampleOriginLevel2 = 'example origin-level-2';
|
|
25
|
+
const exampleOriginLevel3 = 'example origin-level-3';
|
|
26
|
+
const exampleOriginContext = 'example origin-context';
|
|
27
|
+
const exampleSearchUID = 'foo';
|
|
28
|
+
const exampleLanguage = 'en';
|
|
29
|
+
const exampleClientId = '123-456';
|
|
30
|
+
|
|
23
31
|
let client: CaseAssistClient;
|
|
24
32
|
|
|
25
33
|
const provider: CaseAssistClientProvider = {
|
|
26
|
-
getOriginLevel1: () =>
|
|
34
|
+
getOriginLevel1: () => exampleSearchHub,
|
|
35
|
+
getOriginLevel2: () => exampleOriginLevel2,
|
|
36
|
+
getOriginLevel3: () => exampleOriginLevel3,
|
|
37
|
+
getOriginContext: () => exampleOriginContext,
|
|
38
|
+
getIsAnonymous: () => false,
|
|
39
|
+
getSearchUID: () => exampleSearchUID,
|
|
40
|
+
getLanguage: () => exampleLanguage,
|
|
27
41
|
};
|
|
28
42
|
|
|
29
43
|
beforeEach(() => {
|
|
30
44
|
fetchMockBeforeEach();
|
|
31
45
|
|
|
32
46
|
client = initClient();
|
|
47
|
+
client.coveoAnalyticsClient.runtime.storage.setItem('visitorId', exampleClientId);
|
|
33
48
|
fetchMock.mock(/.*/, {
|
|
34
49
|
visitorId: 'visitor-id',
|
|
35
50
|
});
|
|
@@ -76,18 +91,18 @@ describe('CaseAssistClient', () => {
|
|
|
76
91
|
};
|
|
77
92
|
};
|
|
78
93
|
|
|
79
|
-
const fakeDocumentSuggestion
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
94
|
+
const fakeDocumentSuggestion: DocumentSuggestion = {
|
|
95
|
+
responseId: 'document-suggestion-response-id',
|
|
96
|
+
suggestionId: 'document-suggestion-id',
|
|
97
|
+
permanentId: 'example permanent-id',
|
|
98
|
+
suggestion: {
|
|
99
|
+
documentPosition: 0,
|
|
100
|
+
documentTitle: 'the document title',
|
|
101
|
+
documentUri: 'some-document-uri',
|
|
102
|
+
documentUriHash: 'documenturihash',
|
|
103
|
+
documentUrl: 'some-document-url',
|
|
104
|
+
sourceName: 'example source-name',
|
|
105
|
+
},
|
|
91
106
|
};
|
|
92
107
|
|
|
93
108
|
const expectMatchPayload = (actionName: CaseAssistActions, actionData: Object, ticket: TicketProperties) => {
|
|
@@ -96,7 +111,23 @@ describe('CaseAssistClient', () => {
|
|
|
96
111
|
|
|
97
112
|
expectMatchActionPayload(content, actionName, actionData);
|
|
98
113
|
expectMatchTicketPayload(content, ticket);
|
|
99
|
-
expectMatchProperty(content, 'searchHub',
|
|
114
|
+
expectMatchProperty(content, 'searchHub', exampleSearchHub);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const expectMatchDocumentPayload = (actionCause: CaseAssistActions, doc: PartialDocumentInformation, meta = {}) => {
|
|
118
|
+
const body: string = lastCallBody(fetchMock);
|
|
119
|
+
const customData = {...meta};
|
|
120
|
+
expect(JSON.parse(body.toString())).toMatchObject({
|
|
121
|
+
actionCause,
|
|
122
|
+
customData,
|
|
123
|
+
language: exampleLanguage,
|
|
124
|
+
clientId: exampleClientId,
|
|
125
|
+
originContext: exampleOriginContext,
|
|
126
|
+
originLevel1: exampleSearchHub,
|
|
127
|
+
originLevel2: exampleOriginLevel2,
|
|
128
|
+
originLevel3: exampleOriginLevel3,
|
|
129
|
+
...doc,
|
|
130
|
+
});
|
|
100
131
|
};
|
|
101
132
|
|
|
102
133
|
const expectMatchActionPayload = (
|
|
@@ -241,33 +272,26 @@ describe('CaseAssistClient', () => {
|
|
|
241
272
|
|
|
242
273
|
it('should send proper payload for #logSelectDocumentSuggestion', async () => {
|
|
243
274
|
await client.logSelectDocumentSuggestion({
|
|
244
|
-
suggestion: fakeDocumentSuggestion
|
|
275
|
+
suggestion: fakeDocumentSuggestion,
|
|
245
276
|
ticket: fakeTicket,
|
|
246
277
|
});
|
|
247
278
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
it('should send proper payload for #logSelectDocumentSuggestion when the fromQuickview property is set to true', async () => {
|
|
252
|
-
const myFakeDocumentSuggestion = fakeDocumentSuggestion();
|
|
253
|
-
myFakeDocumentSuggestion.fromQuickview = true;
|
|
254
|
-
await client.logSelectDocumentSuggestion({
|
|
255
|
-
suggestion: myFakeDocumentSuggestion,
|
|
256
|
-
ticket: fakeTicket,
|
|
279
|
+
expectMatchDocumentPayload(CaseAssistActions.documentSuggestionClick, fakeDocumentSuggestion.suggestion, {
|
|
280
|
+
contentIDKey: 'permanentId',
|
|
281
|
+
contentIDValue: fakeDocumentSuggestion.permanentId,
|
|
257
282
|
});
|
|
258
|
-
|
|
259
|
-
expectMatchPayload(CaseAssistActions.suggestionClick, myFakeDocumentSuggestion, fakeTicket);
|
|
260
283
|
});
|
|
261
284
|
|
|
262
|
-
it('should send proper payload for #
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
await client.logSelectDocumentSuggestion({
|
|
266
|
-
suggestion: myFakeDocumentSuggestion,
|
|
285
|
+
it('should send proper payload for #logQuickviewDocumentSuggestion', async () => {
|
|
286
|
+
await client.logQuickviewDocumentSuggestion({
|
|
287
|
+
suggestion: fakeDocumentSuggestion,
|
|
267
288
|
ticket: fakeTicket,
|
|
268
289
|
});
|
|
269
290
|
|
|
270
|
-
|
|
291
|
+
expectMatchDocumentPayload(CaseAssistActions.documentSuggestionQuickview, fakeDocumentSuggestion.suggestion, {
|
|
292
|
+
contentIDKey: 'permanentId',
|
|
293
|
+
contentIDValue: fakeDocumentSuggestion.permanentId,
|
|
294
|
+
});
|
|
271
295
|
});
|
|
272
296
|
|
|
273
297
|
it('should send proper payload for #logRateDocumentSuggestion', async () => {
|
|
@@ -275,14 +299,14 @@ describe('CaseAssistClient', () => {
|
|
|
275
299
|
|
|
276
300
|
await client.logRateDocumentSuggestion({
|
|
277
301
|
rating,
|
|
278
|
-
suggestion: fakeDocumentSuggestion
|
|
302
|
+
suggestion: fakeDocumentSuggestion,
|
|
279
303
|
ticket: fakeTicket,
|
|
280
304
|
});
|
|
281
305
|
|
|
282
306
|
expectMatchPayload(
|
|
283
307
|
CaseAssistActions.suggestionRate,
|
|
284
308
|
{
|
|
285
|
-
...fakeDocumentSuggestion
|
|
309
|
+
...fakeDocumentSuggestion,
|
|
286
310
|
rate: rating,
|
|
287
311
|
},
|
|
288
312
|
fakeTicket
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import CoveoAnalyticsClient, {AnalyticsClient, ClientOptions} from '../client/analytics';
|
|
2
2
|
import {NoopAnalytics} from '../client/noopAnalytics';
|
|
3
3
|
import doNotTrack from '../donottrack';
|
|
4
|
+
import {ClickEventRequest} from '../events';
|
|
4
5
|
import {SVCPlugin} from '../plugins/svc';
|
|
6
|
+
import {DocumentIdentifier, PartialDocumentInformation, SearchPageEvents} from '../searchPage/searchPageEvents';
|
|
5
7
|
import {
|
|
6
8
|
CaseAssistActions,
|
|
7
9
|
CaseAssistEvents,
|
|
@@ -19,6 +21,12 @@ import {
|
|
|
19
21
|
|
|
20
22
|
export interface CaseAssistClientProvider {
|
|
21
23
|
getOriginLevel1: () => string;
|
|
24
|
+
getOriginLevel2: () => string;
|
|
25
|
+
getOriginLevel3: () => string;
|
|
26
|
+
getOriginContext: () => string;
|
|
27
|
+
getIsAnonymous: () => boolean;
|
|
28
|
+
getSearchUID: () => string;
|
|
29
|
+
getLanguage: () => string;
|
|
22
30
|
}
|
|
23
31
|
|
|
24
32
|
export interface CaseAssistClientOptions extends ClientOptions {
|
|
@@ -67,9 +75,17 @@ export class CaseAssistClient {
|
|
|
67
75
|
}
|
|
68
76
|
|
|
69
77
|
public logSelectDocumentSuggestion(meta: SelectDocumentSuggestionMetadata) {
|
|
70
|
-
this.
|
|
71
|
-
|
|
72
|
-
|
|
78
|
+
return this.logClickEvent(CaseAssistActions.documentSuggestionClick, meta.suggestion.suggestion, {
|
|
79
|
+
contentIDKey: 'permanentId',
|
|
80
|
+
contentIDValue: meta.suggestion.permanentId,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public logQuickviewDocumentSuggestion(meta: SelectDocumentSuggestionMetadata) {
|
|
85
|
+
return this.logClickEvent(CaseAssistActions.documentSuggestionQuickview, meta.suggestion.suggestion, {
|
|
86
|
+
contentIDKey: 'permanentId',
|
|
87
|
+
contentIDValue: meta.suggestion.permanentId,
|
|
88
|
+
});
|
|
73
89
|
}
|
|
74
90
|
|
|
75
91
|
public logRateDocumentSuggestion(meta: RateDocumentSuggestionMetadata) {
|
|
@@ -136,4 +152,46 @@ export class CaseAssistClient {
|
|
|
136
152
|
: null
|
|
137
153
|
);
|
|
138
154
|
}
|
|
155
|
+
|
|
156
|
+
private async getBaseEventRequest(metadata?: Record<string, any>) {
|
|
157
|
+
const customData = {...metadata};
|
|
158
|
+
return {
|
|
159
|
+
...this.getOrigins(),
|
|
160
|
+
customData,
|
|
161
|
+
language: this.provider?.getLanguage(),
|
|
162
|
+
anonymous: this.provider?.getIsAnonymous(),
|
|
163
|
+
clientId: await this.getClientId(),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private getClientId() {
|
|
168
|
+
return this.coveoAnalyticsClient instanceof CoveoAnalyticsClient
|
|
169
|
+
? this.coveoAnalyticsClient.getCurrentVisitorId()
|
|
170
|
+
: undefined;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
private getOrigins() {
|
|
174
|
+
return {
|
|
175
|
+
originContext: this.provider?.getOriginContext?.(),
|
|
176
|
+
originLevel1: this.provider?.getOriginLevel1(),
|
|
177
|
+
originLevel2: this.provider?.getOriginLevel2(),
|
|
178
|
+
originLevel3: this.provider?.getOriginLevel3(),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
private async logClickEvent(
|
|
183
|
+
event: CaseAssistActions,
|
|
184
|
+
info: PartialDocumentInformation,
|
|
185
|
+
identifier: DocumentIdentifier,
|
|
186
|
+
metadata?: Record<string, any>
|
|
187
|
+
) {
|
|
188
|
+
const payload: ClickEventRequest = {
|
|
189
|
+
...info,
|
|
190
|
+
...(await this.getBaseEventRequest({...identifier, ...metadata})),
|
|
191
|
+
searchQueryUid: this.provider?.getSearchUID() ?? '',
|
|
192
|
+
actionCause: event,
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
return this.coveoAnalyticsClient.sendClickEvent(payload);
|
|
196
|
+
}
|
|
139
197
|
}
|