coveo.analytics 2.23.8 → 2.23.10

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.
@@ -99,6 +99,7 @@ export declare class CoveoAnalyticsClient implements AnalyticsClient, VisitorIdP
99
99
  private removeEmptyPayloadValues;
100
100
  private removeUnknownParameters;
101
101
  private processCustomParameters;
102
+ private mapCustomParametersToCustomData;
102
103
  private lowercaseKeys;
103
104
  private validateParams;
104
105
  private ensureAnonymousUserWhenUsingApiKey;
@@ -1 +1,2 @@
1
1
  export declare const keysOf: <T>(o: T) => Extract<keyof T, string>[];
2
+ export declare function isObject(o: any): boolean;
@@ -1,7 +1,7 @@
1
1
  import { AnalyticsClient, ClientOptions } from '../client/analytics';
2
2
  import { SearchEventRequest } from '../events';
3
3
  import { DocumentIdentifier, FacetStateMetadata, PartialDocumentInformation, SearchPageEvents } from '../searchPage/searchPageEvents';
4
- import { ExpandToFullUIMetadata, InsightEvents, InsightFacetMetadata, InsightInterfaceChangeMetadata, InsightStaticFilterToggleValueMetadata, InsightFacetRangeMetadata, InsightCategoryFacetMetadata, CaseMetadata, InsightFacetSortMeta, InsightFacetBaseMeta, InsightQueryErrorMeta, InsightPagerMetadata, InsightResultsSortMetadata } from './insightEvents';
4
+ import { ExpandToFullUIMetadata, InsightEvents, InsightFacetMetadata, InsightInterfaceChangeMetadata, InsightStaticFilterToggleValueMetadata, InsightFacetRangeMetadata, InsightCategoryFacetMetadata, CaseMetadata, InsightFacetSortMeta, InsightFacetBaseMeta, InsightQueryErrorMeta, InsightPagerMetadata, InsightResultsSortMetadata, UserActionsDocumentMetadata, UserActionsPageViewMetadata } from './insightEvents';
5
5
  export interface InsightClientProvider {
6
6
  getSearchEventRequestPayload: () => Omit<SearchEventRequest, 'actionCause' | 'searchQueryUid'>;
7
7
  getSearchUID: () => string;
@@ -47,6 +47,11 @@ 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
+ logOpenUserActions(metadata: CaseMetadata): Promise<void | import("../events").CustomEventResponse>;
51
+ logShowPrecedingSessions(metadata: CaseMetadata): Promise<void | import("../events").CustomEventResponse>;
52
+ logShowFollowingSessions(metadata: CaseMetadata): Promise<void | import("../events").CustomEventResponse>;
53
+ logViewedDocumentClick(document: UserActionsDocumentMetadata, metadata: CaseMetadata): Promise<void | import("../events").CustomEventResponse>;
54
+ logPageViewClick(pageView: UserActionsPageViewMetadata, metadata: CaseMetadata): Promise<void | import("../events").CustomEventResponse>;
50
55
  logDocumentOpen(info: PartialDocumentInformation, identifier: DocumentIdentifier, metadata?: CaseMetadata): Promise<void | import("../events").ClickEventResponse>;
51
56
  logCopyToClipboard(info: PartialDocumentInformation, identifier: DocumentIdentifier, metadata?: CaseMetadata): Promise<void | import("../events").ClickEventResponse>;
52
57
  logDocumentQuickview(info: PartialDocumentInformation, identifier: DocumentIdentifier, caseMetadata?: CaseMetadata): Promise<void | import("../events").ClickEventResponse>;
@@ -1,7 +1,12 @@
1
1
  import { CategoryFacetMetadata, FacetBaseMeta, FacetMetadata, FacetRangeMetadata, FacetSortMeta, InterfaceChangeMetadata, PagerMetadata, QueryErrorMeta, ResultsSortMetadata, StaticFilterToggleValueMetadata } from '../searchPage/searchPageEvents';
2
2
  export declare enum InsightEvents {
3
3
  contextChanged = "contextChanged",
4
- expandToFullUI = "expandToFullUI"
4
+ expandToFullUI = "expandToFullUI",
5
+ openUserActions = "openUserActions",
6
+ showPrecedingSessions = "showPrecedingSessions",
7
+ showFollowingSessions = "showFollowingSessions",
8
+ clickViewedDocument = "clickViewedDocument",
9
+ clickPageView = "clickPageView"
5
10
  }
6
11
  export interface CaseMetadata {
7
12
  caseId?: string;
@@ -12,6 +17,17 @@ export interface ExpandToFullUIMetadata extends CaseMetadata {
12
17
  fullSearchComponentName: string;
13
18
  triggeredBy: string;
14
19
  }
20
+ export interface UserActionsDocumentMetadata {
21
+ title: string;
22
+ uri: string;
23
+ uriHash?: string;
24
+ permanentId?: string;
25
+ }
26
+ export interface UserActionsPageViewMetadata {
27
+ title: string;
28
+ contentIdKey: string;
29
+ contentIdValue: string;
30
+ }
15
31
  export interface InsightInterfaceChangeMetadata extends InterfaceChangeMetadata, CaseMetadata {
16
32
  }
17
33
  export interface InsightFacetMetadata extends FacetMetadata, CaseMetadata {
@@ -359,7 +359,10 @@ const getRandomValues = (rnds) => {
359
359
  return rnds;
360
360
  };
361
361
 
362
- const keysOf = Object.keys;
362
+ const keysOf = Object.keys;
363
+ function isObject(o) {
364
+ return o !== null && typeof o === 'object' && !Array.isArray(o);
365
+ }
363
366
 
364
367
  const ticketKeysMapping = {
365
368
  id: 'svc_ticket_id',
@@ -912,7 +915,9 @@ class CoveoAnalyticsClient {
912
915
  const validateParams = (currentPayload) => this.validateParams(currentPayload);
913
916
  const processMeasurementProtocolConversionStep = (currentPayload) => usesMeasurementProtocol ? convertKeysToMeasurementProtocol(currentPayload) : currentPayload;
914
917
  const removeUnknownParameters = (currentPayload) => usesMeasurementProtocol ? this.removeUnknownParameters(currentPayload) : currentPayload;
915
- const processCustomParameters = (currentPayload) => usesMeasurementProtocol ? this.processCustomParameters(currentPayload) : currentPayload;
918
+ const processCustomParameters = (currentPayload) => usesMeasurementProtocol
919
+ ? this.processCustomParameters(currentPayload)
920
+ : this.mapCustomParametersToCustomData(currentPayload);
916
921
  const payloadToSend = yield [
917
922
  cleanPayloadStep,
918
923
  validateParams,
@@ -1078,13 +1083,30 @@ class CoveoAnalyticsClient {
1078
1083
  }
1079
1084
  processCustomParameters(payload) {
1080
1085
  const { custom } = payload, rest = __rest(payload, ["custom"]);
1081
- const lowercasedCustom = this.lowercaseKeys(custom);
1086
+ let lowercasedCustom = {};
1087
+ if (custom && isObject(custom)) {
1088
+ lowercasedCustom = this.lowercaseKeys(custom);
1089
+ }
1082
1090
  const newPayload = convertCustomMeasurementProtocolKeys(rest);
1083
1091
  return Object.assign(Object.assign({}, lowercasedCustom), newPayload);
1084
1092
  }
1093
+ mapCustomParametersToCustomData(payload) {
1094
+ const { custom } = payload, rest = __rest(payload, ["custom"]);
1095
+ if (custom && isObject(custom)) {
1096
+ const lowercasedCustom = this.lowercaseKeys(custom);
1097
+ return Object.assign(Object.assign({}, rest), { customData: Object.assign(Object.assign({}, lowercasedCustom), payload.customData) });
1098
+ }
1099
+ else {
1100
+ return payload;
1101
+ }
1102
+ }
1085
1103
  lowercaseKeys(custom) {
1086
- const keys = Object.keys(custom || {});
1087
- return keys.reduce((all, key) => (Object.assign(Object.assign({}, all), { [key.toLowerCase()]: custom[key] })), {});
1104
+ const keys = Object.keys(custom);
1105
+ let result = {};
1106
+ keys.forEach((key) => {
1107
+ result[key.toLowerCase()] = custom[key];
1108
+ });
1109
+ return result;
1088
1110
  }
1089
1111
  validateParams(payload) {
1090
1112
  const { anonymizeIp } = payload, rest = __rest(payload, ["anonymizeIp"]);
@@ -1114,6 +1136,11 @@ var InsightEvents;
1114
1136
  (function (InsightEvents) {
1115
1137
  InsightEvents["contextChanged"] = "contextChanged";
1116
1138
  InsightEvents["expandToFullUI"] = "expandToFullUI";
1139
+ InsightEvents["openUserActions"] = "openUserActions";
1140
+ InsightEvents["showPrecedingSessions"] = "showPrecedingSessions";
1141
+ InsightEvents["showFollowingSessions"] = "showFollowingSessions";
1142
+ InsightEvents["clickViewedDocument"] = "clickViewedDocument";
1143
+ InsightEvents["clickPageView"] = "clickPageView";
1117
1144
  })(InsightEvents || (InsightEvents = {}));
1118
1145
 
1119
1146
  var SearchPageEvents;
@@ -1223,6 +1250,11 @@ const CustomEventsTypes = {
1223
1250
  [SearchPageEvents.clearRecentResults]: 'recentlyClickedDocuments',
1224
1251
  [SearchPageEvents.showLessFoldedResults]: 'folding',
1225
1252
  [InsightEvents.expandToFullUI]: 'interface',
1253
+ [InsightEvents.openUserActions]: 'User Actions',
1254
+ [InsightEvents.showPrecedingSessions]: 'User Actions',
1255
+ [InsightEvents.showFollowingSessions]: 'User Actions',
1256
+ [InsightEvents.clickViewedDocument]: 'User Actions',
1257
+ [InsightEvents.clickPageView]: 'User Actions',
1226
1258
  [SearchPageEvents.caseDetach]: 'case',
1227
1259
  };
1228
1260
 
@@ -2419,6 +2451,24 @@ class CoveoInsightClient {
2419
2451
  const metadataToSend = generateMetadataToSend(metadata);
2420
2452
  return this.logCustomEvent(InsightEvents.expandToFullUI, metadataToSend);
2421
2453
  }
2454
+ logOpenUserActions(metadata) {
2455
+ const metadataToSend = generateMetadataToSend(metadata, false);
2456
+ return this.logCustomEvent(InsightEvents.openUserActions, metadataToSend);
2457
+ }
2458
+ logShowPrecedingSessions(metadata) {
2459
+ const metadataToSend = generateMetadataToSend(metadata, false);
2460
+ return this.logCustomEvent(InsightEvents.showPrecedingSessions, metadataToSend);
2461
+ }
2462
+ logShowFollowingSessions(metadata) {
2463
+ const metadataToSend = generateMetadataToSend(metadata, false);
2464
+ return this.logCustomEvent(InsightEvents.showFollowingSessions, metadataToSend);
2465
+ }
2466
+ logViewedDocumentClick(document, metadata) {
2467
+ return this.logCustomEvent(InsightEvents.clickViewedDocument, Object.assign(Object.assign({}, generateMetadataToSend(metadata, false)), { document }));
2468
+ }
2469
+ logPageViewClick(pageView, metadata) {
2470
+ return this.logCustomEvent(InsightEvents.clickPageView, Object.assign(Object.assign({}, generateMetadataToSend(metadata, false)), { pageView }));
2471
+ }
2422
2472
  logDocumentOpen(info, identifier, metadata) {
2423
2473
  return this.logClickEvent(SearchPageEvents.documentOpen, info, identifier, metadata ? generateMetadataToSend(metadata, false) : undefined);
2424
2474
  }
package/dist/library.js CHANGED
@@ -506,7 +506,10 @@ var getRandomValues = function (rnds) {
506
506
  return rnds;
507
507
  };
508
508
 
509
- var keysOf = Object.keys;
509
+ var keysOf = Object.keys;
510
+ function isObject(o) {
511
+ return o !== null && typeof o === 'object' && !Array.isArray(o);
512
+ }
510
513
 
511
514
  var ticketKeysMapping = {
512
515
  id: 'svc_ticket_id',
@@ -82808,7 +82811,9 @@ var CoveoAnalyticsClient = (function () {
82808
82811
  return usesMeasurementProtocol ? _this.removeUnknownParameters(currentPayload) : currentPayload;
82809
82812
  };
82810
82813
  processCustomParameters = function (currentPayload) {
82811
- return usesMeasurementProtocol ? _this.processCustomParameters(currentPayload) : currentPayload;
82814
+ return usesMeasurementProtocol
82815
+ ? _this.processCustomParameters(currentPayload)
82816
+ : _this.mapCustomParametersToCustomData(currentPayload);
82812
82817
  };
82813
82818
  return [4, [
82814
82819
  cleanPayloadStep,
@@ -83078,16 +83083,30 @@ var CoveoAnalyticsClient = (function () {
83078
83083
  };
83079
83084
  CoveoAnalyticsClient.prototype.processCustomParameters = function (payload) {
83080
83085
  var custom = payload.custom, rest = __rest(payload, ["custom"]);
83081
- var lowercasedCustom = this.lowercaseKeys(custom);
83086
+ var lowercasedCustom = {};
83087
+ if (custom && isObject(custom)) {
83088
+ lowercasedCustom = this.lowercaseKeys(custom);
83089
+ }
83082
83090
  var newPayload = convertCustomMeasurementProtocolKeys(rest);
83083
83091
  return __assign(__assign({}, lowercasedCustom), newPayload);
83084
83092
  };
83093
+ CoveoAnalyticsClient.prototype.mapCustomParametersToCustomData = function (payload) {
83094
+ var custom = payload.custom, rest = __rest(payload, ["custom"]);
83095
+ if (custom && isObject(custom)) {
83096
+ var lowercasedCustom = this.lowercaseKeys(custom);
83097
+ return __assign(__assign({}, rest), { customData: __assign(__assign({}, lowercasedCustom), payload.customData) });
83098
+ }
83099
+ else {
83100
+ return payload;
83101
+ }
83102
+ };
83085
83103
  CoveoAnalyticsClient.prototype.lowercaseKeys = function (custom) {
83086
- var keys = Object.keys(custom || {});
83087
- return keys.reduce(function (all, key) {
83088
- var _a;
83089
- return (__assign(__assign({}, all), (_a = {}, _a[key.toLowerCase()] = custom[key], _a)));
83090
- }, {});
83104
+ var keys = Object.keys(custom);
83105
+ var result = {};
83106
+ keys.forEach(function (key) {
83107
+ result[key.toLowerCase()] = custom[key];
83108
+ });
83109
+ return result;
83091
83110
  };
83092
83111
  CoveoAnalyticsClient.prototype.validateParams = function (payload) {
83093
83112
  var anonymizeIp = payload.anonymizeIp, rest = __rest(payload, ["anonymizeIp"]);
@@ -83450,7 +83469,7 @@ var Plugins = (function () {
83450
83469
  }
83451
83470
  var actionFunction = plugin[fn];
83452
83471
  if (!actionFunction) {
83453
- throw new Error("The function \"" + fn + "\" does not exists on the plugin \"" + name + "\".");
83472
+ throw new Error("The function \"" + fn + "\" does not exist on the plugin \"" + name + "\".");
83454
83473
  }
83455
83474
  if (typeof actionFunction !== 'function') {
83456
83475
  throw new Error("\"" + fn + "\" of the plugin \"" + name + "\" is not a function.");
@@ -83621,6 +83640,11 @@ var InsightEvents;
83621
83640
  (function (InsightEvents) {
83622
83641
  InsightEvents["contextChanged"] = "contextChanged";
83623
83642
  InsightEvents["expandToFullUI"] = "expandToFullUI";
83643
+ InsightEvents["openUserActions"] = "openUserActions";
83644
+ InsightEvents["showPrecedingSessions"] = "showPrecedingSessions";
83645
+ InsightEvents["showFollowingSessions"] = "showFollowingSessions";
83646
+ InsightEvents["clickViewedDocument"] = "clickViewedDocument";
83647
+ InsightEvents["clickPageView"] = "clickPageView";
83624
83648
  })(InsightEvents || (InsightEvents = {}));
83625
83649
 
83626
83650
  var _a;
@@ -83731,6 +83755,11 @@ var CustomEventsTypes = (_a = {},
83731
83755
  _a[SearchPageEvents.clearRecentResults] = 'recentlyClickedDocuments',
83732
83756
  _a[SearchPageEvents.showLessFoldedResults] = 'folding',
83733
83757
  _a[InsightEvents.expandToFullUI] = 'interface',
83758
+ _a[InsightEvents.openUserActions] = 'User Actions',
83759
+ _a[InsightEvents.showPrecedingSessions] = 'User Actions',
83760
+ _a[InsightEvents.showFollowingSessions] = 'User Actions',
83761
+ _a[InsightEvents.clickViewedDocument] = 'User Actions',
83762
+ _a[InsightEvents.clickPageView] = 'User Actions',
83734
83763
  _a[SearchPageEvents.caseDetach] = 'case',
83735
83764
  _a);
83736
83765
 
@@ -85269,6 +85298,24 @@ var CoveoInsightClient = (function () {
85269
85298
  var metadataToSend = generateMetadataToSend(metadata);
85270
85299
  return this.logCustomEvent(InsightEvents.expandToFullUI, metadataToSend);
85271
85300
  };
85301
+ CoveoInsightClient.prototype.logOpenUserActions = function (metadata) {
85302
+ var metadataToSend = generateMetadataToSend(metadata, false);
85303
+ return this.logCustomEvent(InsightEvents.openUserActions, metadataToSend);
85304
+ };
85305
+ CoveoInsightClient.prototype.logShowPrecedingSessions = function (metadata) {
85306
+ var metadataToSend = generateMetadataToSend(metadata, false);
85307
+ return this.logCustomEvent(InsightEvents.showPrecedingSessions, metadataToSend);
85308
+ };
85309
+ CoveoInsightClient.prototype.logShowFollowingSessions = function (metadata) {
85310
+ var metadataToSend = generateMetadataToSend(metadata, false);
85311
+ return this.logCustomEvent(InsightEvents.showFollowingSessions, metadataToSend);
85312
+ };
85313
+ CoveoInsightClient.prototype.logViewedDocumentClick = function (document, metadata) {
85314
+ return this.logCustomEvent(InsightEvents.clickViewedDocument, __assign(__assign({}, generateMetadataToSend(metadata, false)), { document: document }));
85315
+ };
85316
+ CoveoInsightClient.prototype.logPageViewClick = function (pageView, metadata) {
85317
+ return this.logCustomEvent(InsightEvents.clickPageView, __assign(__assign({}, generateMetadataToSend(metadata, false)), { pageView: pageView }));
85318
+ };
85272
85319
  CoveoInsightClient.prototype.logDocumentOpen = function (info, identifier, metadata) {
85273
85320
  return this.logClickEvent(SearchPageEvents.documentOpen, info, identifier, metadata ? generateMetadataToSend(metadata, false) : undefined);
85274
85321
  };
@@ -420,7 +420,10 @@ const addPageViewToHistory = (pageViewValue) => __awaiter(void 0, void 0, void 0
420
420
  yield store.addElementAsync(historyElement);
421
421
  });
422
422
 
423
- const keysOf = Object.keys;
423
+ const keysOf = Object.keys;
424
+ function isObject(o) {
425
+ return o !== null && typeof o === 'object' && !Array.isArray(o);
426
+ }
424
427
 
425
428
  const ticketKeysMapping = {
426
429
  id: 'svc_ticket_id',
@@ -912,7 +915,9 @@ class CoveoAnalyticsClient {
912
915
  const validateParams = (currentPayload) => this.validateParams(currentPayload);
913
916
  const processMeasurementProtocolConversionStep = (currentPayload) => usesMeasurementProtocol ? convertKeysToMeasurementProtocol(currentPayload) : currentPayload;
914
917
  const removeUnknownParameters = (currentPayload) => usesMeasurementProtocol ? this.removeUnknownParameters(currentPayload) : currentPayload;
915
- const processCustomParameters = (currentPayload) => usesMeasurementProtocol ? this.processCustomParameters(currentPayload) : currentPayload;
918
+ const processCustomParameters = (currentPayload) => usesMeasurementProtocol
919
+ ? this.processCustomParameters(currentPayload)
920
+ : this.mapCustomParametersToCustomData(currentPayload);
916
921
  const payloadToSend = yield [
917
922
  cleanPayloadStep,
918
923
  validateParams,
@@ -1078,13 +1083,30 @@ class CoveoAnalyticsClient {
1078
1083
  }
1079
1084
  processCustomParameters(payload) {
1080
1085
  const { custom } = payload, rest = __rest(payload, ["custom"]);
1081
- const lowercasedCustom = this.lowercaseKeys(custom);
1086
+ let lowercasedCustom = {};
1087
+ if (custom && isObject(custom)) {
1088
+ lowercasedCustom = this.lowercaseKeys(custom);
1089
+ }
1082
1090
  const newPayload = convertCustomMeasurementProtocolKeys(rest);
1083
1091
  return Object.assign(Object.assign({}, lowercasedCustom), newPayload);
1084
1092
  }
1093
+ mapCustomParametersToCustomData(payload) {
1094
+ const { custom } = payload, rest = __rest(payload, ["custom"]);
1095
+ if (custom && isObject(custom)) {
1096
+ const lowercasedCustom = this.lowercaseKeys(custom);
1097
+ return Object.assign(Object.assign({}, rest), { customData: Object.assign(Object.assign({}, lowercasedCustom), payload.customData) });
1098
+ }
1099
+ else {
1100
+ return payload;
1101
+ }
1102
+ }
1085
1103
  lowercaseKeys(custom) {
1086
- const keys = Object.keys(custom || {});
1087
- return keys.reduce((all, key) => (Object.assign(Object.assign({}, all), { [key.toLowerCase()]: custom[key] })), {});
1104
+ const keys = Object.keys(custom);
1105
+ let result = {};
1106
+ keys.forEach((key) => {
1107
+ result[key.toLowerCase()] = custom[key];
1108
+ });
1109
+ return result;
1088
1110
  }
1089
1111
  validateParams(payload) {
1090
1112
  const { anonymizeIp } = payload, rest = __rest(payload, ["anonymizeIp"]);
@@ -1131,6 +1153,11 @@ var InsightEvents;
1131
1153
  (function (InsightEvents) {
1132
1154
  InsightEvents["contextChanged"] = "contextChanged";
1133
1155
  InsightEvents["expandToFullUI"] = "expandToFullUI";
1156
+ InsightEvents["openUserActions"] = "openUserActions";
1157
+ InsightEvents["showPrecedingSessions"] = "showPrecedingSessions";
1158
+ InsightEvents["showFollowingSessions"] = "showFollowingSessions";
1159
+ InsightEvents["clickViewedDocument"] = "clickViewedDocument";
1160
+ InsightEvents["clickPageView"] = "clickPageView";
1134
1161
  })(InsightEvents || (InsightEvents = {}));
1135
1162
 
1136
1163
  var SearchPageEvents;
@@ -1240,6 +1267,11 @@ const CustomEventsTypes = {
1240
1267
  [SearchPageEvents.clearRecentResults]: 'recentlyClickedDocuments',
1241
1268
  [SearchPageEvents.showLessFoldedResults]: 'folding',
1242
1269
  [InsightEvents.expandToFullUI]: 'interface',
1270
+ [InsightEvents.openUserActions]: 'User Actions',
1271
+ [InsightEvents.showPrecedingSessions]: 'User Actions',
1272
+ [InsightEvents.showFollowingSessions]: 'User Actions',
1273
+ [InsightEvents.clickViewedDocument]: 'User Actions',
1274
+ [InsightEvents.clickPageView]: 'User Actions',
1243
1275
  [SearchPageEvents.caseDetach]: 'case',
1244
1276
  };
1245
1277
 
@@ -2436,6 +2468,24 @@ class CoveoInsightClient {
2436
2468
  const metadataToSend = generateMetadataToSend(metadata);
2437
2469
  return this.logCustomEvent(InsightEvents.expandToFullUI, metadataToSend);
2438
2470
  }
2471
+ logOpenUserActions(metadata) {
2472
+ const metadataToSend = generateMetadataToSend(metadata, false);
2473
+ return this.logCustomEvent(InsightEvents.openUserActions, metadataToSend);
2474
+ }
2475
+ logShowPrecedingSessions(metadata) {
2476
+ const metadataToSend = generateMetadataToSend(metadata, false);
2477
+ return this.logCustomEvent(InsightEvents.showPrecedingSessions, metadataToSend);
2478
+ }
2479
+ logShowFollowingSessions(metadata) {
2480
+ const metadataToSend = generateMetadataToSend(metadata, false);
2481
+ return this.logCustomEvent(InsightEvents.showFollowingSessions, metadataToSend);
2482
+ }
2483
+ logViewedDocumentClick(document, metadata) {
2484
+ return this.logCustomEvent(InsightEvents.clickViewedDocument, Object.assign(Object.assign({}, generateMetadataToSend(metadata, false)), { document }));
2485
+ }
2486
+ logPageViewClick(pageView, metadata) {
2487
+ return this.logCustomEvent(InsightEvents.clickPageView, Object.assign(Object.assign({}, generateMetadataToSend(metadata, false)), { pageView }));
2488
+ }
2439
2489
  logDocumentOpen(info, identifier, metadata) {
2440
2490
  return this.logClickEvent(SearchPageEvents.documentOpen, info, identifier, metadata ? generateMetadataToSend(metadata, false) : undefined);
2441
2491
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coveo.analytics",
3
- "version": "2.23.8",
3
+ "version": "2.23.10",
4
4
  "description": "📈 Coveo analytics client (node and browser compatible) ",
5
5
  "main": "dist/library.js",
6
6
  "module": "dist/library.es.js",
@@ -34,6 +34,7 @@ import {isApiKey} from './token';
34
34
  import {isReactNative, ReactNativeRuntimeWarning} from '../react-native/react-native-utils';
35
35
  import {doNotTrack} from '../donottrack';
36
36
  import {NullStorage} from '../storage';
37
+ import {isObject} from './utils';
37
38
 
38
39
  export const Version = 'v15';
39
40
 
@@ -294,7 +295,9 @@ export class CoveoAnalyticsClient implements AnalyticsClient, VisitorIdProvider
294
295
  const removeUnknownParameters: ProcessPayloadStep = (currentPayload) =>
295
296
  usesMeasurementProtocol ? this.removeUnknownParameters(currentPayload) : currentPayload;
296
297
  const processCustomParameters: ProcessPayloadStep = (currentPayload) =>
297
- usesMeasurementProtocol ? this.processCustomParameters(currentPayload) : currentPayload;
298
+ usesMeasurementProtocol
299
+ ? this.processCustomParameters(currentPayload)
300
+ : this.mapCustomParametersToCustomData(currentPayload);
298
301
 
299
302
  const payloadToSend = await [
300
303
  cleanPayloadStep,
@@ -489,8 +492,10 @@ export class CoveoAnalyticsClient implements AnalyticsClient, VisitorIdProvider
489
492
 
490
493
  private processCustomParameters(payload: IRequestPayload): IRequestPayload {
491
494
  const {custom, ...rest} = payload;
492
-
493
- const lowercasedCustom = this.lowercaseKeys(custom);
495
+ let lowercasedCustom = {};
496
+ if (custom && isObject(custom)) {
497
+ lowercasedCustom = this.lowercaseKeys(custom);
498
+ }
494
499
 
495
500
  const newPayload = convertCustomMeasurementProtocolKeys(rest);
496
501
 
@@ -500,16 +505,23 @@ export class CoveoAnalyticsClient implements AnalyticsClient, VisitorIdProvider
500
505
  };
501
506
  }
502
507
 
503
- private lowercaseKeys(custom: any) {
504
- const keys = Object.keys(custom || {});
508
+ private mapCustomParametersToCustomData(payload: IRequestPayload): IRequestPayload {
509
+ const {custom, ...rest} = payload;
510
+ if (custom && isObject(custom)) {
511
+ const lowercasedCustom = this.lowercaseKeys(custom);
512
+ return {...rest, customData: {...lowercasedCustom, ...payload.customData}};
513
+ } else {
514
+ return payload;
515
+ }
516
+ }
505
517
 
506
- return keys.reduce(
507
- (all, key) => ({
508
- ...all,
509
- [key.toLowerCase()]: custom[key],
510
- }),
511
- {}
512
- );
518
+ private lowercaseKeys(custom: Record<string, unknown>) {
519
+ const keys = Object.keys(custom);
520
+ let result: Record<string, unknown> = {};
521
+ keys.forEach((key) => {
522
+ result[key.toLowerCase() as string] = custom[key];
523
+ });
524
+ return result;
513
525
  }
514
526
 
515
527
  private validateParams(payload: IRequestPayload): IRequestPayload {
@@ -1,3 +1,6 @@
1
1
  // Object.keys returns `string[]` this adds types
2
2
  // see https://github.com/microsoft/TypeScript/pull/12253#issuecomment-393954723
3
3
  export const keysOf = Object.keys as <T>(o: T) => Extract<keyof T, string>[];
4
+ export function isObject(o: any): boolean {
5
+ return o !== null && typeof o === 'object' && !Array.isArray(o);
6
+ }
@@ -38,7 +38,7 @@ export class Plugins {
38
38
  }
39
39
  const actionFunction = plugin[fn];
40
40
  if (!actionFunction) {
41
- throw new Error(`The function "${fn}" does not exists on the plugin "${name}".`);
41
+ throw new Error(`The function "${fn}" does not exist on the plugin "${name}".`);
42
42
  }
43
43
  if (typeof actionFunction !== 'function') {
44
44
  throw new Error(`"${fn}" of the plugin "${name}" is not a function.`);