coveo.analytics 2.29.3 → 2.29.5

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.
@@ -3,7 +3,7 @@ import { AnyEventResponse, EventType, IRequestPayload } from '../events';
3
3
  export declare class AnalyticsFetchClient implements AnalyticsRequestClient {
4
4
  private opts;
5
5
  constructor(opts: IAnalyticsClientOptions);
6
- sendEvent(eventType: EventType, payload: IRequestPayload): Promise<AnyEventResponse>;
6
+ sendEvent(eventType: EventType, payload: IRequestPayload): Promise<AnyEventResponse | void>;
7
7
  deleteHttpCookieVisitorId(): Promise<void>;
8
8
  private shouldAppendVisitorId;
9
9
  private getVisitorIdParam;
@@ -196,6 +196,7 @@ export interface GeneratedAnswerBaseMeta {
196
196
  }
197
197
  export interface GeneratedAnswerStreamEndMeta extends GeneratedAnswerBaseMeta {
198
198
  answerGenerated: boolean;
199
+ answerTextIsEmpty?: boolean;
199
200
  }
200
201
  export interface GeneratedAnswerCitationMeta {
201
202
  generativeQuestionAnsweringId: string;
@@ -1 +1 @@
1
- export declare const libVersion = "2.29.3";
1
+ export declare const libVersion = "2.29.5";
package/dist/library.cjs CHANGED
@@ -731,7 +731,7 @@ function sha1(bytes) {
731
731
  const v5 = v35('v5', 0x50, sha1);
732
732
  var uuidv5 = v5;
733
733
 
734
- var libVersion = "2.29.3" ;
734
+ var libVersion = "2.29.5" ;
735
735
 
736
736
  var getFormattedLocation = function (location) {
737
737
  return "".concat(location.protocol, "//").concat(location.hostname).concat(location.pathname.indexOf('/') === 0 ? location.pathname : "/".concat(location.pathname)).concat(location.search);
@@ -82840,7 +82840,7 @@ var AnalyticsFetchClient = (function () {
82840
82840
  }
82841
82841
  AnalyticsFetchClient.prototype.sendEvent = function (eventType, payload) {
82842
82842
  return __awaiter(this, void 0, void 0, function () {
82843
- var _a, baseUrl, visitorIdProvider, preprocessRequest, visitorIdParam, _b, defaultOptions, _c, url, fetchData, _d, _e, response, visit;
82843
+ var _a, baseUrl, visitorIdProvider, preprocessRequest, visitorIdParam, _b, defaultOptions, _c, url, fetchData, _d, _e, response, error_1, visit;
82844
82844
  return __generator(this, function (_f) {
82845
82845
  switch (_f.label) {
82846
82846
  case 0:
@@ -82874,18 +82874,27 @@ var AnalyticsFetchClient = (function () {
82874
82874
  _f.label = 6;
82875
82875
  case 6:
82876
82876
  _c = __assign.apply(void 0, _d.concat([(_e)])), url = _c.url, fetchData = __rest(_c, ["url"]);
82877
- return [4, nodePonyfillExports.fetch(url, fetchData)];
82877
+ _f.label = 7;
82878
82878
  case 7:
82879
+ _f.trys.push([7, 9, , 10]);
82880
+ return [4, nodePonyfillExports.fetch(url, fetchData)];
82881
+ case 8:
82879
82882
  response = _f.sent();
82880
- if (!response.ok) return [3, 9];
82883
+ return [3, 10];
82884
+ case 9:
82885
+ error_1 = _f.sent();
82886
+ console.error('An error has occured when sending the event.', error_1);
82887
+ return [2];
82888
+ case 10:
82889
+ if (!response.ok) return [3, 12];
82881
82890
  return [4, response.json()];
82882
- case 8:
82891
+ case 11:
82883
82892
  visit = (_f.sent());
82884
82893
  if (visit.visitorId) {
82885
82894
  visitorIdProvider.setCurrentVisitorId(visit.visitorId);
82886
82895
  }
82887
82896
  return [2, visit];
82888
- case 9:
82897
+ case 12:
82889
82898
  try {
82890
82899
  response.json();
82891
82900
  }
@@ -596,7 +596,7 @@ function sha1(bytes) {
596
596
  const v5 = v35('v5', 0x50, sha1);
597
597
  var uuidv5 = v5;
598
598
 
599
- const libVersion = "2.29.3" ;
599
+ const libVersion = "2.29.5" ;
600
600
 
601
601
  const getFormattedLocation = (location) => `${location.protocol}//${location.hostname}${location.pathname.indexOf('/') === 0 ? location.pathname : `/${location.pathname}`}${location.search}`;
602
602
 
@@ -1112,7 +1112,14 @@ class AnalyticsFetchClient {
1112
1112
  body: JSON.stringify(payload),
1113
1113
  };
1114
1114
  const _a = Object.assign(Object.assign({}, defaultOptions), (preprocessRequest ? yield preprocessRequest(defaultOptions, 'analyticsFetch') : {})), { url } = _a, fetchData = __rest(_a, ["url"]);
1115
- const response = yield fetch$1(url, fetchData);
1115
+ let response;
1116
+ try {
1117
+ response = yield fetch$1(url, fetchData);
1118
+ }
1119
+ catch (error) {
1120
+ console.error('An error has occured when sending the event.', error);
1121
+ return;
1122
+ }
1116
1123
  if (response.ok) {
1117
1124
  const visit = (yield response.json());
1118
1125
  if (visit.visitorId) {
package/dist/library.js CHANGED
@@ -731,7 +731,7 @@ function sha1(bytes) {
731
731
  const v5 = v35('v5', 0x50, sha1);
732
732
  var uuidv5 = v5;
733
733
 
734
- var libVersion = "2.29.3" ;
734
+ var libVersion = "2.29.5" ;
735
735
 
736
736
  var getFormattedLocation = function (location) {
737
737
  return "".concat(location.protocol, "//").concat(location.hostname).concat(location.pathname.indexOf('/') === 0 ? location.pathname : "/".concat(location.pathname)).concat(location.search);
@@ -82840,7 +82840,7 @@ var AnalyticsFetchClient = (function () {
82840
82840
  }
82841
82841
  AnalyticsFetchClient.prototype.sendEvent = function (eventType, payload) {
82842
82842
  return __awaiter(this, void 0, void 0, function () {
82843
- var _a, baseUrl, visitorIdProvider, preprocessRequest, visitorIdParam, _b, defaultOptions, _c, url, fetchData, _d, _e, response, visit;
82843
+ var _a, baseUrl, visitorIdProvider, preprocessRequest, visitorIdParam, _b, defaultOptions, _c, url, fetchData, _d, _e, response, error_1, visit;
82844
82844
  return __generator(this, function (_f) {
82845
82845
  switch (_f.label) {
82846
82846
  case 0:
@@ -82874,18 +82874,27 @@ var AnalyticsFetchClient = (function () {
82874
82874
  _f.label = 6;
82875
82875
  case 6:
82876
82876
  _c = __assign.apply(void 0, _d.concat([(_e)])), url = _c.url, fetchData = __rest(_c, ["url"]);
82877
- return [4, nodePonyfillExports.fetch(url, fetchData)];
82877
+ _f.label = 7;
82878
82878
  case 7:
82879
+ _f.trys.push([7, 9, , 10]);
82880
+ return [4, nodePonyfillExports.fetch(url, fetchData)];
82881
+ case 8:
82879
82882
  response = _f.sent();
82880
- if (!response.ok) return [3, 9];
82883
+ return [3, 10];
82884
+ case 9:
82885
+ error_1 = _f.sent();
82886
+ console.error('An error has occured when sending the event.', error_1);
82887
+ return [2];
82888
+ case 10:
82889
+ if (!response.ok) return [3, 12];
82881
82890
  return [4, response.json()];
82882
- case 8:
82891
+ case 11:
82883
82892
  visit = (_f.sent());
82884
82893
  if (visit.visitorId) {
82885
82894
  visitorIdProvider.setCurrentVisitorId(visit.visitorId);
82886
82895
  }
82887
82896
  return [2, visit];
82888
- case 9:
82897
+ case 12:
82889
82898
  try {
82890
82899
  response.json();
82891
82900
  }
package/dist/library.mjs CHANGED
@@ -729,7 +729,7 @@ function sha1(bytes) {
729
729
  const v5 = v35('v5', 0x50, sha1);
730
730
  var uuidv5 = v5;
731
731
 
732
- var libVersion = "2.29.3" ;
732
+ var libVersion = "2.29.5" ;
733
733
 
734
734
  var getFormattedLocation = function (location) {
735
735
  return "".concat(location.protocol, "//").concat(location.hostname).concat(location.pathname.indexOf('/') === 0 ? location.pathname : "/".concat(location.pathname)).concat(location.search);
@@ -82838,7 +82838,7 @@ var AnalyticsFetchClient = (function () {
82838
82838
  }
82839
82839
  AnalyticsFetchClient.prototype.sendEvent = function (eventType, payload) {
82840
82840
  return __awaiter(this, void 0, void 0, function () {
82841
- var _a, baseUrl, visitorIdProvider, preprocessRequest, visitorIdParam, _b, defaultOptions, _c, url, fetchData, _d, _e, response, visit;
82841
+ var _a, baseUrl, visitorIdProvider, preprocessRequest, visitorIdParam, _b, defaultOptions, _c, url, fetchData, _d, _e, response, error_1, visit;
82842
82842
  return __generator(this, function (_f) {
82843
82843
  switch (_f.label) {
82844
82844
  case 0:
@@ -82872,18 +82872,27 @@ var AnalyticsFetchClient = (function () {
82872
82872
  _f.label = 6;
82873
82873
  case 6:
82874
82874
  _c = __assign.apply(void 0, _d.concat([(_e)])), url = _c.url, fetchData = __rest(_c, ["url"]);
82875
- return [4, nodePonyfillExports.fetch(url, fetchData)];
82875
+ _f.label = 7;
82876
82876
  case 7:
82877
+ _f.trys.push([7, 9, , 10]);
82878
+ return [4, nodePonyfillExports.fetch(url, fetchData)];
82879
+ case 8:
82877
82880
  response = _f.sent();
82878
- if (!response.ok) return [3, 9];
82881
+ return [3, 10];
82882
+ case 9:
82883
+ error_1 = _f.sent();
82884
+ console.error('An error has occured when sending the event.', error_1);
82885
+ return [2];
82886
+ case 10:
82887
+ if (!response.ok) return [3, 12];
82879
82888
  return [4, response.json()];
82880
- case 8:
82889
+ case 11:
82881
82890
  visit = (_f.sent());
82882
82891
  if (visit.visitorId) {
82883
82892
  visitorIdProvider.setCurrentVisitorId(visit.visitorId);
82884
82893
  }
82885
82894
  return [2, visit];
82886
- case 9:
82895
+ case 12:
82887
82896
  try {
82888
82897
  response.json();
82889
82898
  }
@@ -64,7 +64,14 @@ class AnalyticsFetchClient {
64
64
  body: JSON.stringify(payload),
65
65
  };
66
66
  const _a = Object.assign(Object.assign({}, defaultOptions), (preprocessRequest ? yield preprocessRequest(defaultOptions, 'analyticsFetch') : {})), { url } = _a, fetchData = __rest(_a, ["url"]);
67
- const response = yield fetch$1(url, fetchData);
67
+ let response;
68
+ try {
69
+ response = yield fetch$1(url, fetchData);
70
+ }
71
+ catch (error) {
72
+ console.error('An error has occured when sending the event.', error);
73
+ return;
74
+ }
68
75
  if (response.ok) {
69
76
  const visit = (yield response.json());
70
77
  if (visit.visitorId) {
@@ -658,7 +665,7 @@ const addPageViewToHistory = (pageViewValue) => __awaiter(void 0, void 0, void 0
658
665
  yield store.addElementAsync(historyElement);
659
666
  });
660
667
 
661
- const libVersion = "2.29.3" ;
668
+ const libVersion = "2.29.5" ;
662
669
 
663
670
  const getFormattedLocation = (location) => `${location.protocol}//${location.hostname}${location.pathname.indexOf('/') === 0 ? location.pathname : `/${location.pathname}`}${location.search}`;
664
671
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coveo.analytics",
3
- "version": "2.29.3",
3
+ "version": "2.29.5",
4
4
  "description": "📈 Coveo analytics client (node and browser compatible) ",
5
5
  "main": "dist/library.cjs",
6
6
  "module": "dist/browser.mjs",
@@ -5,7 +5,7 @@ import {fetch} from 'cross-fetch';
5
5
  export class AnalyticsFetchClient implements AnalyticsRequestClient {
6
6
  constructor(private opts: IAnalyticsClientOptions) {}
7
7
 
8
- public async sendEvent(eventType: EventType, payload: IRequestPayload): Promise<AnyEventResponse> {
8
+ public async sendEvent(eventType: EventType, payload: IRequestPayload): Promise<AnyEventResponse | void> {
9
9
  const {baseUrl, visitorIdProvider, preprocessRequest} = this.opts;
10
10
 
11
11
  const visitorIdParam = this.shouldAppendVisitorId(eventType) ? await this.getVisitorIdParam() : '';
@@ -22,7 +22,15 @@ export class AnalyticsFetchClient implements AnalyticsRequestClient {
22
22
  ...(preprocessRequest ? await preprocessRequest(defaultOptions, 'analyticsFetch') : {}),
23
23
  };
24
24
 
25
- const response = await fetch(url, fetchData);
25
+ let response: Response;
26
+
27
+ try {
28
+ response = await fetch(url, fetchData);
29
+ } catch (error) {
30
+ console.error('An error has occured when sending the event.', error);
31
+ return;
32
+ }
33
+
26
34
  if (response.ok) {
27
35
  const visit = (await response.json()) as AnyEventResponse;
28
36
 
@@ -618,6 +618,7 @@ describe('InsightClient', () => {
618
618
  const exampleGeneratedAnswerMetadata = {
619
619
  generativeQuestionAnsweringId: '123',
620
620
  answerGenerated: true,
621
+ answerTextIsEmpty: false,
621
622
  };
622
623
 
623
624
  await client.logGeneratedAnswerStreamEnd(exampleGeneratedAnswerMetadata);
@@ -1381,6 +1382,7 @@ describe('InsightClient', () => {
1381
1382
  const exampleGeneratedAnswerMetadata = {
1382
1383
  generativeQuestionAnsweringId: '123',
1383
1384
  answerGenerated: true,
1385
+ answerTextIsEmpty: false,
1384
1386
  };
1385
1387
  const expectedMetadata = {
1386
1388
  ...exampleGeneratedAnswerMetadata,
@@ -1494,13 +1494,13 @@ describe('SearchPageClient', () => {
1494
1494
  });
1495
1495
 
1496
1496
  it('should send proper payload for #logGeneratedAnswerStreamEnd', async () => {
1497
- const meta = {generativeQuestionAnsweringId: fakeStreamId, answerGenerated: true};
1497
+ const meta = {generativeQuestionAnsweringId: fakeStreamId, answerGenerated: true, answerTextIsEmpty: false};
1498
1498
  await client.logGeneratedAnswerStreamEnd(meta);
1499
1499
  expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerStreamEnd, meta);
1500
1500
  });
1501
1501
 
1502
1502
  it('should send proper payload for #makeGeneratedAnswerStreamEnd', async () => {
1503
- const meta = {generativeQuestionAnsweringId: fakeStreamId, answerGenerated: true};
1503
+ const meta = {generativeQuestionAnsweringId: fakeStreamId, answerGenerated: true, answerTextIsEmpty: false};
1504
1504
  const built = await client.makeGeneratedAnswerStreamEnd(meta);
1505
1505
  await built.log({searchUID: provider.getSearchUID()});
1506
1506
  expectMatchCustomEventPayload(SearchPageEvents.generatedAnswerStreamEnd, meta);
@@ -530,6 +530,7 @@ export interface GeneratedAnswerBaseMeta {
530
530
 
531
531
  export interface GeneratedAnswerStreamEndMeta extends GeneratedAnswerBaseMeta {
532
532
  answerGenerated: boolean;
533
+ answerTextIsEmpty?: boolean;
533
534
  }
534
535
 
535
536
  export interface GeneratedAnswerCitationMeta {