coveo.analytics 2.30.1 → 2.30.3

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.
@@ -45,12 +45,12 @@ describe('EC plugin', () => {
45
45
  expect(result).toEqual({...defaultResult, pr1id: 'C0V30'});
46
46
  });
47
47
 
48
- it('should append the product with the pageview event', () => {
48
+ it('should not append the product with the pageview event', () => {
49
49
  ec.addProduct({name: 'Relevance T-Shirt'});
50
50
 
51
- const result = executeRegisteredHook(ECPluginEventTypes.event, {});
51
+ const result = executeRegisteredHook(ECPluginEventTypes.pageview, {});
52
52
 
53
- expect(result).toEqual({...defaultResult, pr1nm: 'Relevance T-Shirt'});
53
+ expect(result).toEqual({...defaultResult, hitType: ECPluginEventTypes.pageview});
54
54
  });
55
55
 
56
56
  it('should not append the product with a random event type', () => {
@@ -61,14 +61,15 @@ describe('EC plugin', () => {
61
61
  expect(result).toEqual({});
62
62
  });
63
63
 
64
- it('should keep the products until a valid event type is used', () => {
64
+ it('should keep the products until an event type is used', () => {
65
65
  ec.addProduct({id: 'P12345'});
66
66
 
67
67
  executeRegisteredHook('🎲', {});
68
68
  executeRegisteredHook('🐟', {});
69
- executeRegisteredHook('💀', {});
69
+ const pageviewResult = executeRegisteredHook(ECPluginEventTypes.pageview, {});
70
70
  const result = executeRegisteredHook(ECPluginEventTypes.event, {});
71
71
 
72
+ expect(pageviewResult).toEqual({...defaultResult, hitType: ECPluginEventTypes.pageview});
72
73
  expect(result).toEqual({...defaultResult, pr1id: 'P12345'});
73
74
  });
74
75
 
@@ -119,6 +120,18 @@ describe('EC plugin', () => {
119
120
  expect(secondResult).toEqual({...defaultResult});
120
121
  });
121
122
 
123
+ it('should not flush the products when the pageview is sent', () => {
124
+ ec.addProduct({name: 'boup'});
125
+
126
+ const result = executeRegisteredHook(ECPluginEventTypes.pageview, {});
127
+
128
+ expect(result).not.toEqual({});
129
+
130
+ const secondResult = executeRegisteredHook(ECPluginEventTypes.event, {});
131
+
132
+ expect(secondResult).toEqual({...defaultResult, pr1nm: 'boup'});
133
+ });
134
+
122
135
  it('should convert position to number if possible', () => {
123
136
  const validValues = ['13', '5.5'];
124
137
  for (const value of validValues) {
@@ -264,14 +277,14 @@ describe('EC plugin', () => {
264
277
  expect(result).toEqual({...defaultResult, il1pi1id: 'C0V30'});
265
278
  });
266
279
 
267
- it('should append the impression with the pageview event', () => {
280
+ it('should not append the impression with the pageview event', () => {
268
281
  ec.addImpression({name: 'Relevance T-Shirt'});
269
282
 
270
- const result = executeRegisteredHook(ECPluginEventTypes.event, {});
283
+ const result = executeRegisteredHook(ECPluginEventTypes.pageview, {});
271
284
 
272
285
  expect(result).toEqual({
273
286
  ...defaultResult,
274
- il1pi1nm: 'Relevance T-Shirt',
287
+ hitType: ECPluginEventTypes.pageview,
275
288
  });
276
289
  });
277
290
 
@@ -283,14 +296,15 @@ describe('EC plugin', () => {
283
296
  expect(result).toEqual({});
284
297
  });
285
298
 
286
- it('should keep the impressions until a valid event type is used', () => {
299
+ it('should keep the impressions until an event type is used', () => {
287
300
  ec.addImpression({id: 'P12345'});
288
301
 
289
302
  executeRegisteredHook('🎲', {});
290
303
  executeRegisteredHook('🐟', {});
291
- executeRegisteredHook('💀', {});
304
+ const pageviewResult = executeRegisteredHook(ECPluginEventTypes.pageview, {});
292
305
  const result = executeRegisteredHook(ECPluginEventTypes.event, {});
293
306
 
307
+ expect(pageviewResult).toEqual({...defaultResult, hitType: ECPluginEventTypes.pageview});
294
308
  expect(result).toEqual({...defaultResult, il1pi1id: 'P12345'});
295
309
  });
296
310
 
@@ -372,7 +386,7 @@ describe('EC plugin', () => {
372
386
  });
373
387
  });
374
388
 
375
- it('should flush the products once they are sent', () => {
389
+ it('should flush the impressions once they are sent', () => {
376
390
  ec.addImpression({name: '🍟', price: 1.99});
377
391
  ec.addImpression({name: '🍿', price: 3});
378
392
 
@@ -385,6 +399,18 @@ describe('EC plugin', () => {
385
399
  expect(secondResult).toEqual({...defaultResult});
386
400
  });
387
401
 
402
+ it('should not flush the impressions when a pageview is sent', () => {
403
+ ec.addImpression({name: 'bap'});
404
+
405
+ const result = executeRegisteredHook(ECPluginEventTypes.pageview, {});
406
+
407
+ expect(result).not.toEqual({});
408
+
409
+ const secondResult = executeRegisteredHook(ECPluginEventTypes.event, {});
410
+
411
+ expect(secondResult).toEqual({...defaultResult, il1pi1nm: 'bap'});
412
+ });
413
+
388
414
  describe('when the position is invalid', () => {
389
415
  it('should warn when executing hook on added impression', () => {
390
416
  jest.spyOn(console, 'warn').mockImplementation();
@@ -480,6 +506,17 @@ describe('EC plugin', () => {
480
506
  });
481
507
  });
482
508
 
509
+ it('should not set an action with a pageview', () => {
510
+ ec.setAction('ok');
511
+
512
+ const result = executeRegisteredHook(ECPluginEventTypes.pageview, {});
513
+
514
+ expect(result).toEqual({
515
+ ...defaultResult,
516
+ hitType: ECPluginEventTypes.pageview,
517
+ });
518
+ });
519
+
483
520
  it('should flush the action once it is sent', () => {
484
521
  ec.setAction('ok');
485
522
 
@@ -492,6 +529,18 @@ describe('EC plugin', () => {
492
529
  expect(secondResult).toEqual({...defaultResult});
493
530
  });
494
531
 
532
+ it('should not flush the action with the pageview', () => {
533
+ ec.setAction('ok');
534
+
535
+ const result = executeRegisteredHook(ECPluginEventTypes.pageview, {});
536
+
537
+ expect(result).not.toEqual({});
538
+
539
+ const secondResult = executeRegisteredHook(ECPluginEventTypes.event, {});
540
+
541
+ expect(secondResult).toEqual({...defaultResult, action: 'ok'});
542
+ });
543
+
495
544
  it('should be able to clear all the data', () => {
496
545
  ec.addProduct({name: '🍨', price: 2.99});
497
546
  ec.addImpression({id: '🍦', price: 3.49});
package/src/plugins/ec.ts CHANGED
@@ -135,6 +135,14 @@ export class ECPlugin extends BasePlugin {
135
135
  }
136
136
 
137
137
  private addECDataToPayload(eventType: string, payload: any) {
138
+ if (eventType === ECPluginEventTypes.pageview) {
139
+ return {
140
+ ...this.getLocationInformation(eventType, payload),
141
+ ...this.getDefaultContextInformation(eventType),
142
+ ...payload,
143
+ };
144
+ }
145
+
138
146
  const ecPayload = {
139
147
  ...this.getLocationInformation(eventType, payload),
140
148
  ...this.getDefaultContextInformation(eventType),
@@ -1573,6 +1573,34 @@ describe('SearchPageClient', () => {
1573
1573
  expectMatchDescription(built.description, SearchPageEvents.generatedAnswerShowAnswers, meta);
1574
1574
  });
1575
1575
 
1576
+ it('should send proper payload for #logGeneratedAnswerExpand', async () => {
1577
+ const meta = {generativeQuestionAnsweringId: fakeStreamId};
1578
+ await client.logGeneratedAnswerExpand(meta);
1579
+ expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerExpand, meta);
1580
+ });
1581
+
1582
+ it('should send proper payload for #makeGeneratedAnswerExpand', async () => {
1583
+ const meta = {generativeQuestionAnsweringId: fakeStreamId};
1584
+ const built = await client.makeGeneratedAnswerExpand(meta);
1585
+ await built.log({searchUID: provider.getSearchUID()});
1586
+ expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerExpand, meta);
1587
+ expectMatchDescription(built.description, SearchPageEvents.generatedAnswerExpand, meta);
1588
+ });
1589
+
1590
+ it('should send proper payload for #logGeneratedAnswerCollapse', async () => {
1591
+ const meta = {generativeQuestionAnsweringId: fakeStreamId};
1592
+ await client.logGeneratedAnswerCollapse(meta);
1593
+ expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerCollapse, meta);
1594
+ });
1595
+
1596
+ it('should send proper payload for #makeGeneratedAnswerCollapse', async () => {
1597
+ const meta = {generativeQuestionAnsweringId: fakeStreamId};
1598
+ const built = await client.makeGeneratedAnswerCollapse(meta);
1599
+ await built.log({searchUID: provider.getSearchUID()});
1600
+ expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerCollapse, meta);
1601
+ expectMatchDescription(built.description, SearchPageEvents.generatedAnswerCollapse, meta);
1602
+ });
1603
+
1576
1604
  it('should send proper payload for #logGeneratedAnswerFeedbackSubmit', async () => {
1577
1605
  const meta = {
1578
1606
  generativeQuestionAnsweringId: fakeStreamId,
@@ -951,6 +951,22 @@ export class CoveoSearchPageClient {
951
951
  });
952
952
  }
953
953
 
954
+ public makeGeneratedAnswerExpand(metadata: GeneratedAnswerBaseMeta) {
955
+ return this.makeCustomEvent(SearchPageEvents.generatedAnswerExpand, metadata);
956
+ }
957
+
958
+ public async logGeneratedAnswerExpand(metadata: GeneratedAnswerBaseMeta) {
959
+ return (await this.makeGeneratedAnswerExpand(metadata)).log({searchUID: this.provider.getSearchUID()});
960
+ }
961
+
962
+ public makeGeneratedAnswerCollapse(metadata: GeneratedAnswerBaseMeta) {
963
+ return this.makeCustomEvent(SearchPageEvents.generatedAnswerCollapse, metadata);
964
+ }
965
+
966
+ public async logGeneratedAnswerCollapse(metadata: GeneratedAnswerBaseMeta) {
967
+ return (await this.makeGeneratedAnswerCollapse(metadata)).log({searchUID: this.provider.getSearchUID()});
968
+ }
969
+
954
970
  public makeGeneratedAnswerFeedbackSubmit(meta: GeneratedAnswerFeedbackMeta) {
955
971
  return this.makeCustomEvent(SearchPageEvents.generatedAnswerFeedbackSubmit, meta);
956
972
  }
@@ -330,6 +330,14 @@ export enum SearchPageEvents {
330
330
  * Identifies the custom event that gets logged when a user activates the genQA feature.
331
331
  */
332
332
  generatedAnswerShowAnswers = 'generatedAnswerShowAnswers',
333
+ /**
334
+ * Identifies the custom event that gets logged when a user expand a generated answer.
335
+ */
336
+ generatedAnswerExpand = 'generatedAnswerExpand',
337
+ /**
338
+ * Identifies the custom event that gets logged when a user collapse a generated answer.
339
+ */
340
+ generatedAnswerCollapse = 'generatedAnswerCollapse',
333
341
  /**
334
342
  * Identifies the custom event that gets logged when a user submits a feedback of a generated answer.
335
343
  */
@@ -382,6 +390,8 @@ export const CustomEventsTypes: Partial<Record<SearchPageEvents | InsightEvents,
382
390
  [SearchPageEvents.generatedAnswerCopyToClipboard]: 'generatedAnswer',
383
391
  [SearchPageEvents.generatedAnswerHideAnswers]: 'generatedAnswer',
384
392
  [SearchPageEvents.generatedAnswerShowAnswers]: 'generatedAnswer',
393
+ [SearchPageEvents.generatedAnswerExpand]: 'generatedAnswer',
394
+ [SearchPageEvents.generatedAnswerCollapse]: 'generatedAnswer',
385
395
  [SearchPageEvents.generatedAnswerFeedbackSubmit]: 'generatedAnswer',
386
396
  [InsightEvents.expandToFullUI]: 'interface',
387
397
  [InsightEvents.openUserActions]: 'User Actions',