coveo.analytics 2.22.1 → 2.22.2
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/insight/insightClient.d.ts +3 -1
- package/dist/library.es.js +9 -0
- package/dist/library.js +18 -0
- package/dist/react-native.es.js +9 -0
- package/package.json +1 -1
- package/src/insight/insightClient.spec.ts +53 -1
- package/src/insight/insightClient.ts +33 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AnalyticsClient, ClientOptions } from '../client/analytics';
|
|
2
2
|
import { SearchEventRequest } from '../events';
|
|
3
|
-
import { FacetStateMetadata, SearchPageEvents } from '../searchPage/searchPageEvents';
|
|
3
|
+
import { DocumentIdentifier, FacetStateMetadata, PartialDocumentInformation, SearchPageEvents } from '../searchPage/searchPageEvents';
|
|
4
4
|
import { ExpandToFullUIMetadata, InsightEvents, InsightFacetMetadata, InsightInterfaceChangeMetadata, InsightStaticFilterToggleValueMetadata, InsightFacetRangeMetadata, InsightCategoryFacetMetadata, CaseMetadata, InsightFacetSortMeta, InsightFacetBaseMeta, InsightQueryErrorMeta, InsightPagerMetadata, InsightResultsSortMetadata } from './insightEvents';
|
|
5
5
|
export interface InsightClientProvider {
|
|
6
6
|
getSearchEventRequestPayload: () => Omit<SearchEventRequest, 'actionCause' | 'searchQueryUid'>;
|
|
@@ -47,8 +47,10 @@ export declare class CoveoInsightClient {
|
|
|
47
47
|
logSearchboxSubmit(metadata?: CaseMetadata): Promise<void | import("../events").SearchEventResponse>;
|
|
48
48
|
logContextChanged(metadata: CaseMetadata): Promise<void | import("../events").SearchEventResponse>;
|
|
49
49
|
logExpandToFullUI(metadata: ExpandToFullUIMetadata): Promise<void | import("../events").CustomEventResponse>;
|
|
50
|
+
logDocumentOpen(info: PartialDocumentInformation, identifier: DocumentIdentifier, metadata?: CaseMetadata): Promise<void | import("../events").ClickEventResponse>;
|
|
50
51
|
logCustomEvent(event: SearchPageEvents | InsightEvents, metadata?: Record<string, any>): Promise<void | import("../events").CustomEventResponse>;
|
|
51
52
|
logSearchEvent(event: SearchPageEvents | InsightEvents, metadata?: Record<string, any>): Promise<void | import("../events").SearchEventResponse>;
|
|
53
|
+
logClickEvent(event: SearchPageEvents, info: PartialDocumentInformation, identifier: DocumentIdentifier, metadata?: Record<string, any>): Promise<void | import("../events").ClickEventResponse>;
|
|
52
54
|
private getBaseCustomEventRequest;
|
|
53
55
|
private getBaseSearchEventRequest;
|
|
54
56
|
private getBaseEventRequest;
|
package/dist/library.es.js
CHANGED
|
@@ -2191,6 +2191,9 @@ class CoveoInsightClient {
|
|
|
2191
2191
|
const metadataToSend = generateMetadataToSend(metadata);
|
|
2192
2192
|
return this.logCustomEvent(InsightEvents.expandToFullUI, metadataToSend);
|
|
2193
2193
|
}
|
|
2194
|
+
logDocumentOpen(info, identifier, metadata) {
|
|
2195
|
+
return this.logClickEvent(SearchPageEvents.documentOpen, info, identifier, metadata ? generateMetadataToSend(metadata, false) : undefined);
|
|
2196
|
+
}
|
|
2194
2197
|
logCustomEvent(event, metadata) {
|
|
2195
2198
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2196
2199
|
const customData = Object.assign(Object.assign({}, this.provider.getBaseMetadata()), metadata);
|
|
@@ -2203,6 +2206,12 @@ class CoveoInsightClient {
|
|
|
2203
2206
|
return this.coveoAnalyticsClient.sendSearchEvent(yield this.getBaseSearchEventRequest(event, metadata));
|
|
2204
2207
|
});
|
|
2205
2208
|
}
|
|
2209
|
+
logClickEvent(event, info, identifier, metadata) {
|
|
2210
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2211
|
+
const payload = Object.assign(Object.assign(Object.assign({}, info), (yield this.getBaseEventRequest(Object.assign(Object.assign({}, identifier), metadata)))), { searchQueryUid: this.provider.getSearchUID(), queryPipeline: this.provider.getPipeline(), actionCause: event });
|
|
2212
|
+
return this.coveoAnalyticsClient.sendClickEvent(payload);
|
|
2213
|
+
});
|
|
2214
|
+
}
|
|
2206
2215
|
getBaseCustomEventRequest(metadata) {
|
|
2207
2216
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2208
2217
|
return Object.assign(Object.assign({}, (yield this.getBaseEventRequest(metadata))), { lastSearchQueryUid: this.provider.getSearchUID() });
|
package/dist/library.js
CHANGED
|
@@ -84613,6 +84613,9 @@ var CoveoInsightClient = (function () {
|
|
|
84613
84613
|
var metadataToSend = generateMetadataToSend(metadata);
|
|
84614
84614
|
return this.logCustomEvent(InsightEvents.expandToFullUI, metadataToSend);
|
|
84615
84615
|
};
|
|
84616
|
+
CoveoInsightClient.prototype.logDocumentOpen = function (info, identifier, metadata) {
|
|
84617
|
+
return this.logClickEvent(SearchPageEvents.documentOpen, info, identifier, metadata ? generateMetadataToSend(metadata, false) : undefined);
|
|
84618
|
+
};
|
|
84616
84619
|
CoveoInsightClient.prototype.logCustomEvent = function (event, metadata) {
|
|
84617
84620
|
return __awaiter(this, void 0, void 0, function () {
|
|
84618
84621
|
var customData, payload, _a;
|
|
@@ -84642,6 +84645,21 @@ var CoveoInsightClient = (function () {
|
|
|
84642
84645
|
});
|
|
84643
84646
|
});
|
|
84644
84647
|
};
|
|
84648
|
+
CoveoInsightClient.prototype.logClickEvent = function (event, info, identifier, metadata) {
|
|
84649
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
84650
|
+
var payload, _a;
|
|
84651
|
+
return __generator(this, function (_b) {
|
|
84652
|
+
switch (_b.label) {
|
|
84653
|
+
case 0:
|
|
84654
|
+
_a = [__assign({}, info)];
|
|
84655
|
+
return [4, this.getBaseEventRequest(__assign(__assign({}, identifier), metadata))];
|
|
84656
|
+
case 1:
|
|
84657
|
+
payload = __assign.apply(void 0, [__assign.apply(void 0, _a.concat([(_b.sent())])), { searchQueryUid: this.provider.getSearchUID(), queryPipeline: this.provider.getPipeline(), actionCause: event }]);
|
|
84658
|
+
return [2, this.coveoAnalyticsClient.sendClickEvent(payload)];
|
|
84659
|
+
}
|
|
84660
|
+
});
|
|
84661
|
+
});
|
|
84662
|
+
};
|
|
84645
84663
|
CoveoInsightClient.prototype.getBaseCustomEventRequest = function (metadata) {
|
|
84646
84664
|
return __awaiter(this, void 0, void 0, function () {
|
|
84647
84665
|
var _a;
|
package/dist/react-native.es.js
CHANGED
|
@@ -2208,6 +2208,9 @@ class CoveoInsightClient {
|
|
|
2208
2208
|
const metadataToSend = generateMetadataToSend(metadata);
|
|
2209
2209
|
return this.logCustomEvent(InsightEvents.expandToFullUI, metadataToSend);
|
|
2210
2210
|
}
|
|
2211
|
+
logDocumentOpen(info, identifier, metadata) {
|
|
2212
|
+
return this.logClickEvent(SearchPageEvents.documentOpen, info, identifier, metadata ? generateMetadataToSend(metadata, false) : undefined);
|
|
2213
|
+
}
|
|
2211
2214
|
logCustomEvent(event, metadata) {
|
|
2212
2215
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2213
2216
|
const customData = Object.assign(Object.assign({}, this.provider.getBaseMetadata()), metadata);
|
|
@@ -2220,6 +2223,12 @@ class CoveoInsightClient {
|
|
|
2220
2223
|
return this.coveoAnalyticsClient.sendSearchEvent(yield this.getBaseSearchEventRequest(event, metadata));
|
|
2221
2224
|
});
|
|
2222
2225
|
}
|
|
2226
|
+
logClickEvent(event, info, identifier, metadata) {
|
|
2227
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2228
|
+
const payload = Object.assign(Object.assign(Object.assign({}, info), (yield this.getBaseEventRequest(Object.assign(Object.assign({}, identifier), metadata)))), { searchQueryUid: this.provider.getSearchUID(), queryPipeline: this.provider.getPipeline(), actionCause: event });
|
|
2229
|
+
return this.coveoAnalyticsClient.sendClickEvent(payload);
|
|
2230
|
+
});
|
|
2231
|
+
}
|
|
2223
2232
|
getBaseCustomEventRequest(metadata) {
|
|
2224
2233
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2225
2234
|
return Object.assign(Object.assign({}, (yield this.getBaseEventRequest(metadata))), { lastSearchQueryUid: this.provider.getSearchUID() });
|
package/package.json
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import {mockFetch} from '../../tests/fetchMock';
|
|
2
2
|
import CoveoAnalyticsClient from '../client/analytics';
|
|
3
3
|
import {NoopAnalytics} from '../client/noopAnalytics';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
CustomEventsTypes,
|
|
6
|
+
PartialDocumentInformation,
|
|
7
|
+
SearchPageEvents,
|
|
8
|
+
StaticFilterToggleValueMetadata,
|
|
9
|
+
} from '../searchPage/searchPageEvents';
|
|
5
10
|
import {CoveoInsightClient, InsightClientProvider} from './insightClient';
|
|
6
11
|
import doNotTrack from '../donottrack';
|
|
7
12
|
import {InsightEvents, InsightStaticFilterToggleValueMetadata} from './insightEvents';
|
|
@@ -101,6 +106,37 @@ describe('InsightClient', () => {
|
|
|
101
106
|
});
|
|
102
107
|
};
|
|
103
108
|
|
|
109
|
+
const expectMatchDocumentPayload = (actionCause: SearchPageEvents, doc: PartialDocumentInformation, meta = {}) => {
|
|
110
|
+
const [, {body}] = fetchMock.lastCall();
|
|
111
|
+
const customData = {foo: 'bar', ...meta};
|
|
112
|
+
expect(JSON.parse(body.toString())).toMatchObject({
|
|
113
|
+
actionCause,
|
|
114
|
+
customData,
|
|
115
|
+
language: 'en',
|
|
116
|
+
clientId: 'visitor-id',
|
|
117
|
+
...doc,
|
|
118
|
+
...expectOrigins(),
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const fakeDocInfo = {
|
|
123
|
+
collectionName: 'collection',
|
|
124
|
+
documentAuthor: 'author',
|
|
125
|
+
documentPosition: 1,
|
|
126
|
+
documentTitle: 'title',
|
|
127
|
+
documentUri: 'uri',
|
|
128
|
+
documentUriHash: 'hash',
|
|
129
|
+
documentUrl: 'url',
|
|
130
|
+
queryPipeline: 'my-pipeline',
|
|
131
|
+
rankingModifier: 'modifier',
|
|
132
|
+
sourceName: 'source',
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const fakeDocID = {
|
|
136
|
+
contentIDKey: 'permanentID',
|
|
137
|
+
contentIDValue: 'the-permanent-id',
|
|
138
|
+
};
|
|
139
|
+
|
|
104
140
|
beforeEach(() => {
|
|
105
141
|
fetchMockBeforeEach();
|
|
106
142
|
|
|
@@ -277,6 +313,11 @@ describe('InsightClient', () => {
|
|
|
277
313
|
await client.logSearchboxSubmit();
|
|
278
314
|
expectMatchPayload(SearchPageEvents.searchboxSubmit);
|
|
279
315
|
});
|
|
316
|
+
|
|
317
|
+
it('should send proper payload for #documentOpen', async () => {
|
|
318
|
+
await client.logDocumentOpen(fakeDocInfo, fakeDocID);
|
|
319
|
+
expectMatchDocumentPayload(SearchPageEvents.documentOpen, fakeDocInfo, fakeDocID);
|
|
320
|
+
});
|
|
280
321
|
});
|
|
281
322
|
|
|
282
323
|
describe('when the case metadata is included', () => {
|
|
@@ -623,6 +664,17 @@ describe('InsightClient', () => {
|
|
|
623
664
|
await client.logSearchboxSubmit(metadata);
|
|
624
665
|
expectMatchPayload(SearchPageEvents.searchboxSubmit, expectedMetadata);
|
|
625
666
|
});
|
|
667
|
+
|
|
668
|
+
it('should send proper payload for #documentOpen', async () => {
|
|
669
|
+
const metadata = baseCaseMetadata;
|
|
670
|
+
|
|
671
|
+
const expectedMetadata = {
|
|
672
|
+
...fakeDocID,
|
|
673
|
+
...expectedBaseCaseMetadata,
|
|
674
|
+
};
|
|
675
|
+
await client.logDocumentOpen(fakeDocInfo, fakeDocID, metadata);
|
|
676
|
+
expectMatchDocumentPayload(SearchPageEvents.documentOpen, fakeDocInfo, expectedMetadata);
|
|
677
|
+
});
|
|
626
678
|
});
|
|
627
679
|
|
|
628
680
|
it('should enable analytics tracking by default', () => {
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import CoveoAnalyticsClient, {AnalyticsClient, ClientOptions} from '../client/analytics';
|
|
2
2
|
import {NoopAnalytics} from '../client/noopAnalytics';
|
|
3
3
|
import doNotTrack from '../donottrack';
|
|
4
|
-
import {CustomEventRequest, SearchEventRequest} from '../events';
|
|
5
|
-
import {
|
|
4
|
+
import {ClickEventRequest, CustomEventRequest, SearchEventRequest} from '../events';
|
|
5
|
+
import {
|
|
6
|
+
CustomEventsTypes,
|
|
7
|
+
DocumentIdentifier,
|
|
8
|
+
FacetStateMetadata,
|
|
9
|
+
PartialDocumentInformation,
|
|
10
|
+
SearchPageEvents,
|
|
11
|
+
} from '../searchPage/searchPageEvents';
|
|
6
12
|
import {
|
|
7
13
|
ExpandToFullUIMetadata,
|
|
8
14
|
InsightEvents,
|
|
@@ -213,6 +219,14 @@ export class CoveoInsightClient {
|
|
|
213
219
|
return this.logCustomEvent(InsightEvents.expandToFullUI, metadataToSend);
|
|
214
220
|
}
|
|
215
221
|
|
|
222
|
+
public logDocumentOpen(info: PartialDocumentInformation, identifier: DocumentIdentifier, metadata?: CaseMetadata) {
|
|
223
|
+
return this.logClickEvent(
|
|
224
|
+
SearchPageEvents.documentOpen,
|
|
225
|
+
info,
|
|
226
|
+
identifier,
|
|
227
|
+
metadata ? generateMetadataToSend(metadata, false) : undefined);
|
|
228
|
+
}
|
|
229
|
+
|
|
216
230
|
public async logCustomEvent(event: SearchPageEvents | InsightEvents, metadata?: Record<string, any>) {
|
|
217
231
|
const customData = {...this.provider.getBaseMetadata(), ...metadata};
|
|
218
232
|
|
|
@@ -229,6 +243,23 @@ export class CoveoInsightClient {
|
|
|
229
243
|
return this.coveoAnalyticsClient.sendSearchEvent(await this.getBaseSearchEventRequest(event, metadata));
|
|
230
244
|
}
|
|
231
245
|
|
|
246
|
+
public async logClickEvent(
|
|
247
|
+
event: SearchPageEvents,
|
|
248
|
+
info: PartialDocumentInformation,
|
|
249
|
+
identifier: DocumentIdentifier,
|
|
250
|
+
metadata?: Record<string, any>
|
|
251
|
+
) {
|
|
252
|
+
const payload: ClickEventRequest = {
|
|
253
|
+
...info,
|
|
254
|
+
...(await this.getBaseEventRequest({...identifier, ...metadata})),
|
|
255
|
+
searchQueryUid: this.provider.getSearchUID(),
|
|
256
|
+
queryPipeline: this.provider.getPipeline(),
|
|
257
|
+
actionCause: event,
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
return this.coveoAnalyticsClient.sendClickEvent(payload);
|
|
261
|
+
}
|
|
262
|
+
|
|
232
263
|
private async getBaseCustomEventRequest(metadata?: Record<string, any>) {
|
|
233
264
|
return {
|
|
234
265
|
...(await this.getBaseEventRequest(metadata)),
|