coveo.analytics 2.28.25 → 2.29.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.
@@ -10,7 +10,5 @@ export declare class AnalyticsBeaconClient implements AnalyticsRequestClient {
10
10
  private encodeForEventType;
11
11
  private getQueryParamsForEventType;
12
12
  private isEventTypeLegacy;
13
- private encodeForLegacyType;
14
- private encodeForFormUrlEncoded;
15
- private encodeValue;
13
+ private encodeEventToJson;
16
14
  }
@@ -1 +1 @@
1
- export declare const libVersion = "2.28.25";
1
+ export declare const libVersion = "2.29.2";
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.28.25" ;
734
+ var libVersion = "2.29.2" ;
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);
@@ -1268,8 +1268,8 @@ var AnalyticsBeaconClient = (function () {
1268
1268
  };
1269
1269
  AnalyticsBeaconClient.prototype.encodeForEventType = function (eventType, payload) {
1270
1270
  return this.isEventTypeLegacy(eventType)
1271
- ? this.encodeForLegacyType(eventType, payload)
1272
- : this.encodeForFormUrlEncoded(__assign({ access_token: this.opts.token }, payload));
1271
+ ? this.encodeEventToJson(eventType, payload)
1272
+ : this.encodeEventToJson(eventType, payload, this.opts.token);
1273
1273
  };
1274
1274
  AnalyticsBeaconClient.prototype.getQueryParamsForEventType = function (eventType) {
1275
1275
  return __awaiter(this, void 0, void 0, function () {
@@ -1295,20 +1295,12 @@ var AnalyticsBeaconClient = (function () {
1295
1295
  AnalyticsBeaconClient.prototype.isEventTypeLegacy = function (eventType) {
1296
1296
  return [exports.EventType.click, exports.EventType.custom, exports.EventType.search, exports.EventType.view].indexOf(eventType) !== -1;
1297
1297
  };
1298
- AnalyticsBeaconClient.prototype.encodeForLegacyType = function (eventType, payload) {
1299
- return "".concat(eventType, "Event=").concat(encodeURIComponent(JSON.stringify(payload)));
1300
- };
1301
- AnalyticsBeaconClient.prototype.encodeForFormUrlEncoded = function (payload) {
1302
- var _this = this;
1303
- return Object.keys(payload)
1304
- .filter(function (key) { return !!payload[key]; })
1305
- .map(function (key) { return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(_this.encodeValue(payload[key]))); })
1306
- .join('&');
1307
- };
1308
- AnalyticsBeaconClient.prototype.encodeValue = function (value) {
1309
- return typeof value === 'number' || typeof value === 'string' || typeof value === 'boolean'
1310
- ? value
1311
- : JSON.stringify(value);
1298
+ AnalyticsBeaconClient.prototype.encodeEventToJson = function (eventType, payload, access_token) {
1299
+ var encoded = "".concat(eventType, "Event=").concat(encodeURIComponent(JSON.stringify(payload)));
1300
+ if (access_token) {
1301
+ encoded = "access_token=".concat(encodeURIComponent(access_token), "&").concat(encoded);
1302
+ }
1303
+ return encoded;
1312
1304
  };
1313
1305
  return AnalyticsBeaconClient;
1314
1306
  }());
@@ -83058,7 +83050,6 @@ var CoveoAnalyticsClient = (function () {
83058
83050
  };
83059
83051
  this.runtime = this.options.runtimeEnvironment || this.initRuntime(clientsOptions);
83060
83052
  if (doNotTrack()) {
83061
- this.clear();
83062
83053
  this.runtime.storage = new NullStorage();
83063
83054
  }
83064
83055
  this.addEventTypeMapping(exports.EventType.view, { newEventType: exports.EventType.view, addClientIdParameter: true });
@@ -84451,9 +84442,6 @@ var CoveoSearchPageClient = (function () {
84451
84442
  this.coveoAnalyticsClient = shouldDisableAnalytics ? new NoopAnalytics() : new CoveoAnalyticsClient(opts);
84452
84443
  }
84453
84444
  CoveoSearchPageClient.prototype.disable = function () {
84454
- if (this.coveoAnalyticsClient instanceof CoveoAnalyticsClient) {
84455
- this.coveoAnalyticsClient.clear();
84456
- }
84457
84445
  this.coveoAnalyticsClient = new NoopAnalytics();
84458
84446
  };
84459
84447
  CoveoSearchPageClient.prototype.enable = function () {
@@ -85823,9 +85811,6 @@ var CaseAssistClient = (function () {
85823
85811
  this.svc = new SVCPlugin({ client: this.coveoAnalyticsClient });
85824
85812
  }
85825
85813
  CaseAssistClient.prototype.disable = function () {
85826
- if (this.coveoAnalyticsClient instanceof CoveoAnalyticsClient) {
85827
- this.coveoAnalyticsClient.clear();
85828
- }
85829
85814
  this.coveoAnalyticsClient = new NoopAnalytics();
85830
85815
  this.svc = new SVCPlugin({ client: this.coveoAnalyticsClient });
85831
85816
  };
@@ -85931,9 +85916,6 @@ var CoveoInsightClient = (function () {
85931
85916
  this.coveoAnalyticsClient = shouldDisableAnalytics ? new NoopAnalytics() : new CoveoAnalyticsClient(opts);
85932
85917
  }
85933
85918
  CoveoInsightClient.prototype.disable = function () {
85934
- if (this.coveoAnalyticsClient instanceof CoveoAnalyticsClient) {
85935
- this.coveoAnalyticsClient.clear();
85936
- }
85937
85919
  this.coveoAnalyticsClient = new NoopAnalytics();
85938
85920
  };
85939
85921
  CoveoInsightClient.prototype.enable = function () {
@@ -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.28.25" ;
599
+ const libVersion = "2.29.2" ;
600
600
 
601
601
  const getFormattedLocation = (location) => `${location.protocol}//${location.hostname}${location.pathname.indexOf('/') === 0 ? location.pathname : `/${location.pathname}`}${location.search}`;
602
602
 
@@ -1052,8 +1052,8 @@ class AnalyticsBeaconClient {
1052
1052
  }
1053
1053
  encodeForEventType(eventType, payload) {
1054
1054
  return this.isEventTypeLegacy(eventType)
1055
- ? this.encodeForLegacyType(eventType, payload)
1056
- : this.encodeForFormUrlEncoded(Object.assign({ access_token: this.opts.token }, payload));
1055
+ ? this.encodeEventToJson(eventType, payload)
1056
+ : this.encodeEventToJson(eventType, payload, this.opts.token);
1057
1057
  }
1058
1058
  getQueryParamsForEventType(eventType) {
1059
1059
  return __awaiter(this, void 0, void 0, function* () {
@@ -1071,19 +1071,12 @@ class AnalyticsBeaconClient {
1071
1071
  isEventTypeLegacy(eventType) {
1072
1072
  return [EventType.click, EventType.custom, EventType.search, EventType.view].indexOf(eventType) !== -1;
1073
1073
  }
1074
- encodeForLegacyType(eventType, payload) {
1075
- return `${eventType}Event=${encodeURIComponent(JSON.stringify(payload))}`;
1076
- }
1077
- encodeForFormUrlEncoded(payload) {
1078
- return Object.keys(payload)
1079
- .filter((key) => !!payload[key])
1080
- .map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(this.encodeValue(payload[key]))}`)
1081
- .join('&');
1082
- }
1083
- encodeValue(value) {
1084
- return typeof value === 'number' || typeof value === 'string' || typeof value === 'boolean'
1085
- ? value
1086
- : JSON.stringify(value);
1074
+ encodeEventToJson(eventType, payload, access_token) {
1075
+ let encoded = `${eventType}Event=${encodeURIComponent(JSON.stringify(payload))}`;
1076
+ if (access_token) {
1077
+ encoded = `access_token=${encodeURIComponent(access_token)}&${encoded}`;
1078
+ }
1079
+ return encoded;
1087
1080
  }
1088
1081
  }
1089
1082
 
@@ -1276,7 +1269,6 @@ class CoveoAnalyticsClient {
1276
1269
  };
1277
1270
  this.runtime = this.options.runtimeEnvironment || this.initRuntime(clientsOptions);
1278
1271
  if (doNotTrack()) {
1279
- this.clear();
1280
1272
  this.runtime.storage = new NullStorage();
1281
1273
  }
1282
1274
  this.addEventTypeMapping(EventType.view, { newEventType: EventType.view, addClientIdParameter: true });
@@ -1933,9 +1925,6 @@ class CoveoSearchPageClient {
1933
1925
  this.coveoAnalyticsClient = shouldDisableAnalytics ? new NoopAnalytics() : new CoveoAnalyticsClient(opts);
1934
1926
  }
1935
1927
  disable() {
1936
- if (this.coveoAnalyticsClient instanceof CoveoAnalyticsClient) {
1937
- this.coveoAnalyticsClient.clear();
1938
- }
1939
1928
  this.coveoAnalyticsClient = new NoopAnalytics();
1940
1929
  }
1941
1930
  enable() {
@@ -2838,9 +2827,6 @@ class CaseAssistClient {
2838
2827
  this.svc = new SVCPlugin({ client: this.coveoAnalyticsClient });
2839
2828
  }
2840
2829
  disable() {
2841
- if (this.coveoAnalyticsClient instanceof CoveoAnalyticsClient) {
2842
- this.coveoAnalyticsClient.clear();
2843
- }
2844
2830
  this.coveoAnalyticsClient = new NoopAnalytics();
2845
2831
  this.svc = new SVCPlugin({ client: this.coveoAnalyticsClient });
2846
2832
  }
@@ -2944,9 +2930,6 @@ class CoveoInsightClient {
2944
2930
  this.coveoAnalyticsClient = shouldDisableAnalytics ? new NoopAnalytics() : new CoveoAnalyticsClient(opts);
2945
2931
  }
2946
2932
  disable() {
2947
- if (this.coveoAnalyticsClient instanceof CoveoAnalyticsClient) {
2948
- this.coveoAnalyticsClient.clear();
2949
- }
2950
2933
  this.coveoAnalyticsClient = new NoopAnalytics();
2951
2934
  }
2952
2935
  enable() {
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.28.25" ;
734
+ var libVersion = "2.29.2" ;
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);
@@ -1268,8 +1268,8 @@ var AnalyticsBeaconClient = (function () {
1268
1268
  };
1269
1269
  AnalyticsBeaconClient.prototype.encodeForEventType = function (eventType, payload) {
1270
1270
  return this.isEventTypeLegacy(eventType)
1271
- ? this.encodeForLegacyType(eventType, payload)
1272
- : this.encodeForFormUrlEncoded(__assign({ access_token: this.opts.token }, payload));
1271
+ ? this.encodeEventToJson(eventType, payload)
1272
+ : this.encodeEventToJson(eventType, payload, this.opts.token);
1273
1273
  };
1274
1274
  AnalyticsBeaconClient.prototype.getQueryParamsForEventType = function (eventType) {
1275
1275
  return __awaiter(this, void 0, void 0, function () {
@@ -1295,20 +1295,12 @@ var AnalyticsBeaconClient = (function () {
1295
1295
  AnalyticsBeaconClient.prototype.isEventTypeLegacy = function (eventType) {
1296
1296
  return [exports.EventType.click, exports.EventType.custom, exports.EventType.search, exports.EventType.view].indexOf(eventType) !== -1;
1297
1297
  };
1298
- AnalyticsBeaconClient.prototype.encodeForLegacyType = function (eventType, payload) {
1299
- return "".concat(eventType, "Event=").concat(encodeURIComponent(JSON.stringify(payload)));
1300
- };
1301
- AnalyticsBeaconClient.prototype.encodeForFormUrlEncoded = function (payload) {
1302
- var _this = this;
1303
- return Object.keys(payload)
1304
- .filter(function (key) { return !!payload[key]; })
1305
- .map(function (key) { return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(_this.encodeValue(payload[key]))); })
1306
- .join('&');
1307
- };
1308
- AnalyticsBeaconClient.prototype.encodeValue = function (value) {
1309
- return typeof value === 'number' || typeof value === 'string' || typeof value === 'boolean'
1310
- ? value
1311
- : JSON.stringify(value);
1298
+ AnalyticsBeaconClient.prototype.encodeEventToJson = function (eventType, payload, access_token) {
1299
+ var encoded = "".concat(eventType, "Event=").concat(encodeURIComponent(JSON.stringify(payload)));
1300
+ if (access_token) {
1301
+ encoded = "access_token=".concat(encodeURIComponent(access_token), "&").concat(encoded);
1302
+ }
1303
+ return encoded;
1312
1304
  };
1313
1305
  return AnalyticsBeaconClient;
1314
1306
  }());
@@ -83058,7 +83050,6 @@ var CoveoAnalyticsClient = (function () {
83058
83050
  };
83059
83051
  this.runtime = this.options.runtimeEnvironment || this.initRuntime(clientsOptions);
83060
83052
  if (doNotTrack()) {
83061
- this.clear();
83062
83053
  this.runtime.storage = new NullStorage();
83063
83054
  }
83064
83055
  this.addEventTypeMapping(exports.EventType.view, { newEventType: exports.EventType.view, addClientIdParameter: true });
@@ -84451,9 +84442,6 @@ var CoveoSearchPageClient = (function () {
84451
84442
  this.coveoAnalyticsClient = shouldDisableAnalytics ? new NoopAnalytics() : new CoveoAnalyticsClient(opts);
84452
84443
  }
84453
84444
  CoveoSearchPageClient.prototype.disable = function () {
84454
- if (this.coveoAnalyticsClient instanceof CoveoAnalyticsClient) {
84455
- this.coveoAnalyticsClient.clear();
84456
- }
84457
84445
  this.coveoAnalyticsClient = new NoopAnalytics();
84458
84446
  };
84459
84447
  CoveoSearchPageClient.prototype.enable = function () {
@@ -85823,9 +85811,6 @@ var CaseAssistClient = (function () {
85823
85811
  this.svc = new SVCPlugin({ client: this.coveoAnalyticsClient });
85824
85812
  }
85825
85813
  CaseAssistClient.prototype.disable = function () {
85826
- if (this.coveoAnalyticsClient instanceof CoveoAnalyticsClient) {
85827
- this.coveoAnalyticsClient.clear();
85828
- }
85829
85814
  this.coveoAnalyticsClient = new NoopAnalytics();
85830
85815
  this.svc = new SVCPlugin({ client: this.coveoAnalyticsClient });
85831
85816
  };
@@ -85931,9 +85916,6 @@ var CoveoInsightClient = (function () {
85931
85916
  this.coveoAnalyticsClient = shouldDisableAnalytics ? new NoopAnalytics() : new CoveoAnalyticsClient(opts);
85932
85917
  }
85933
85918
  CoveoInsightClient.prototype.disable = function () {
85934
- if (this.coveoAnalyticsClient instanceof CoveoAnalyticsClient) {
85935
- this.coveoAnalyticsClient.clear();
85936
- }
85937
85919
  this.coveoAnalyticsClient = new NoopAnalytics();
85938
85920
  };
85939
85921
  CoveoInsightClient.prototype.enable = function () {
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.28.25" ;
732
+ var libVersion = "2.29.2" ;
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);
@@ -1266,8 +1266,8 @@ var AnalyticsBeaconClient = (function () {
1266
1266
  };
1267
1267
  AnalyticsBeaconClient.prototype.encodeForEventType = function (eventType, payload) {
1268
1268
  return this.isEventTypeLegacy(eventType)
1269
- ? this.encodeForLegacyType(eventType, payload)
1270
- : this.encodeForFormUrlEncoded(__assign({ access_token: this.opts.token }, payload));
1269
+ ? this.encodeEventToJson(eventType, payload)
1270
+ : this.encodeEventToJson(eventType, payload, this.opts.token);
1271
1271
  };
1272
1272
  AnalyticsBeaconClient.prototype.getQueryParamsForEventType = function (eventType) {
1273
1273
  return __awaiter(this, void 0, void 0, function () {
@@ -1293,20 +1293,12 @@ var AnalyticsBeaconClient = (function () {
1293
1293
  AnalyticsBeaconClient.prototype.isEventTypeLegacy = function (eventType) {
1294
1294
  return [EventType.click, EventType.custom, EventType.search, EventType.view].indexOf(eventType) !== -1;
1295
1295
  };
1296
- AnalyticsBeaconClient.prototype.encodeForLegacyType = function (eventType, payload) {
1297
- return "".concat(eventType, "Event=").concat(encodeURIComponent(JSON.stringify(payload)));
1298
- };
1299
- AnalyticsBeaconClient.prototype.encodeForFormUrlEncoded = function (payload) {
1300
- var _this = this;
1301
- return Object.keys(payload)
1302
- .filter(function (key) { return !!payload[key]; })
1303
- .map(function (key) { return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(_this.encodeValue(payload[key]))); })
1304
- .join('&');
1305
- };
1306
- AnalyticsBeaconClient.prototype.encodeValue = function (value) {
1307
- return typeof value === 'number' || typeof value === 'string' || typeof value === 'boolean'
1308
- ? value
1309
- : JSON.stringify(value);
1296
+ AnalyticsBeaconClient.prototype.encodeEventToJson = function (eventType, payload, access_token) {
1297
+ var encoded = "".concat(eventType, "Event=").concat(encodeURIComponent(JSON.stringify(payload)));
1298
+ if (access_token) {
1299
+ encoded = "access_token=".concat(encodeURIComponent(access_token), "&").concat(encoded);
1300
+ }
1301
+ return encoded;
1310
1302
  };
1311
1303
  return AnalyticsBeaconClient;
1312
1304
  }());
@@ -83056,7 +83048,6 @@ var CoveoAnalyticsClient = (function () {
83056
83048
  };
83057
83049
  this.runtime = this.options.runtimeEnvironment || this.initRuntime(clientsOptions);
83058
83050
  if (doNotTrack()) {
83059
- this.clear();
83060
83051
  this.runtime.storage = new NullStorage();
83061
83052
  }
83062
83053
  this.addEventTypeMapping(EventType.view, { newEventType: EventType.view, addClientIdParameter: true });
@@ -84449,9 +84440,6 @@ var CoveoSearchPageClient = (function () {
84449
84440
  this.coveoAnalyticsClient = shouldDisableAnalytics ? new NoopAnalytics() : new CoveoAnalyticsClient(opts);
84450
84441
  }
84451
84442
  CoveoSearchPageClient.prototype.disable = function () {
84452
- if (this.coveoAnalyticsClient instanceof CoveoAnalyticsClient) {
84453
- this.coveoAnalyticsClient.clear();
84454
- }
84455
84443
  this.coveoAnalyticsClient = new NoopAnalytics();
84456
84444
  };
84457
84445
  CoveoSearchPageClient.prototype.enable = function () {
@@ -85821,9 +85809,6 @@ var CaseAssistClient = (function () {
85821
85809
  this.svc = new SVCPlugin({ client: this.coveoAnalyticsClient });
85822
85810
  }
85823
85811
  CaseAssistClient.prototype.disable = function () {
85824
- if (this.coveoAnalyticsClient instanceof CoveoAnalyticsClient) {
85825
- this.coveoAnalyticsClient.clear();
85826
- }
85827
85812
  this.coveoAnalyticsClient = new NoopAnalytics();
85828
85813
  this.svc = new SVCPlugin({ client: this.coveoAnalyticsClient });
85829
85814
  };
@@ -85929,9 +85914,6 @@ var CoveoInsightClient = (function () {
85929
85914
  this.coveoAnalyticsClient = shouldDisableAnalytics ? new NoopAnalytics() : new CoveoAnalyticsClient(opts);
85930
85915
  }
85931
85916
  CoveoInsightClient.prototype.disable = function () {
85932
- if (this.coveoAnalyticsClient instanceof CoveoAnalyticsClient) {
85933
- this.coveoAnalyticsClient.clear();
85934
- }
85935
85917
  this.coveoAnalyticsClient = new NoopAnalytics();
85936
85918
  };
85937
85919
  CoveoInsightClient.prototype.enable = function () {
@@ -658,7 +658,7 @@ const addPageViewToHistory = (pageViewValue) => __awaiter(void 0, void 0, void 0
658
658
  yield store.addElementAsync(historyElement);
659
659
  });
660
660
 
661
- const libVersion = "2.28.25" ;
661
+ const libVersion = "2.29.2" ;
662
662
 
663
663
  const getFormattedLocation = (location) => `${location.protocol}//${location.hostname}${location.pathname.indexOf('/') === 0 ? location.pathname : `/${location.pathname}`}${location.search}`;
664
664
 
@@ -1114,8 +1114,8 @@ class AnalyticsBeaconClient {
1114
1114
  }
1115
1115
  encodeForEventType(eventType, payload) {
1116
1116
  return this.isEventTypeLegacy(eventType)
1117
- ? this.encodeForLegacyType(eventType, payload)
1118
- : this.encodeForFormUrlEncoded(Object.assign({ access_token: this.opts.token }, payload));
1117
+ ? this.encodeEventToJson(eventType, payload)
1118
+ : this.encodeEventToJson(eventType, payload, this.opts.token);
1119
1119
  }
1120
1120
  getQueryParamsForEventType(eventType) {
1121
1121
  return __awaiter(this, void 0, void 0, function* () {
@@ -1133,19 +1133,12 @@ class AnalyticsBeaconClient {
1133
1133
  isEventTypeLegacy(eventType) {
1134
1134
  return [EventType.click, EventType.custom, EventType.search, EventType.view].indexOf(eventType) !== -1;
1135
1135
  }
1136
- encodeForLegacyType(eventType, payload) {
1137
- return `${eventType}Event=${encodeURIComponent(JSON.stringify(payload))}`;
1138
- }
1139
- encodeForFormUrlEncoded(payload) {
1140
- return Object.keys(payload)
1141
- .filter((key) => !!payload[key])
1142
- .map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(this.encodeValue(payload[key]))}`)
1143
- .join('&');
1144
- }
1145
- encodeValue(value) {
1146
- return typeof value === 'number' || typeof value === 'string' || typeof value === 'boolean'
1147
- ? value
1148
- : JSON.stringify(value);
1136
+ encodeEventToJson(eventType, payload, access_token) {
1137
+ let encoded = `${eventType}Event=${encodeURIComponent(JSON.stringify(payload))}`;
1138
+ if (access_token) {
1139
+ encoded = `access_token=${encodeURIComponent(access_token)}&${encoded}`;
1140
+ }
1141
+ return encoded;
1149
1142
  }
1150
1143
  }
1151
1144
 
@@ -1277,7 +1270,6 @@ class CoveoAnalyticsClient {
1277
1270
  };
1278
1271
  this.runtime = this.options.runtimeEnvironment || this.initRuntime(clientsOptions);
1279
1272
  if (doNotTrack()) {
1280
- this.clear();
1281
1273
  this.runtime.storage = new NullStorage();
1282
1274
  }
1283
1275
  this.addEventTypeMapping(EventType.view, { newEventType: EventType.view, addClientIdParameter: true });
@@ -1954,9 +1946,6 @@ class CoveoSearchPageClient {
1954
1946
  this.coveoAnalyticsClient = shouldDisableAnalytics ? new NoopAnalytics() : new CoveoAnalyticsClient(opts);
1955
1947
  }
1956
1948
  disable() {
1957
- if (this.coveoAnalyticsClient instanceof CoveoAnalyticsClient) {
1958
- this.coveoAnalyticsClient.clear();
1959
- }
1960
1949
  this.coveoAnalyticsClient = new NoopAnalytics();
1961
1950
  }
1962
1951
  enable() {
@@ -2859,9 +2848,6 @@ class CaseAssistClient {
2859
2848
  this.svc = new SVCPlugin({ client: this.coveoAnalyticsClient });
2860
2849
  }
2861
2850
  disable() {
2862
- if (this.coveoAnalyticsClient instanceof CoveoAnalyticsClient) {
2863
- this.coveoAnalyticsClient.clear();
2864
- }
2865
2851
  this.coveoAnalyticsClient = new NoopAnalytics();
2866
2852
  this.svc = new SVCPlugin({ client: this.coveoAnalyticsClient });
2867
2853
  }
@@ -2965,9 +2951,6 @@ class CoveoInsightClient {
2965
2951
  this.coveoAnalyticsClient = shouldDisableAnalytics ? new NoopAnalytics() : new CoveoAnalyticsClient(opts);
2966
2952
  }
2967
2953
  disable() {
2968
- if (this.coveoAnalyticsClient instanceof CoveoAnalyticsClient) {
2969
- this.coveoAnalyticsClient.clear();
2970
- }
2971
2954
  this.coveoAnalyticsClient = new NoopAnalytics();
2972
2955
  }
2973
2956
  enable() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coveo.analytics",
3
- "version": "2.28.25",
3
+ "version": "2.29.2",
4
4
  "description": "📈 Coveo analytics client (node and browser compatible) ",
5
5
  "main": "dist/library.cjs",
6
6
  "module": "dist/browser.mjs",
@@ -11,8 +11,8 @@
11
11
  "lint:fix": "prettier --write .",
12
12
  "build": "rollup -c",
13
13
  "start": "rollup -c -w --environment SERVE",
14
- "test": "jest --clearCache && jest --coverage",
15
- "test:watch": "jest --clearCache && jest --watch",
14
+ "test": "jest --clearCache && jest --coverage --silent",
15
+ "test:watch": "jest --clearCache && jest --watch --silent",
16
16
  "prepare-deploy": "mkdir -p deploy && cp dist/coveoua*.js dist/coveoua*.js.map deploy",
17
17
  "clean": "rimraf -rf dist dist_test coverage"
18
18
  },
@@ -10,6 +10,7 @@ import {mockFetch, lastCallBody} from '../../tests/fetchMock';
10
10
  import {TicketProperties} from '../plugins/svc';
11
11
  const {fetchMock, fetchMockBeforeEach} = mockFetch();
12
12
  import doNotTrack from '../donottrack';
13
+ import {Cookie} from '../cookieutils';
13
14
  jest.mock('../donottrack', () => {
14
15
  return {
15
16
  default: jest.fn(),
@@ -178,6 +179,15 @@ describe('CaseAssistClient', () => {
178
179
  expect(fetchMock.called()).toBe(false);
179
180
  });
180
181
 
182
+ it('disabling does not delete the visitorId', () => {
183
+ const visitorId = 'uuid';
184
+ Cookie.set('coveo_visitorId', visitorId);
185
+
186
+ expect(Cookie.get('coveo_visitorId')).toBe(visitorId);
187
+ client.disable();
188
+ expect(Cookie.get('coveo_visitorId')).toBe(visitorId);
189
+ });
190
+
181
191
  it('should send events after #enable function is called', async () => {
182
192
  client = new CaseAssistClient({
183
193
  enableAnalytics: false,
@@ -37,9 +37,6 @@ export class CaseAssistClient {
37
37
  }
38
38
 
39
39
  public disable() {
40
- if (this.coveoAnalyticsClient instanceof CoveoAnalyticsClient) {
41
- this.coveoAnalyticsClient.clear();
42
- }
43
40
  this.coveoAnalyticsClient = new NoopAnalytics();
44
41
  this.svc = new SVCPlugin({client: this.coveoAnalyticsClient});
45
42
  }
@@ -667,14 +667,14 @@ describe('doNotTrack', () => {
667
667
  expect(client.runtime.storage).toBeInstanceOf(NullStorage);
668
668
  });
669
669
 
670
- it('should clear existing cookies', async () => {
670
+ it('should not clear existing cookies', async () => {
671
671
  jest.spyOn(doNotTrack, 'doNotTrack').mockImplementation(() => true);
672
672
  Cookie.set('coveo_visitorId', aVisitorId);
673
673
  expect(Cookie.get('coveo_visitorId')).toBe(aVisitorId);
674
674
 
675
675
  new CoveoAnalyticsClient({});
676
676
 
677
- expect(Cookie.get('coveo_visitorId')).not.toBe(aVisitorId);
677
+ expect(Cookie.get('coveo_visitorId')).toBe(aVisitorId);
678
678
  });
679
679
  });
680
680
 
@@ -184,7 +184,6 @@ export class CoveoAnalyticsClient implements AnalyticsClient, VisitorIdProvider
184
184
 
185
185
  this.runtime = this.options.runtimeEnvironment || this.initRuntime(clientsOptions);
186
186
  if (doNotTrack()) {
187
- this.clear();
188
187
  this.runtime.storage = new NullStorage();
189
188
  }
190
189
 
@@ -41,7 +41,7 @@ describe('AnalyticsBeaconClient', () => {
41
41
  `${baseUrl}/analytics/custom?access_token=👛&visitorId=${currentVisitorId}&discardVisitInfo=true`,
42
42
  expect.anything()
43
43
  );
44
- expect(await getSendBeaconFirstCallBlobArgument()).toBe(`customEvent=${encodeURIComponent(`{"wow":"ok"}`)}`);
44
+ expect(await getSendBeaconFirstCallBlobArgument()).toBe(`customEvent=${encodeURIComponent('{"wow":"ok"}')}`);
45
45
  });
46
46
 
47
47
  it('can send a collect event with the proper payload', async () => {
@@ -66,7 +66,9 @@ describe('AnalyticsBeaconClient', () => {
66
66
  expect.anything()
67
67
  );
68
68
  expect(await getSendBeaconFirstCallBlobArgument()).toBe(
69
- 'access_token=%F0%9F%91%9B&pr1a=value&to%20encode=to%20encode'
69
+ `access_token=${encodeURIComponent('👛')}&collectEvent=${encodeURIComponent(
70
+ '{"pr1a":"value","to encode":"to encode"}'
71
+ )}`
70
72
  );
71
73
  });
72
74
 
@@ -95,7 +97,7 @@ describe('AnalyticsBeaconClient', () => {
95
97
  expect.anything()
96
98
  );
97
99
  expect(await getSendBeaconFirstCallBlobArgument()).toBe(
98
- `access_token=%F0%9F%91%9B&value=${encodeURIComponent(JSON.stringify({subvalue: 'ok'}))}`
100
+ `access_token=${encodeURIComponent('👛')}&collectEvent=${encodeURIComponent('{"value":{"subvalue":"ok"}}')}`
99
101
  );
100
102
  });
101
103
 
@@ -131,7 +133,7 @@ describe('AnalyticsBeaconClient', () => {
131
133
 
132
134
  expect(clientOrigin!).toBe('analyticsBeacon');
133
135
  expect(sendBeaconMock).toHaveBeenCalledWith(processedRequest.url, expect.anything());
134
- expect(await getSendBeaconFirstCallBlobArgument()).toContain('test=custom');
136
+ expect(await getSendBeaconFirstCallBlobArgument()).toContain('%22test%22%3A%22custom%22');
135
137
  });
136
138
 
137
139
  it('to modify the request body as a JSON string for a collect event', async () => {
@@ -144,7 +146,9 @@ describe('AnalyticsBeaconClient', () => {
144
146
  });
145
147
 
146
148
  await client.sendEvent(EventType.collect, {foo: 'bar'});
147
- expect(await getSendBeaconFirstCallBlobArgument()).toContain(`foo=baz`);
149
+ expect(await getSendBeaconFirstCallBlobArgument()).toBe(
150
+ 'access_token=%F0%9F%91%9B&collectEvent=%7B%22foo%22%3A%22baz%22%7D'
151
+ );
148
152
  });
149
153
 
150
154
  it('to modify the request body as a JSON string for a click event', async () => {
@@ -158,7 +162,7 @@ describe('AnalyticsBeaconClient', () => {
158
162
 
159
163
  await client.sendEvent(EventType.click, {actionCause: 'foo'});
160
164
  expect(await getSendBeaconFirstCallBlobArgument()).toContain(
161
- `clickEvent=${encodeURIComponent(`{"actionCause":"bar"}`)}`
165
+ `clickEvent=${encodeURIComponent('{"actionCause":"bar"}')}`
162
166
  );
163
167
  });
164
168
 
@@ -172,7 +176,7 @@ describe('AnalyticsBeaconClient', () => {
172
176
 
173
177
  await client.sendEvent(EventType.click, {actionCause: 'foo'});
174
178
  expect(await getSendBeaconFirstCallBlobArgument()).toContain(
175
- `clickEvent=${encodeURIComponent(`{"actionCause":"foo","aNewProperty":"bar"}`)}`
179
+ `clickEvent=${encodeURIComponent('{"actionCause":"foo","aNewProperty":"bar"}')}`
176
180
  );
177
181
  });
178
182
 
@@ -68,11 +68,8 @@ export class AnalyticsBeaconClient implements AnalyticsRequestClient {
68
68
 
69
69
  private encodeForEventType(eventType: EventType, payload: IRequestPayload): string {
70
70
  return this.isEventTypeLegacy(eventType)
71
- ? this.encodeForLegacyType(eventType, payload)
72
- : this.encodeForFormUrlEncoded({
73
- access_token: this.opts.token,
74
- ...payload,
75
- });
71
+ ? this.encodeEventToJson(eventType, payload)
72
+ : this.encodeEventToJson(eventType, payload, this.opts.token);
76
73
  }
77
74
 
78
75
  private async getQueryParamsForEventType(eventType: EventType): Promise<string> {
@@ -91,20 +88,11 @@ export class AnalyticsBeaconClient implements AnalyticsRequestClient {
91
88
  return [EventType.click, EventType.custom, EventType.search, EventType.view].indexOf(eventType) !== -1;
92
89
  }
93
90
 
94
- private encodeForLegacyType(eventType: EventType, payload: IRequestPayload): string {
95
- return `${eventType}Event=${encodeURIComponent(JSON.stringify(payload))}`;
96
- }
97
-
98
- private encodeForFormUrlEncoded(payload: IRequestPayload): string {
99
- return Object.keys(payload)
100
- .filter((key) => !!payload[key])
101
- .map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(this.encodeValue(payload[key]))}`)
102
- .join('&');
103
- }
104
-
105
- private encodeValue(value: any) {
106
- return typeof value === 'number' || typeof value === 'string' || typeof value === 'boolean'
107
- ? value
108
- : JSON.stringify(value);
91
+ private encodeEventToJson(eventType: EventType, payload: IRequestPayload, access_token?: string): string {
92
+ let encoded = `${eventType}Event=${encodeURIComponent(JSON.stringify(payload))}`;
93
+ if (access_token) {
94
+ encoded = `access_token=${encodeURIComponent(access_token)}&${encoded}`;
95
+ }
96
+ return encoded;
109
97
  }
110
98
  }
@@ -12,6 +12,7 @@ import {
12
12
  import {CoveoInsightClient, InsightClientProvider} from './insightClient';
13
13
  import doNotTrack from '../donottrack';
14
14
  import {InsightEvents, InsightStaticFilterToggleValueMetadata} from './insightEvents';
15
+ import {Cookie} from '../cookieutils';
15
16
 
16
17
  const baseCaseMetadata = {
17
18
  caseId: '1234',
@@ -1420,6 +1421,16 @@ describe('InsightClient', () => {
1420
1421
  expect(c.coveoAnalyticsClient instanceof NoopAnalytics).toBe(true);
1421
1422
  });
1422
1423
 
1424
+ it('disabling analytics does not delete the visitorId', () => {
1425
+ const visitorId = 'uuid';
1426
+ Cookie.set('coveo_visitorId', visitorId);
1427
+ const c = new CoveoInsightClient({enableAnalytics: true}, provider);
1428
+
1429
+ expect(Cookie.get('coveo_visitorId')).toBe(visitorId);
1430
+ c.disable();
1431
+ expect(Cookie.get('coveo_visitorId')).toBe(visitorId);
1432
+ });
1433
+
1423
1434
  it('should disable analytics when doNotTrack is enabled', async () => {
1424
1435
  (doNotTrack as jest.Mock).mockImplementationOnce(() => true);
1425
1436