coveo.analytics 2.18.55 → 2.18.62
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.js +1 -1
- package/dist/coveoua.js.map +1 -1
- package/dist/definitions/events.d.ts +2 -0
- package/dist/definitions/searchPage/searchPageClient.d.ts +2 -0
- package/dist/library.es.js +34 -14
- package/dist/library.js +80132 -235
- package/package.json +4 -3
- package/src/client/analytics.ts +3 -0
- package/src/events.ts +2 -1
- package/src/searchPage/searchPageClient.spec.ts +7 -1
- package/src/searchPage/searchPageClient.ts +25 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "coveo.analytics",
|
|
3
|
-
"version": "2.18.
|
|
3
|
+
"version": "2.18.62",
|
|
4
4
|
"description": "📈 Coveo analytics client (node and browser compatible) ",
|
|
5
5
|
"main": "dist/library.js",
|
|
6
6
|
"module": "dist/library.es.js",
|
|
@@ -23,12 +23,13 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@react-native-async-storage/async-storage": "^1.15.
|
|
27
|
-
"cross-fetch": "^3.1.
|
|
26
|
+
"@react-native-async-storage/async-storage": "^1.15.16",
|
|
27
|
+
"cross-fetch": "^3.1.5"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@rollup/plugin-alias": "^3.1.2",
|
|
31
31
|
"@rollup/plugin-commonjs": "^19.0.0",
|
|
32
|
+
"@rollup/plugin-json": "^4.1.0",
|
|
32
33
|
"@rollup/plugin-node-resolve": "^13.0.0",
|
|
33
34
|
"@types/fetch-mock": "^7.3.2",
|
|
34
35
|
"@types/jest": "^25.1.1",
|
package/src/client/analytics.ts
CHANGED
|
@@ -71,6 +71,9 @@ export interface AnalyticsClient {
|
|
|
71
71
|
registerAfterSendEventHook(hook: AnalyticsClientSendEventHook): void;
|
|
72
72
|
addEventTypeMapping(eventType: string, eventConfig: EventTypeConfig): void;
|
|
73
73
|
runtime: IRuntimeEnvironment;
|
|
74
|
+
/**
|
|
75
|
+
* @deprecated
|
|
76
|
+
*/
|
|
74
77
|
readonly currentVisitorId: string;
|
|
75
78
|
}
|
|
76
79
|
|
package/src/events.ts
CHANGED
|
@@ -56,6 +56,7 @@ describe('SearchPageClient', () => {
|
|
|
56
56
|
}),
|
|
57
57
|
getSearchUID: () => 'my-uid',
|
|
58
58
|
getPipeline: () => 'my-pipeline',
|
|
59
|
+
getOriginContext: () => 'origin-context',
|
|
59
60
|
getOriginLevel1: () => 'origin-level-1',
|
|
60
61
|
getOriginLevel2: () => 'origin-level-2',
|
|
61
62
|
getOriginLevel3: () => 'origin-level-3',
|
|
@@ -68,9 +69,9 @@ describe('SearchPageClient', () => {
|
|
|
68
69
|
fetchMockBeforeEach();
|
|
69
70
|
|
|
70
71
|
client = initClient();
|
|
72
|
+
client.coveoAnalyticsClient.runtime.storage.setItem('visitorId', 'visitor-id');
|
|
71
73
|
fetchMock.mock(/.*/, {
|
|
72
74
|
visitId: 'visit-id',
|
|
73
|
-
visitorId: 'visitor-id',
|
|
74
75
|
});
|
|
75
76
|
});
|
|
76
77
|
|
|
@@ -83,6 +84,7 @@ describe('SearchPageClient', () => {
|
|
|
83
84
|
};
|
|
84
85
|
|
|
85
86
|
const expectOrigins = () => ({
|
|
87
|
+
originContext: 'origin-context',
|
|
86
88
|
originLevel1: 'origin-level-1',
|
|
87
89
|
originLevel2: 'origin-level-2',
|
|
88
90
|
originLevel3: 'origin-level-3',
|
|
@@ -99,6 +101,7 @@ describe('SearchPageClient', () => {
|
|
|
99
101
|
customData,
|
|
100
102
|
facetState: fakeFacetState,
|
|
101
103
|
language: 'en',
|
|
104
|
+
clientId: 'visitor-id',
|
|
102
105
|
...expectOrigins(),
|
|
103
106
|
});
|
|
104
107
|
};
|
|
@@ -111,6 +114,7 @@ describe('SearchPageClient', () => {
|
|
|
111
114
|
customData,
|
|
112
115
|
queryPipeline: 'my-pipeline',
|
|
113
116
|
language: 'en',
|
|
117
|
+
clientId: 'visitor-id',
|
|
114
118
|
...doc,
|
|
115
119
|
...expectOrigins(),
|
|
116
120
|
});
|
|
@@ -125,6 +129,7 @@ describe('SearchPageClient', () => {
|
|
|
125
129
|
lastSearchQueryUid: 'my-uid',
|
|
126
130
|
customData,
|
|
127
131
|
language: 'en',
|
|
132
|
+
clientId: 'visitor-id',
|
|
128
133
|
...expectOrigins(),
|
|
129
134
|
});
|
|
130
135
|
};
|
|
@@ -138,6 +143,7 @@ describe('SearchPageClient', () => {
|
|
|
138
143
|
lastSearchQueryUid: 'my-uid',
|
|
139
144
|
customData,
|
|
140
145
|
language: 'en',
|
|
146
|
+
clientId: 'visitor-id',
|
|
141
147
|
...expectOrigins(),
|
|
142
148
|
});
|
|
143
149
|
};
|
|
@@ -33,6 +33,7 @@ export interface SearchPageClientProvider {
|
|
|
33
33
|
getSearchEventRequestPayload: () => Omit<SearchEventRequest, 'actionCause' | 'searchQueryUid'>;
|
|
34
34
|
getSearchUID: () => string;
|
|
35
35
|
getPipeline: () => string;
|
|
36
|
+
getOriginContext: () => string;
|
|
36
37
|
getOriginLevel1: () => string;
|
|
37
38
|
getOriginLevel2: () => string;
|
|
38
39
|
getOriginLevel3: () => string;
|
|
@@ -305,11 +306,11 @@ export class CoveoSearchPageClient {
|
|
|
305
306
|
return this.logSearchEvent(SearchPageEvents.noResultsBack);
|
|
306
307
|
}
|
|
307
308
|
|
|
308
|
-
public logCustomEvent(event: SearchPageEvents, metadata?: Record<string, any>) {
|
|
309
|
+
public async logCustomEvent(event: SearchPageEvents, metadata?: Record<string, any>) {
|
|
309
310
|
const customData = {...this.provider.getBaseMetadata(), ...metadata};
|
|
310
311
|
|
|
311
312
|
const payload: CustomEventRequest = {
|
|
312
|
-
...this.getBaseCustomEventRequest(customData),
|
|
313
|
+
...(await this.getBaseCustomEventRequest(customData)),
|
|
313
314
|
eventType: CustomEventsTypes[event]!,
|
|
314
315
|
eventValue: event,
|
|
315
316
|
};
|
|
@@ -317,22 +318,22 @@ export class CoveoSearchPageClient {
|
|
|
317
318
|
return this.coveoAnalyticsClient.sendCustomEvent(payload);
|
|
318
319
|
}
|
|
319
320
|
|
|
320
|
-
public logCustomEventWithType(eventValue: string, eventType: string, metadata?: Record<string, any>) {
|
|
321
|
+
public async logCustomEventWithType(eventValue: string, eventType: string, metadata?: Record<string, any>) {
|
|
321
322
|
const customData = {...this.provider.getBaseMetadata(), ...metadata};
|
|
322
323
|
|
|
323
324
|
const payload: CustomEventRequest = {
|
|
324
|
-
...this.getBaseCustomEventRequest(customData),
|
|
325
|
+
...(await this.getBaseCustomEventRequest(customData)),
|
|
325
326
|
eventType,
|
|
326
327
|
eventValue,
|
|
327
328
|
};
|
|
328
329
|
return this.coveoAnalyticsClient.sendCustomEvent(payload);
|
|
329
330
|
}
|
|
330
331
|
|
|
331
|
-
public logSearchEvent(event: SearchPageEvents, metadata?: Record<string, any>) {
|
|
332
|
-
return this.coveoAnalyticsClient.sendSearchEvent(this.getBaseSearchEventRequest(event, metadata));
|
|
332
|
+
public async logSearchEvent(event: SearchPageEvents, metadata?: Record<string, any>) {
|
|
333
|
+
return this.coveoAnalyticsClient.sendSearchEvent(await this.getBaseSearchEventRequest(event, metadata));
|
|
333
334
|
}
|
|
334
335
|
|
|
335
|
-
public logClickEvent(
|
|
336
|
+
public async logClickEvent(
|
|
336
337
|
event: SearchPageEvents,
|
|
337
338
|
info: PartialDocumentInformation,
|
|
338
339
|
identifier: DocumentIdentifier,
|
|
@@ -340,7 +341,7 @@ export class CoveoSearchPageClient {
|
|
|
340
341
|
) {
|
|
341
342
|
const payload: ClickEventRequest = {
|
|
342
343
|
...info,
|
|
343
|
-
...this.getBaseEventRequest({...identifier, ...metadata}),
|
|
344
|
+
...(await this.getBaseEventRequest({...identifier, ...metadata})),
|
|
344
345
|
searchQueryUid: this.provider.getSearchUID(),
|
|
345
346
|
queryPipeline: this.provider.getPipeline(),
|
|
346
347
|
actionCause: event,
|
|
@@ -349,9 +350,12 @@ export class CoveoSearchPageClient {
|
|
|
349
350
|
return this.coveoAnalyticsClient.sendClickEvent(payload);
|
|
350
351
|
}
|
|
351
352
|
|
|
352
|
-
private getBaseSearchEventRequest(
|
|
353
|
+
private async getBaseSearchEventRequest(
|
|
354
|
+
event: SearchPageEvents,
|
|
355
|
+
metadata?: Record<string, any>
|
|
356
|
+
): Promise<SearchEventRequest> {
|
|
353
357
|
return {
|
|
354
|
-
...this.getBaseEventRequest(metadata),
|
|
358
|
+
...(await this.getBaseEventRequest(metadata)),
|
|
355
359
|
...this.provider.getSearchEventRequestPayload(),
|
|
356
360
|
searchQueryUid: this.provider.getSearchUID(),
|
|
357
361
|
queryPipeline: this.provider.getPipeline(),
|
|
@@ -359,14 +363,14 @@ export class CoveoSearchPageClient {
|
|
|
359
363
|
};
|
|
360
364
|
}
|
|
361
365
|
|
|
362
|
-
private getBaseCustomEventRequest(metadata?: Record<string, any>) {
|
|
366
|
+
private async getBaseCustomEventRequest(metadata?: Record<string, any>) {
|
|
363
367
|
return {
|
|
364
|
-
...this.getBaseEventRequest(metadata),
|
|
368
|
+
...(await this.getBaseEventRequest(metadata)),
|
|
365
369
|
lastSearchQueryUid: this.provider.getSearchUID(),
|
|
366
370
|
};
|
|
367
371
|
}
|
|
368
372
|
|
|
369
|
-
private getBaseEventRequest(metadata?: Record<string, any>) {
|
|
373
|
+
private async getBaseEventRequest(metadata?: Record<string, any>) {
|
|
370
374
|
const customData = {...this.provider.getBaseMetadata(), ...metadata};
|
|
371
375
|
return {
|
|
372
376
|
...this.getOrigins(),
|
|
@@ -374,14 +378,22 @@ export class CoveoSearchPageClient {
|
|
|
374
378
|
language: this.provider.getLanguage(),
|
|
375
379
|
facetState: this.provider.getFacetState ? this.provider.getFacetState() : [],
|
|
376
380
|
anonymous: this.provider.getIsAnonymous(),
|
|
381
|
+
clientId: await this.getClientId(),
|
|
377
382
|
};
|
|
378
383
|
}
|
|
379
384
|
|
|
380
385
|
private getOrigins() {
|
|
381
386
|
return {
|
|
387
|
+
originContext: this.provider.getOriginContext(),
|
|
382
388
|
originLevel1: this.provider.getOriginLevel1(),
|
|
383
389
|
originLevel2: this.provider.getOriginLevel2(),
|
|
384
390
|
originLevel3: this.provider.getOriginLevel3(),
|
|
385
391
|
};
|
|
386
392
|
}
|
|
393
|
+
|
|
394
|
+
private getClientId() {
|
|
395
|
+
return this.coveoAnalyticsClient instanceof CoveoAnalyticsClient
|
|
396
|
+
? this.coveoAnalyticsClient.getCurrentVisitorId()
|
|
397
|
+
: undefined;
|
|
398
|
+
}
|
|
387
399
|
}
|