coveo.analytics 2.23.5 → 2.23.6

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.
@@ -0,0 +1,3259 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
+ typeof define === 'function' && define.amd ? define(factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.coveoua = factory());
5
+ })(this, (function () { 'use strict';
6
+
7
+ /*! *****************************************************************************
8
+ Copyright (c) Microsoft Corporation.
9
+
10
+ Permission to use, copy, modify, and/or distribute this software for any
11
+ purpose with or without fee is hereby granted.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
+ PERFORMANCE OF THIS SOFTWARE.
20
+ ***************************************************************************** */
21
+ /* global Reflect, Promise */
22
+
23
+ var extendStatics = function(d, b) {
24
+ extendStatics = Object.setPrototypeOf ||
25
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
26
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
27
+ return extendStatics(d, b);
28
+ };
29
+
30
+ function __extends(d, b) {
31
+ extendStatics(d, b);
32
+ function __() { this.constructor = d; }
33
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
34
+ }
35
+
36
+ var __assign = function() {
37
+ __assign = Object.assign || function __assign(t) {
38
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
39
+ s = arguments[i];
40
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
41
+ }
42
+ return t;
43
+ };
44
+ return __assign.apply(this, arguments);
45
+ };
46
+
47
+ function __rest(s, e) {
48
+ var t = {};
49
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
50
+ t[p] = s[p];
51
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
52
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
53
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
54
+ t[p[i]] = s[p[i]];
55
+ }
56
+ return t;
57
+ }
58
+
59
+ function __awaiter(thisArg, _arguments, P, generator) {
60
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
61
+ return new (P || (P = Promise))(function (resolve, reject) {
62
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
63
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
64
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
65
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
66
+ });
67
+ }
68
+
69
+ function __generator(thisArg, body) {
70
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
71
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
72
+ function verb(n) { return function (v) { return step([n, v]); }; }
73
+ function step(op) {
74
+ if (f) throw new TypeError("Generator is already executing.");
75
+ while (_) try {
76
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
77
+ if (y = 0, t) op = [op[0] & 2, t.value];
78
+ switch (op[0]) {
79
+ case 0: case 1: t = op; break;
80
+ case 4: _.label++; return { value: op[1], done: false };
81
+ case 5: _.label++; y = op[1]; op = [0]; continue;
82
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
83
+ default:
84
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
85
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
86
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
87
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
88
+ if (t[2]) _.ops.pop();
89
+ _.trys.pop(); continue;
90
+ }
91
+ op = body.call(thisArg, _);
92
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
93
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
94
+ }
95
+ }
96
+
97
+ function __spreadArrays() {
98
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
99
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
100
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
101
+ r[k] = a[j];
102
+ return r;
103
+ }
104
+
105
+ var EventType;
106
+ (function (EventType) {
107
+ EventType["search"] = "search";
108
+ EventType["click"] = "click";
109
+ EventType["custom"] = "custom";
110
+ EventType["view"] = "view";
111
+ EventType["collect"] = "collect";
112
+ })(EventType || (EventType = {}));
113
+
114
+ function hasWindow() {
115
+ return typeof window !== 'undefined';
116
+ }
117
+ function hasNavigator() {
118
+ return typeof navigator !== 'undefined';
119
+ }
120
+ function hasDocument() {
121
+ return typeof document !== 'undefined';
122
+ }
123
+ function hasLocalStorage() {
124
+ try {
125
+ return typeof localStorage !== 'undefined';
126
+ }
127
+ catch (error) {
128
+ return false;
129
+ }
130
+ }
131
+ function hasSessionStorage() {
132
+ try {
133
+ return typeof sessionStorage !== 'undefined';
134
+ }
135
+ catch (error) {
136
+ return false;
137
+ }
138
+ }
139
+ function hasCookieStorage() {
140
+ return hasNavigator() && navigator.cookieEnabled;
141
+ }
142
+ function hasCrypto() {
143
+ return typeof crypto !== 'undefined';
144
+ }
145
+ function hasCryptoRandomValues() {
146
+ return hasCrypto() && typeof crypto.getRandomValues !== 'undefined';
147
+ }
148
+
149
+ var eventTypesForDefaultValues = [EventType.click, EventType.custom, EventType.search, EventType.view];
150
+ var addDefaultValues = function (eventType, payload) {
151
+ return eventTypesForDefaultValues.indexOf(eventType) !== -1
152
+ ? __assign({ language: hasDocument() ? document.documentElement.lang : 'unknown', userAgent: hasNavigator() ? navigator.userAgent : 'unknown' }, payload) : payload;
153
+ };
154
+
155
+ var Cookie = (function () {
156
+ function Cookie() {
157
+ }
158
+ Cookie.set = function (name, value, expiration) {
159
+ var domain, domainParts, date, expires, host;
160
+ if (expiration) {
161
+ date = new Date();
162
+ date.setTime(date.getTime() + expiration);
163
+ expires = '; expires=' + date.toGMTString();
164
+ }
165
+ else {
166
+ expires = '';
167
+ }
168
+ host = window.location.hostname;
169
+ if (host.indexOf('.') === -1) {
170
+ document.cookie = name + '=' + value + expires + '; path=/';
171
+ }
172
+ else {
173
+ domainParts = host.split('.');
174
+ domainParts.shift();
175
+ domain = '.' + domainParts.join('.');
176
+ writeCookie({ name: name, value: value, expires: expires, domain: domain });
177
+ if (Cookie.get(name) == null || Cookie.get(name) != value) {
178
+ domain = '.' + host;
179
+ writeCookie({ name: name, value: value, expires: expires, domain: domain });
180
+ }
181
+ }
182
+ };
183
+ Cookie.get = function (name) {
184
+ var cookiePrefix = name + '=';
185
+ var cookieArray = document.cookie.split(';');
186
+ for (var i = 0; i < cookieArray.length; i++) {
187
+ var cookie = cookieArray[i];
188
+ cookie = cookie.replace(/^\s+/, '');
189
+ if (cookie.indexOf(cookiePrefix) == 0) {
190
+ return cookie.substring(cookiePrefix.length, cookie.length);
191
+ }
192
+ }
193
+ return null;
194
+ };
195
+ Cookie.erase = function (name) {
196
+ Cookie.set(name, '', -1);
197
+ };
198
+ return Cookie;
199
+ }());
200
+ function writeCookie(details) {
201
+ var name = details.name, value = details.value, expires = details.expires, domain = details.domain;
202
+ document.cookie = name + "=" + value + expires + "; path=/; domain=" + domain + "; SameSite=Lax";
203
+ }
204
+
205
+ var preferredStorage = null;
206
+ function getAvailableStorage() {
207
+ if (hasLocalStorage()) {
208
+ return localStorage;
209
+ }
210
+ if (hasCookieStorage()) {
211
+ return new CookieStorage();
212
+ }
213
+ if (hasSessionStorage()) {
214
+ return sessionStorage;
215
+ }
216
+ return new NullStorage();
217
+ }
218
+ var CookieStorage = (function () {
219
+ function CookieStorage() {
220
+ }
221
+ CookieStorage.prototype.getItem = function (key) {
222
+ return Cookie.get("" + CookieStorage.prefix + key);
223
+ };
224
+ CookieStorage.prototype.removeItem = function (key) {
225
+ Cookie.erase("" + CookieStorage.prefix + key);
226
+ };
227
+ CookieStorage.prototype.setItem = function (key, data) {
228
+ Cookie.set("" + CookieStorage.prefix + key, data);
229
+ };
230
+ CookieStorage.prefix = 'coveo_';
231
+ return CookieStorage;
232
+ }());
233
+ var CookieAndLocalStorage = (function () {
234
+ function CookieAndLocalStorage() {
235
+ this.cookieStorage = new CookieStorage();
236
+ }
237
+ CookieAndLocalStorage.prototype.getItem = function (key) {
238
+ return localStorage.getItem(key) || this.cookieStorage.getItem(key);
239
+ };
240
+ CookieAndLocalStorage.prototype.removeItem = function (key) {
241
+ this.cookieStorage.removeItem(key);
242
+ localStorage.removeItem(key);
243
+ };
244
+ CookieAndLocalStorage.prototype.setItem = function (key, data) {
245
+ localStorage.setItem(key, data);
246
+ this.cookieStorage.setItem(key, data);
247
+ };
248
+ return CookieAndLocalStorage;
249
+ }());
250
+ var NullStorage = (function () {
251
+ function NullStorage() {
252
+ }
253
+ NullStorage.prototype.getItem = function (key) {
254
+ return null;
255
+ };
256
+ NullStorage.prototype.removeItem = function (key) {
257
+ };
258
+ NullStorage.prototype.setItem = function (key, data) {
259
+ };
260
+ return NullStorage;
261
+ }());
262
+
263
+ var storage = /*#__PURE__*/Object.freeze({
264
+ __proto__: null,
265
+ preferredStorage: preferredStorage,
266
+ getAvailableStorage: getAvailableStorage,
267
+ CookieStorage: CookieStorage,
268
+ CookieAndLocalStorage: CookieAndLocalStorage,
269
+ NullStorage: NullStorage
270
+ });
271
+
272
+ var STORE_KEY = '__coveo.analytics.history';
273
+ var MAX_NUMBER_OF_HISTORY_ELEMENTS = 20;
274
+ var MIN_THRESHOLD_FOR_DUPLICATE_VALUE = 1000 * 60;
275
+ var MAX_VALUE_SIZE = 75;
276
+ var HistoryStore = (function () {
277
+ function HistoryStore(store) {
278
+ this.store = store || getAvailableStorage();
279
+ }
280
+ HistoryStore.prototype.addElement = function (elem) {
281
+ elem.internalTime = new Date().getTime();
282
+ elem = this.cropQueryElement(this.stripEmptyQuery(elem));
283
+ var currentHistory = this.getHistoryWithInternalTime();
284
+ if (currentHistory != null) {
285
+ if (this.isValidEntry(elem)) {
286
+ this.setHistory([elem].concat(currentHistory));
287
+ }
288
+ }
289
+ else {
290
+ this.setHistory([elem]);
291
+ }
292
+ };
293
+ HistoryStore.prototype.addElementAsync = function (elem) {
294
+ return __awaiter(this, void 0, void 0, function () {
295
+ var currentHistory;
296
+ return __generator(this, function (_a) {
297
+ switch (_a.label) {
298
+ case 0:
299
+ elem.internalTime = new Date().getTime();
300
+ elem = this.cropQueryElement(this.stripEmptyQuery(elem));
301
+ return [4, this.getHistoryWithInternalTimeAsync()];
302
+ case 1:
303
+ currentHistory = _a.sent();
304
+ if (currentHistory != null) {
305
+ if (this.isValidEntry(elem)) {
306
+ this.setHistory([elem].concat(currentHistory));
307
+ }
308
+ }
309
+ else {
310
+ this.setHistory([elem]);
311
+ }
312
+ return [2];
313
+ }
314
+ });
315
+ });
316
+ };
317
+ HistoryStore.prototype.getHistory = function () {
318
+ var history = this.getHistoryWithInternalTime();
319
+ return this.stripEmptyQueries(this.stripInternalTime(history));
320
+ };
321
+ HistoryStore.prototype.getHistoryAsync = function () {
322
+ return __awaiter(this, void 0, void 0, function () {
323
+ var history;
324
+ return __generator(this, function (_a) {
325
+ switch (_a.label) {
326
+ case 0: return [4, this.getHistoryWithInternalTimeAsync()];
327
+ case 1:
328
+ history = _a.sent();
329
+ return [2, this.stripEmptyQueries(this.stripInternalTime(history))];
330
+ }
331
+ });
332
+ });
333
+ };
334
+ HistoryStore.prototype.getHistoryWithInternalTime = function () {
335
+ try {
336
+ var elements = this.store.getItem(STORE_KEY);
337
+ if (elements && typeof elements === 'string') {
338
+ return JSON.parse(elements);
339
+ }
340
+ else {
341
+ return [];
342
+ }
343
+ }
344
+ catch (e) {
345
+ return [];
346
+ }
347
+ };
348
+ HistoryStore.prototype.getHistoryWithInternalTimeAsync = function () {
349
+ return __awaiter(this, void 0, void 0, function () {
350
+ var elements;
351
+ return __generator(this, function (_a) {
352
+ switch (_a.label) {
353
+ case 0:
354
+ _a.trys.push([0, 2, , 3]);
355
+ return [4, this.store.getItem(STORE_KEY)];
356
+ case 1:
357
+ elements = _a.sent();
358
+ if (elements) {
359
+ return [2, JSON.parse(elements)];
360
+ }
361
+ else {
362
+ return [2, []];
363
+ }
364
+ case 2:
365
+ _a.sent();
366
+ return [2, []];
367
+ case 3: return [2];
368
+ }
369
+ });
370
+ });
371
+ };
372
+ HistoryStore.prototype.setHistory = function (history) {
373
+ try {
374
+ this.store.setItem(STORE_KEY, JSON.stringify(history.slice(0, MAX_NUMBER_OF_HISTORY_ELEMENTS)));
375
+ }
376
+ catch (e) {
377
+ }
378
+ };
379
+ HistoryStore.prototype.clear = function () {
380
+ try {
381
+ this.store.removeItem(STORE_KEY);
382
+ }
383
+ catch (e) {
384
+ }
385
+ };
386
+ HistoryStore.prototype.getMostRecentElement = function () {
387
+ var currentHistory = this.getHistoryWithInternalTime();
388
+ if (currentHistory != null) {
389
+ var sorted = currentHistory.sort(function (first, second) {
390
+ return (second.internalTime || 0) - (first.internalTime || 0);
391
+ });
392
+ return sorted[0];
393
+ }
394
+ return null;
395
+ };
396
+ HistoryStore.prototype.cropQueryElement = function (part) {
397
+ if (part.name && part.value && part.name.toLowerCase() === 'query') {
398
+ part.value = part.value.slice(0, MAX_VALUE_SIZE);
399
+ }
400
+ return part;
401
+ };
402
+ HistoryStore.prototype.isValidEntry = function (elem) {
403
+ var lastEntry = this.getMostRecentElement();
404
+ if (lastEntry && lastEntry.value == elem.value) {
405
+ return (elem.internalTime || 0) - (lastEntry.internalTime || 0) > MIN_THRESHOLD_FOR_DUPLICATE_VALUE;
406
+ }
407
+ return true;
408
+ };
409
+ HistoryStore.prototype.stripInternalTime = function (history) {
410
+ return history.map(function (part) {
411
+ var name = part.name, time = part.time, value = part.value;
412
+ return { name: name, time: time, value: value };
413
+ });
414
+ };
415
+ HistoryStore.prototype.stripEmptyQuery = function (part) {
416
+ var name = part.name, time = part.time, value = part.value;
417
+ if (name && typeof value === 'string' && name.toLowerCase() === 'query' && value.trim() === '') {
418
+ return { name: name, time: time };
419
+ }
420
+ return part;
421
+ };
422
+ HistoryStore.prototype.stripEmptyQueries = function (history) {
423
+ var _this = this;
424
+ return history.map(function (part) { return _this.stripEmptyQuery(part); });
425
+ };
426
+ return HistoryStore;
427
+ }());
428
+
429
+ var history = /*#__PURE__*/Object.freeze({
430
+ __proto__: null,
431
+ STORE_KEY: STORE_KEY,
432
+ MAX_NUMBER_OF_HISTORY_ELEMENTS: MAX_NUMBER_OF_HISTORY_ELEMENTS,
433
+ MIN_THRESHOLD_FOR_DUPLICATE_VALUE: MIN_THRESHOLD_FOR_DUPLICATE_VALUE,
434
+ MAX_VALUE_SIZE: MAX_VALUE_SIZE,
435
+ HistoryStore: HistoryStore,
436
+ 'default': HistoryStore
437
+ });
438
+
439
+ var enhanceViewEvent = function (eventType, payload) { return __awaiter(void 0, void 0, void 0, function () {
440
+ return __generator(this, function (_a) {
441
+ switch (_a.label) {
442
+ case 0:
443
+ if (!(eventType === EventType.view)) return [3, 2];
444
+ return [4, addPageViewToHistory(payload.contentIdValue)];
445
+ case 1:
446
+ _a.sent();
447
+ return [2, __assign({ location: window.location.toString(), referrer: document.referrer, title: document.title }, payload)];
448
+ case 2: return [2, payload];
449
+ }
450
+ });
451
+ }); };
452
+ var addPageViewToHistory = function (pageViewValue) { return __awaiter(void 0, void 0, void 0, function () {
453
+ var store, historyElement;
454
+ return __generator(this, function (_a) {
455
+ switch (_a.label) {
456
+ case 0:
457
+ store = new HistoryStore();
458
+ historyElement = {
459
+ name: 'PageView',
460
+ value: pageViewValue,
461
+ time: JSON.stringify(new Date()),
462
+ };
463
+ return [4, store.addElementAsync(historyElement)];
464
+ case 1:
465
+ _a.sent();
466
+ return [2];
467
+ }
468
+ });
469
+ }); };
470
+
471
+ var uuidv4 = function (a) {
472
+ if (!!a) {
473
+ return (Number(a) ^ (getRandomValues(new Uint8Array(1))[0] % 16 >> (Number(a) / 4))).toString(16);
474
+ }
475
+ return ("" + 1e7 + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, uuidv4);
476
+ };
477
+ var getRandomValues = function (rnds) {
478
+ if (hasCryptoRandomValues()) {
479
+ return crypto.getRandomValues(rnds);
480
+ }
481
+ for (var i = 0, r = 0; i < rnds.length; i++) {
482
+ if ((i & 0x03) === 0) {
483
+ r = Math.random() * 0x100000000;
484
+ }
485
+ rnds[i] = (r >>> ((i & 0x03) << 3)) & 0xff;
486
+ }
487
+ return rnds;
488
+ };
489
+
490
+ var keysOf = Object.keys;
491
+
492
+ var ticketKeysMapping = {
493
+ id: 'svc_ticket_id',
494
+ subject: 'svc_ticket_subject',
495
+ description: 'svc_ticket_description',
496
+ category: 'svc_ticket_category',
497
+ productId: 'svc_ticket_product_id',
498
+ custom: 'svc_ticket_custom',
499
+ };
500
+ var ticketKeysMappingValues = keysOf(ticketKeysMapping).map(function (key) { return ticketKeysMapping[key]; });
501
+ var ticketSubKeysMatchGroup = __spreadArrays(ticketKeysMappingValues).join('|');
502
+ var ticketKeyRegex = new RegExp("^(" + ticketSubKeysMatchGroup + "$)");
503
+ var serviceActionsKeysMapping = {
504
+ svcAction: 'svc_action',
505
+ svcActionData: 'svc_action_data',
506
+ };
507
+ var convertTicketToMeasurementProtocol = function (ticket) {
508
+ return keysOf(ticket)
509
+ .filter(function (key) { return ticket[key] !== undefined; })
510
+ .reduce(function (mappedTicket, key) {
511
+ var _a;
512
+ var newKey = ticketKeysMapping[key] || key;
513
+ return __assign(__assign({}, mappedTicket), (_a = {}, _a[newKey] = ticket[key], _a));
514
+ }, {});
515
+ };
516
+ var isTicketKey = function (key) { return ticketKeyRegex.test(key); };
517
+ var isServiceKey = [isTicketKey];
518
+
519
+ var productKeysMapping = {
520
+ id: 'id',
521
+ name: 'nm',
522
+ brand: 'br',
523
+ category: 'ca',
524
+ variant: 'va',
525
+ price: 'pr',
526
+ quantity: 'qt',
527
+ coupon: 'cc',
528
+ position: 'ps',
529
+ group: 'group',
530
+ };
531
+ var impressionKeysMapping = {
532
+ id: 'id',
533
+ name: 'nm',
534
+ brand: 'br',
535
+ category: 'ca',
536
+ variant: 'va',
537
+ position: 'ps',
538
+ price: 'pr',
539
+ group: 'group',
540
+ };
541
+ var productActionsKeysMapping = {
542
+ action: 'pa',
543
+ list: 'pal',
544
+ listSource: 'pls',
545
+ };
546
+ var transactionActionsKeysMapping = {
547
+ id: 'ti',
548
+ revenue: 'tr',
549
+ tax: 'tt',
550
+ shipping: 'ts',
551
+ coupon: 'tcc',
552
+ affiliation: 'ta',
553
+ step: 'cos',
554
+ option: 'col',
555
+ };
556
+ var coveoCommerceExtensionKeys = [
557
+ 'loyaltyCardId',
558
+ 'loyaltyTier',
559
+ 'thirdPartyPersona',
560
+ 'companyName',
561
+ 'favoriteStore',
562
+ 'storeName',
563
+ 'userIndustry',
564
+ 'userRole',
565
+ 'userDepartment',
566
+ 'businessUnit',
567
+ ];
568
+ var quoteActionsKeysMapping = {
569
+ id: 'quoteId',
570
+ affiliation: 'quoteAffiliation',
571
+ };
572
+ var reviewActionsKeysMapping = {
573
+ id: 'reviewId',
574
+ rating: 'reviewRating',
575
+ comment: 'reviewComment',
576
+ };
577
+ var commerceActionKeysMappingPerAction = {
578
+ add: productActionsKeysMapping,
579
+ bookmark_add: productActionsKeysMapping,
580
+ bookmark_remove: productActionsKeysMapping,
581
+ click: productActionsKeysMapping,
582
+ checkout: productActionsKeysMapping,
583
+ checkout_option: productActionsKeysMapping,
584
+ detail: productActionsKeysMapping,
585
+ impression: productActionsKeysMapping,
586
+ remove: productActionsKeysMapping,
587
+ refund: __assign(__assign({}, productActionsKeysMapping), transactionActionsKeysMapping),
588
+ purchase: __assign(__assign({}, productActionsKeysMapping), transactionActionsKeysMapping),
589
+ quickview: productActionsKeysMapping,
590
+ quote: __assign(__assign({}, productActionsKeysMapping), quoteActionsKeysMapping),
591
+ review: __assign(__assign({}, productActionsKeysMapping), reviewActionsKeysMapping),
592
+ };
593
+ var convertProductToMeasurementProtocol = function (product, index) {
594
+ return keysOf(product).reduce(function (mappedProduct, key) {
595
+ var _a;
596
+ var newKey = "pr" + (index + 1) + (productKeysMapping[key] || key);
597
+ return __assign(__assign({}, mappedProduct), (_a = {}, _a[newKey] = product[key], _a));
598
+ }, {});
599
+ };
600
+ var convertImpressionListToMeasurementProtocol = function (impressionList, listIndex, prefix) {
601
+ var payload = impressionList.impressions.reduce(function (mappedImpressions, impression, productIndex) {
602
+ return __assign(__assign({}, mappedImpressions), convertImpressionToMeasurementProtocol(impression, listIndex, productIndex, prefix));
603
+ }, {});
604
+ if (impressionList.listName) {
605
+ var listNameKey = "il" + (listIndex + 1) + "nm";
606
+ payload[listNameKey] = impressionList.listName;
607
+ }
608
+ return payload;
609
+ };
610
+ var convertImpressionToMeasurementProtocol = function (impression, listIndex, productIndex, prefix) {
611
+ return keysOf(impression).reduce(function (mappedImpression, key) {
612
+ var _a;
613
+ var newKey = "il" + (listIndex + 1) + prefix + (productIndex + 1) + (impressionKeysMapping[key] || key);
614
+ return __assign(__assign({}, mappedImpression), (_a = {}, _a[newKey] = impression[key], _a));
615
+ }, {});
616
+ };
617
+ var productKeysMappingValues = keysOf(productKeysMapping).map(function (key) { return productKeysMapping[key]; });
618
+ var impressionKeysMappingValues = keysOf(impressionKeysMapping).map(function (key) { return impressionKeysMapping[key]; });
619
+ var productActionsKeysMappingValues = keysOf(productActionsKeysMapping).map(function (key) { return productActionsKeysMapping[key]; });
620
+ var transactionActionsKeysMappingValues = keysOf(transactionActionsKeysMapping).map(function (key) { return transactionActionsKeysMapping[key]; });
621
+ var reviewKeysMappingValues = keysOf(reviewActionsKeysMapping).map(function (key) { return reviewActionsKeysMapping[key]; });
622
+ var quoteKeysMappingValues = keysOf(quoteActionsKeysMapping).map(function (key) { return quoteActionsKeysMapping[key]; });
623
+ var productSubKeysMatchGroup = __spreadArrays(productKeysMappingValues, ['custom']).join('|');
624
+ var impressionSubKeysMatchGroup = __spreadArrays(impressionKeysMappingValues, ['custom']).join('|');
625
+ var productPrefixMatchGroup = '(pr[0-9]+)';
626
+ var impressionPrefixMatchGroup = '(il[0-9]+pi[0-9]+)';
627
+ var productKeyRegex = new RegExp("^" + productPrefixMatchGroup + "(" + productSubKeysMatchGroup + ")$");
628
+ var impressionKeyRegex = new RegExp("^(" + impressionPrefixMatchGroup + "(" + impressionSubKeysMatchGroup + "))|(il[0-9]+nm)$");
629
+ var productActionsKeyRegex = new RegExp("^(" + productActionsKeysMappingValues.join('|') + ")$");
630
+ var transactionActionsKeyRegex = new RegExp("^(" + transactionActionsKeysMappingValues.join('|') + ")$");
631
+ var customProductKeyRegex = new RegExp("^" + productPrefixMatchGroup + "custom$");
632
+ var customImpressionKeyRegex = new RegExp("^" + impressionPrefixMatchGroup + "custom$");
633
+ var coveoCommerceExtensionKeysRegex = new RegExp("^(" + __spreadArrays(coveoCommerceExtensionKeys, reviewKeysMappingValues, quoteKeysMappingValues).join('|') + ")$");
634
+ var isProductKey = function (key) { return productKeyRegex.test(key); };
635
+ var isImpressionKey = function (key) { return impressionKeyRegex.test(key); };
636
+ var isProductActionsKey = function (key) { return productActionsKeyRegex.test(key); };
637
+ var isTransactionActionsKeyRegex = function (key) { return transactionActionsKeyRegex.test(key); };
638
+ var isCoveoCommerceExtensionKey = function (key) { return coveoCommerceExtensionKeysRegex.test(key); };
639
+ var isCommerceKey = [
640
+ isImpressionKey,
641
+ isProductKey,
642
+ isProductActionsKey,
643
+ isTransactionActionsKeyRegex,
644
+ isCoveoCommerceExtensionKey,
645
+ ];
646
+ var isCustomCommerceKey = [customProductKeyRegex, customImpressionKeyRegex];
647
+
648
+ var globalParamKeysMapping = {
649
+ anonymizeIp: 'aip',
650
+ };
651
+ var eventKeysMapping = {
652
+ eventCategory: 'ec',
653
+ eventAction: 'ea',
654
+ eventLabel: 'el',
655
+ eventValue: 'ev',
656
+ page: 'dp',
657
+ visitorId: 'cid',
658
+ clientId: 'cid',
659
+ userId: 'uid',
660
+ currencyCode: 'cu',
661
+ };
662
+ var contextInformationMapping = {
663
+ hitType: 't',
664
+ pageViewId: 'pid',
665
+ encoding: 'de',
666
+ location: 'dl',
667
+ referrer: 'dr',
668
+ screenColor: 'sd',
669
+ screenResolution: 'sr',
670
+ title: 'dt',
671
+ userAgent: 'ua',
672
+ language: 'ul',
673
+ eventId: 'z',
674
+ time: 'tm',
675
+ };
676
+ var coveoExtensionsKeys = [
677
+ 'contentId',
678
+ 'contentIdKey',
679
+ 'contentType',
680
+ 'searchHub',
681
+ 'tab',
682
+ 'searchUid',
683
+ 'permanentId',
684
+ 'contentLocale',
685
+ ];
686
+ var baseMeasurementProtocolKeysMapping = __assign(__assign(__assign(__assign({}, globalParamKeysMapping), eventKeysMapping), contextInformationMapping), coveoExtensionsKeys.reduce(function (all, key) {
687
+ var _a;
688
+ return (__assign(__assign({}, all), (_a = {}, _a[key] = key, _a)));
689
+ }, {}));
690
+
691
+ var measurementProtocolKeysMapping = __assign(__assign({}, baseMeasurementProtocolKeysMapping), serviceActionsKeysMapping);
692
+ var convertKeysToMeasurementProtocol = function (params) {
693
+ var keysMappingForAction = (!!params.action && commerceActionKeysMappingPerAction[params.action]) || {};
694
+ return keysOf(params).reduce(function (mappedKeys, key) {
695
+ var _a;
696
+ var newKey = keysMappingForAction[key] || measurementProtocolKeysMapping[key] || key;
697
+ return __assign(__assign({}, mappedKeys), (_a = {}, _a[newKey] = params[key], _a));
698
+ }, {});
699
+ };
700
+ var measurementProtocolKeysMappingValues = keysOf(measurementProtocolKeysMapping).map(function (key) { return measurementProtocolKeysMapping[key]; });
701
+ var isKnownMeasurementProtocolKey = function (key) { return measurementProtocolKeysMappingValues.indexOf(key) !== -1; };
702
+ var isCustomKey = function (key) { return key === 'custom'; };
703
+ var isMeasurementProtocolKey = function (key) {
704
+ return __spreadArrays(isCommerceKey, isServiceKey, [isKnownMeasurementProtocolKey, isCustomKey]).some(function (test) { return test(key); });
705
+ };
706
+ var convertCustomMeasurementProtocolKeys = function (data) {
707
+ return keysOf(data).reduce(function (all, current) {
708
+ var _a;
709
+ var match = getFirstCustomMeasurementProtocolKeyMatch(current);
710
+ if (match) {
711
+ return __assign(__assign({}, all), convertCustomObject(match, data[current]));
712
+ }
713
+ else {
714
+ return __assign(__assign({}, all), (_a = {}, _a[current] = data[current], _a));
715
+ }
716
+ }, {});
717
+ };
718
+ var getFirstCustomMeasurementProtocolKeyMatch = function (key) {
719
+ var matchedKey = undefined;
720
+ __spreadArrays(isCustomCommerceKey).every(function (regex) {
721
+ var _a;
722
+ matchedKey = (_a = regex.exec(key)) === null || _a === void 0 ? void 0 : _a[1];
723
+ return !Boolean(matchedKey);
724
+ });
725
+ return matchedKey;
726
+ };
727
+ var convertCustomObject = function (prefix, customData) {
728
+ return keysOf(customData).reduce(function (allCustom, currentCustomKey) {
729
+ var _a;
730
+ return (__assign(__assign({}, allCustom), (_a = {}, _a["" + prefix + currentCustomKey] = customData[currentCustomKey], _a)));
731
+ }, {});
732
+ };
733
+
734
+ var AnalyticsBeaconClient = (function () {
735
+ function AnalyticsBeaconClient(opts) {
736
+ this.opts = opts;
737
+ }
738
+ AnalyticsBeaconClient.prototype.sendEvent = function (eventType, payload) {
739
+ return __awaiter(this, void 0, void 0, function () {
740
+ var _a, baseUrl, preprocessRequest, parsedRequestData, paramsFragments, defaultOptions, _b, url, body, _c, _d;
741
+ return __generator(this, function (_e) {
742
+ switch (_e.label) {
743
+ case 0:
744
+ if (!navigator.sendBeacon) {
745
+ throw new Error("navigator.sendBeacon is not supported in this browser. Consider adding a polyfill like \"sendbeacon-polyfill\".");
746
+ }
747
+ _a = this.opts, baseUrl = _a.baseUrl, preprocessRequest = _a.preprocessRequest;
748
+ parsedRequestData = this.encodeForEventType(eventType, payload);
749
+ return [4, this.getQueryParamsForEventType(eventType)];
750
+ case 1:
751
+ paramsFragments = _e.sent();
752
+ defaultOptions = {
753
+ url: baseUrl + "/analytics/" + eventType + "?" + paramsFragments,
754
+ body: new Blob([parsedRequestData], {
755
+ type: 'application/x-www-form-urlencoded',
756
+ }),
757
+ };
758
+ _c = [__assign({}, defaultOptions)];
759
+ if (!preprocessRequest) return [3, 3];
760
+ return [4, preprocessRequest(defaultOptions, 'analyticsBeacon')];
761
+ case 2:
762
+ _d = _e.sent();
763
+ return [3, 4];
764
+ case 3:
765
+ _d = {};
766
+ _e.label = 4;
767
+ case 4:
768
+ _b = __assign.apply(void 0, _c.concat([(_d)])), url = _b.url, body = _b.body;
769
+ console.log("Sending beacon for \"" + eventType + "\" with: ", JSON.stringify(payload));
770
+ navigator.sendBeacon(url, body);
771
+ return [2];
772
+ }
773
+ });
774
+ });
775
+ };
776
+ AnalyticsBeaconClient.prototype.deleteHttpCookieVisitorId = function () {
777
+ return Promise.resolve();
778
+ };
779
+ AnalyticsBeaconClient.prototype.encodeForEventType = function (eventType, payload) {
780
+ return this.isEventTypeLegacy(eventType)
781
+ ? this.encodeForLegacyType(eventType, payload)
782
+ : this.encodeForFormUrlEncoded(__assign({ access_token: this.opts.token }, payload));
783
+ };
784
+ AnalyticsBeaconClient.prototype.getQueryParamsForEventType = function (eventType) {
785
+ return __awaiter(this, void 0, void 0, function () {
786
+ var _a, token, visitorIdProvider, visitorId;
787
+ return __generator(this, function (_b) {
788
+ switch (_b.label) {
789
+ case 0:
790
+ _a = this.opts, token = _a.token, visitorIdProvider = _a.visitorIdProvider;
791
+ return [4, visitorIdProvider.getCurrentVisitorId()];
792
+ case 1:
793
+ visitorId = _b.sent();
794
+ return [2, [
795
+ token && this.isEventTypeLegacy(eventType) ? "access_token=" + token : '',
796
+ visitorId ? "visitorId=" + visitorId : '',
797
+ 'discardVisitInfo=true',
798
+ ]
799
+ .filter(function (p) { return !!p; })
800
+ .join('&')];
801
+ }
802
+ });
803
+ });
804
+ };
805
+ AnalyticsBeaconClient.prototype.isEventTypeLegacy = function (eventType) {
806
+ return [EventType.click, EventType.custom, EventType.search, EventType.view].indexOf(eventType) !== -1;
807
+ };
808
+ AnalyticsBeaconClient.prototype.encodeForLegacyType = function (eventType, payload) {
809
+ return eventType + "Event=" + encodeURIComponent(JSON.stringify(payload));
810
+ };
811
+ AnalyticsBeaconClient.prototype.encodeForFormUrlEncoded = function (payload) {
812
+ var _this = this;
813
+ return Object.keys(payload)
814
+ .filter(function (key) { return !!payload[key]; })
815
+ .map(function (key) { return encodeURIComponent(key) + "=" + encodeURIComponent(_this.encodeValue(payload[key])); })
816
+ .join('&');
817
+ };
818
+ AnalyticsBeaconClient.prototype.encodeValue = function (value) {
819
+ return typeof value === 'number' || typeof value === 'string' || typeof value === 'boolean'
820
+ ? value
821
+ : JSON.stringify(value);
822
+ };
823
+ return AnalyticsBeaconClient;
824
+ }());
825
+
826
+ var NoopAnalyticsClient = (function () {
827
+ function NoopAnalyticsClient() {
828
+ }
829
+ NoopAnalyticsClient.prototype.sendEvent = function (_, __) {
830
+ return __awaiter(this, void 0, void 0, function () {
831
+ return __generator(this, function (_a) {
832
+ return [2, Promise.resolve()];
833
+ });
834
+ });
835
+ };
836
+ NoopAnalyticsClient.prototype.deleteHttpCookieVisitorId = function () {
837
+ return __awaiter(this, void 0, void 0, function () {
838
+ return __generator(this, function (_a) {
839
+ return [2, Promise.resolve()];
840
+ });
841
+ });
842
+ };
843
+ return NoopAnalyticsClient;
844
+ }());
845
+
846
+ var fetch$2 = window.fetch;
847
+
848
+ var AnalyticsFetchClient = (function () {
849
+ function AnalyticsFetchClient(opts) {
850
+ this.opts = opts;
851
+ }
852
+ AnalyticsFetchClient.prototype.sendEvent = function (eventType, payload) {
853
+ return __awaiter(this, void 0, void 0, function () {
854
+ var _a, baseUrl, visitorIdProvider, preprocessRequest, visitorIdParam, _b, defaultOptions, _c, url, fetchData, _d, _e, response, visit;
855
+ return __generator(this, function (_f) {
856
+ switch (_f.label) {
857
+ case 0:
858
+ _a = this.opts, baseUrl = _a.baseUrl, visitorIdProvider = _a.visitorIdProvider, preprocessRequest = _a.preprocessRequest;
859
+ if (!this.shouldAppendVisitorId(eventType)) return [3, 2];
860
+ return [4, this.getVisitorIdParam()];
861
+ case 1:
862
+ _b = _f.sent();
863
+ return [3, 3];
864
+ case 2:
865
+ _b = '';
866
+ _f.label = 3;
867
+ case 3:
868
+ visitorIdParam = _b;
869
+ defaultOptions = {
870
+ url: baseUrl + "/analytics/" + eventType + visitorIdParam,
871
+ credentials: 'include',
872
+ mode: 'cors',
873
+ headers: this.getHeaders(),
874
+ method: 'POST',
875
+ body: JSON.stringify(payload),
876
+ };
877
+ _d = [__assign({}, defaultOptions)];
878
+ if (!preprocessRequest) return [3, 5];
879
+ return [4, preprocessRequest(defaultOptions, 'analyticsFetch')];
880
+ case 4:
881
+ _e = _f.sent();
882
+ return [3, 6];
883
+ case 5:
884
+ _e = {};
885
+ _f.label = 6;
886
+ case 6:
887
+ _c = __assign.apply(void 0, _d.concat([(_e)])), url = _c.url, fetchData = __rest(_c, ["url"]);
888
+ return [4, fetch$2(url, fetchData)];
889
+ case 7:
890
+ response = _f.sent();
891
+ if (!response.ok) return [3, 9];
892
+ return [4, response.json()];
893
+ case 8:
894
+ visit = (_f.sent());
895
+ if (visit.visitorId) {
896
+ visitorIdProvider.setCurrentVisitorId(visit.visitorId);
897
+ }
898
+ return [2, visit];
899
+ case 9:
900
+ try {
901
+ response.json();
902
+ }
903
+ catch (_g) {
904
+ }
905
+ console.error("An error has occured when sending the \"" + eventType + "\" event.", response, payload);
906
+ throw new Error("An error has occurred when sending the \"" + eventType + "\" event. Check the console logs for more details.");
907
+ }
908
+ });
909
+ });
910
+ };
911
+ AnalyticsFetchClient.prototype.deleteHttpCookieVisitorId = function () {
912
+ return __awaiter(this, void 0, void 0, function () {
913
+ var baseUrl, url;
914
+ return __generator(this, function (_a) {
915
+ switch (_a.label) {
916
+ case 0:
917
+ baseUrl = this.opts.baseUrl;
918
+ url = baseUrl + "/analytics/visit";
919
+ return [4, fetch$2(url, { headers: this.getHeaders(), method: 'DELETE' })];
920
+ case 1:
921
+ _a.sent();
922
+ return [2];
923
+ }
924
+ });
925
+ });
926
+ };
927
+ AnalyticsFetchClient.prototype.shouldAppendVisitorId = function (eventType) {
928
+ return [EventType.click, EventType.custom, EventType.search, EventType.view].indexOf(eventType) !== -1;
929
+ };
930
+ AnalyticsFetchClient.prototype.getVisitorIdParam = function () {
931
+ return __awaiter(this, void 0, void 0, function () {
932
+ var visitorIdProvider, visitorId;
933
+ return __generator(this, function (_a) {
934
+ switch (_a.label) {
935
+ case 0:
936
+ visitorIdProvider = this.opts.visitorIdProvider;
937
+ return [4, visitorIdProvider.getCurrentVisitorId()];
938
+ case 1:
939
+ visitorId = _a.sent();
940
+ return [2, visitorId ? "?visitor=" + visitorId : ''];
941
+ }
942
+ });
943
+ });
944
+ };
945
+ AnalyticsFetchClient.prototype.getHeaders = function () {
946
+ var token = this.opts.token;
947
+ return __assign(__assign({}, (token ? { Authorization: "Bearer " + token } : {})), { 'Content-Type': "application/json" });
948
+ };
949
+ return AnalyticsFetchClient;
950
+ }());
951
+
952
+ var BrowserRuntime = (function () {
953
+ function BrowserRuntime(clientOptions, getUnprocessedRequests) {
954
+ var _this = this;
955
+ if (hasLocalStorage() && hasCookieStorage()) {
956
+ this.storage = new CookieAndLocalStorage();
957
+ }
958
+ else if (hasLocalStorage()) {
959
+ this.storage = localStorage;
960
+ }
961
+ else {
962
+ console.warn('BrowserRuntime detected no valid storage available.', this);
963
+ this.storage = new NullStorage();
964
+ }
965
+ this.client = new AnalyticsFetchClient(clientOptions);
966
+ this.beaconClient = new AnalyticsBeaconClient(clientOptions);
967
+ window.addEventListener('beforeunload', function () {
968
+ var requests = getUnprocessedRequests();
969
+ for (var _i = 0, requests_1 = requests; _i < requests_1.length; _i++) {
970
+ var _a = requests_1[_i], eventType = _a.eventType, payload = _a.payload;
971
+ _this.beaconClient.sendEvent(eventType, payload);
972
+ }
973
+ });
974
+ }
975
+ return BrowserRuntime;
976
+ }());
977
+ var NodeJSRuntime = (function () {
978
+ function NodeJSRuntime(clientOptions, storage) {
979
+ this.storage = storage || new NullStorage();
980
+ this.client = new AnalyticsFetchClient(clientOptions);
981
+ }
982
+ return NodeJSRuntime;
983
+ }());
984
+ var NoopRuntime = (function () {
985
+ function NoopRuntime() {
986
+ this.storage = new NullStorage();
987
+ this.client = new NoopAnalyticsClient();
988
+ }
989
+ return NoopRuntime;
990
+ }());
991
+
992
+ var API_KEY_PREFIX = 'xx';
993
+ var isApiKey = function (token) { return (token === null || token === void 0 ? void 0 : token.startsWith(API_KEY_PREFIX)) || false; };
994
+
995
+ var ReactNativeRuntimeWarning = "\n We've detected you're using React Native but have not provided the corresponding runtime, \n for an optimal experience please use the \"coveo.analytics/react-native\" subpackage.\n Follow the Readme on how to set it up: https://github.com/coveo/coveo.analytics.js#using-react-native\n ";
996
+ function isReactNative() {
997
+ return typeof navigator != 'undefined' && navigator.product == 'ReactNative';
998
+ }
999
+
1000
+ var doNotTrackValues = ['1', 1, 'yes', true];
1001
+ function doNotTrack() {
1002
+ return (hasNavigator() &&
1003
+ [
1004
+ navigator.globalPrivacyControl,
1005
+ navigator.doNotTrack,
1006
+ navigator.msDoNotTrack,
1007
+ window.doNotTrack,
1008
+ ].some(function (value) { return doNotTrackValues.indexOf(value) !== -1; }));
1009
+ }
1010
+
1011
+ var donottrack = /*#__PURE__*/Object.freeze({
1012
+ __proto__: null,
1013
+ doNotTrack: doNotTrack,
1014
+ 'default': doNotTrack
1015
+ });
1016
+
1017
+ var Version = 'v15';
1018
+ var Endpoints = {
1019
+ default: 'https://analytics.cloud.coveo.com/rest/ua',
1020
+ production: 'https://analytics.cloud.coveo.com/rest/ua',
1021
+ hipaa: 'https://analyticshipaa.cloud.coveo.com/rest/ua',
1022
+ };
1023
+ function buildBaseUrl(endpoint, apiVersion) {
1024
+ if (endpoint === void 0) { endpoint = Endpoints.default; }
1025
+ if (apiVersion === void 0) { apiVersion = Version; }
1026
+ var endpointIsCoveoProxy = endpoint.indexOf('.cloud.coveo.com') !== -1;
1027
+ return "" + endpoint + (endpointIsCoveoProxy ? '' : '/rest') + "/" + apiVersion;
1028
+ }
1029
+ var CoveoAnalyticsClient = (function () {
1030
+ function CoveoAnalyticsClient(opts) {
1031
+ if (!opts) {
1032
+ throw new Error('You have to pass options to this constructor');
1033
+ }
1034
+ this.options = __assign(__assign({}, this.defaultOptions), opts);
1035
+ this.visitorId = '';
1036
+ this.bufferedRequests = [];
1037
+ this.beforeSendHooks = [enhanceViewEvent, addDefaultValues].concat(this.options.beforeSendHooks);
1038
+ this.afterSendHooks = this.options.afterSendHooks;
1039
+ this.eventTypeMapping = {};
1040
+ var clientsOptions = {
1041
+ baseUrl: this.baseUrl,
1042
+ token: this.options.token,
1043
+ visitorIdProvider: this,
1044
+ preprocessRequest: this.options.preprocessRequest,
1045
+ };
1046
+ this.runtime = this.options.runtimeEnvironment || this.initRuntime(clientsOptions);
1047
+ if (doNotTrack()) {
1048
+ this.clear();
1049
+ this.runtime.storage = new NullStorage();
1050
+ }
1051
+ }
1052
+ Object.defineProperty(CoveoAnalyticsClient.prototype, "defaultOptions", {
1053
+ get: function () {
1054
+ return {
1055
+ endpoint: Endpoints.default,
1056
+ token: '',
1057
+ version: Version,
1058
+ beforeSendHooks: [],
1059
+ afterSendHooks: [],
1060
+ };
1061
+ },
1062
+ enumerable: false,
1063
+ configurable: true
1064
+ });
1065
+ CoveoAnalyticsClient.prototype.initRuntime = function (clientsOptions) {
1066
+ var _this = this;
1067
+ if (hasWindow() && hasDocument()) {
1068
+ return new BrowserRuntime(clientsOptions, function () {
1069
+ var copy = __spreadArrays(_this.bufferedRequests);
1070
+ _this.bufferedRequests = [];
1071
+ return copy;
1072
+ });
1073
+ }
1074
+ else if (isReactNative()) {
1075
+ console.warn(ReactNativeRuntimeWarning);
1076
+ }
1077
+ return new NodeJSRuntime(clientsOptions);
1078
+ };
1079
+ Object.defineProperty(CoveoAnalyticsClient.prototype, "storage", {
1080
+ get: function () {
1081
+ return this.runtime.storage;
1082
+ },
1083
+ enumerable: false,
1084
+ configurable: true
1085
+ });
1086
+ CoveoAnalyticsClient.prototype.determineVisitorId = function () {
1087
+ return __awaiter(this, void 0, void 0, function () {
1088
+ var err_1;
1089
+ return __generator(this, function (_a) {
1090
+ switch (_a.label) {
1091
+ case 0:
1092
+ _a.trys.push([0, 2, , 3]);
1093
+ return [4, this.storage.getItem('visitorId')];
1094
+ case 1: return [2, (_a.sent()) || uuidv4()];
1095
+ case 2:
1096
+ err_1 = _a.sent();
1097
+ console.log('Could not get visitor ID from the current runtime environment storage. Using a random ID instead.', err_1);
1098
+ return [2, uuidv4()];
1099
+ case 3: return [2];
1100
+ }
1101
+ });
1102
+ });
1103
+ };
1104
+ CoveoAnalyticsClient.prototype.getCurrentVisitorId = function () {
1105
+ return __awaiter(this, void 0, void 0, function () {
1106
+ var id;
1107
+ return __generator(this, function (_a) {
1108
+ switch (_a.label) {
1109
+ case 0:
1110
+ if (!!this.visitorId) return [3, 3];
1111
+ return [4, this.determineVisitorId()];
1112
+ case 1:
1113
+ id = _a.sent();
1114
+ return [4, this.setCurrentVisitorId(id)];
1115
+ case 2:
1116
+ _a.sent();
1117
+ _a.label = 3;
1118
+ case 3: return [2, this.visitorId];
1119
+ }
1120
+ });
1121
+ });
1122
+ };
1123
+ CoveoAnalyticsClient.prototype.setCurrentVisitorId = function (visitorId) {
1124
+ return __awaiter(this, void 0, void 0, function () {
1125
+ return __generator(this, function (_a) {
1126
+ switch (_a.label) {
1127
+ case 0:
1128
+ this.visitorId = visitorId;
1129
+ return [4, this.storage.setItem('visitorId', visitorId)];
1130
+ case 1:
1131
+ _a.sent();
1132
+ return [2];
1133
+ }
1134
+ });
1135
+ });
1136
+ };
1137
+ CoveoAnalyticsClient.prototype.getParameters = function (eventType) {
1138
+ var payload = [];
1139
+ for (var _i = 1; _i < arguments.length; _i++) {
1140
+ payload[_i - 1] = arguments[_i];
1141
+ }
1142
+ return __awaiter(this, void 0, void 0, function () {
1143
+ return __generator(this, function (_a) {
1144
+ switch (_a.label) {
1145
+ case 0: return [4, this.resolveParameters.apply(this, __spreadArrays([eventType], payload))];
1146
+ case 1: return [2, _a.sent()];
1147
+ }
1148
+ });
1149
+ });
1150
+ };
1151
+ CoveoAnalyticsClient.prototype.getPayload = function (eventType) {
1152
+ var payload = [];
1153
+ for (var _i = 1; _i < arguments.length; _i++) {
1154
+ payload[_i - 1] = arguments[_i];
1155
+ }
1156
+ return __awaiter(this, void 0, void 0, function () {
1157
+ var parametersToSend;
1158
+ return __generator(this, function (_a) {
1159
+ switch (_a.label) {
1160
+ case 0: return [4, this.resolveParameters.apply(this, __spreadArrays([eventType], payload))];
1161
+ case 1:
1162
+ parametersToSend = _a.sent();
1163
+ return [4, this.resolvePayloadForParameters(eventType, parametersToSend)];
1164
+ case 2: return [2, _a.sent()];
1165
+ }
1166
+ });
1167
+ });
1168
+ };
1169
+ Object.defineProperty(CoveoAnalyticsClient.prototype, "currentVisitorId", {
1170
+ get: function () {
1171
+ var visitorId = this.visitorId || this.storage.getItem('visitorId');
1172
+ if (typeof visitorId !== 'string') {
1173
+ this.setCurrentVisitorId(uuidv4());
1174
+ }
1175
+ return this.visitorId;
1176
+ },
1177
+ set: function (visitorId) {
1178
+ this.visitorId = visitorId;
1179
+ this.storage.setItem('visitorId', visitorId);
1180
+ },
1181
+ enumerable: false,
1182
+ configurable: true
1183
+ });
1184
+ CoveoAnalyticsClient.prototype.resolveParameters = function (eventType) {
1185
+ var payload = [];
1186
+ for (var _i = 1; _i < arguments.length; _i++) {
1187
+ payload[_i - 1] = arguments[_i];
1188
+ }
1189
+ return __awaiter(this, void 0, void 0, function () {
1190
+ var _a, _b, variableLengthArgumentsNames, _c, addVisitorIdParameter, _d, usesMeasurementProtocol, _e, addClientIdParameter, processVariableArgumentNamesStep, addVisitorIdStep, addClientIdStep, setAnonymousUserStep, processBeforeSendHooksStep, parametersToSend;
1191
+ var _this = this;
1192
+ return __generator(this, function (_f) {
1193
+ switch (_f.label) {
1194
+ case 0:
1195
+ _a = this.eventTypeMapping[eventType] || {}, _b = _a.variableLengthArgumentsNames, variableLengthArgumentsNames = _b === void 0 ? [] : _b, _c = _a.addVisitorIdParameter, addVisitorIdParameter = _c === void 0 ? false : _c, _d = _a.usesMeasurementProtocol, usesMeasurementProtocol = _d === void 0 ? false : _d, _e = _a.addClientIdParameter, addClientIdParameter = _e === void 0 ? false : _e;
1196
+ processVariableArgumentNamesStep = function (currentPayload) {
1197
+ return variableLengthArgumentsNames.length > 0
1198
+ ? _this.parseVariableArgumentsPayload(variableLengthArgumentsNames, currentPayload)
1199
+ : currentPayload[0];
1200
+ };
1201
+ addVisitorIdStep = function (currentPayload) { return __awaiter(_this, void 0, void 0, function () {
1202
+ var _a, _b, _c;
1203
+ return __generator(this, function (_d) {
1204
+ switch (_d.label) {
1205
+ case 0:
1206
+ _a = [__assign({}, currentPayload)];
1207
+ _b = {};
1208
+ if (!addVisitorIdParameter) return [3, 2];
1209
+ return [4, this.getCurrentVisitorId()];
1210
+ case 1:
1211
+ _c = _d.sent();
1212
+ return [3, 3];
1213
+ case 2:
1214
+ _c = '';
1215
+ _d.label = 3;
1216
+ case 3: return [2, (__assign.apply(void 0, _a.concat([(_b.visitorId = _c, _b)])))];
1217
+ }
1218
+ });
1219
+ }); };
1220
+ addClientIdStep = function (currentPayload) { return __awaiter(_this, void 0, void 0, function () {
1221
+ var _a, _b;
1222
+ return __generator(this, function (_c) {
1223
+ switch (_c.label) {
1224
+ case 0:
1225
+ if (!addClientIdParameter) return [3, 2];
1226
+ _a = [__assign({}, currentPayload)];
1227
+ _b = {};
1228
+ return [4, this.getCurrentVisitorId()];
1229
+ case 1: return [2, __assign.apply(void 0, _a.concat([(_b.clientId = _c.sent(), _b)]))];
1230
+ case 2: return [2, currentPayload];
1231
+ }
1232
+ });
1233
+ }); };
1234
+ setAnonymousUserStep = function (currentPayload) {
1235
+ return usesMeasurementProtocol ? _this.ensureAnonymousUserWhenUsingApiKey(currentPayload) : currentPayload;
1236
+ };
1237
+ processBeforeSendHooksStep = function (currentPayload) {
1238
+ return _this.beforeSendHooks.reduce(function (promisePayload, current) { return __awaiter(_this, void 0, void 0, function () {
1239
+ var payload;
1240
+ return __generator(this, function (_a) {
1241
+ switch (_a.label) {
1242
+ case 0: return [4, promisePayload];
1243
+ case 1:
1244
+ payload = _a.sent();
1245
+ return [4, current(eventType, payload)];
1246
+ case 2: return [2, _a.sent()];
1247
+ }
1248
+ });
1249
+ }); }, currentPayload);
1250
+ };
1251
+ return [4, [
1252
+ processVariableArgumentNamesStep,
1253
+ addVisitorIdStep,
1254
+ addClientIdStep,
1255
+ setAnonymousUserStep,
1256
+ processBeforeSendHooksStep,
1257
+ ].reduce(function (payloadPromise, step) { return __awaiter(_this, void 0, void 0, function () {
1258
+ var payload;
1259
+ return __generator(this, function (_a) {
1260
+ switch (_a.label) {
1261
+ case 0: return [4, payloadPromise];
1262
+ case 1:
1263
+ payload = _a.sent();
1264
+ return [4, step(payload)];
1265
+ case 2: return [2, _a.sent()];
1266
+ }
1267
+ });
1268
+ }); }, Promise.resolve(payload))];
1269
+ case 1:
1270
+ parametersToSend = _f.sent();
1271
+ return [2, parametersToSend];
1272
+ }
1273
+ });
1274
+ });
1275
+ };
1276
+ CoveoAnalyticsClient.prototype.resolvePayloadForParameters = function (eventType, parameters) {
1277
+ return __awaiter(this, void 0, void 0, function () {
1278
+ var _a, usesMeasurementProtocol, cleanPayloadStep, validateParams, processMeasurementProtocolConversionStep, removeUnknownParameters, processCustomParameters, payloadToSend;
1279
+ var _this = this;
1280
+ return __generator(this, function (_b) {
1281
+ switch (_b.label) {
1282
+ case 0:
1283
+ _a = (this.eventTypeMapping[eventType] || {}).usesMeasurementProtocol, usesMeasurementProtocol = _a === void 0 ? false : _a;
1284
+ cleanPayloadStep = function (currentPayload) {
1285
+ return _this.removeEmptyPayloadValues(currentPayload, eventType);
1286
+ };
1287
+ validateParams = function (currentPayload) { return _this.validateParams(currentPayload); };
1288
+ processMeasurementProtocolConversionStep = function (currentPayload) {
1289
+ return usesMeasurementProtocol ? convertKeysToMeasurementProtocol(currentPayload) : currentPayload;
1290
+ };
1291
+ removeUnknownParameters = function (currentPayload) {
1292
+ return usesMeasurementProtocol ? _this.removeUnknownParameters(currentPayload) : currentPayload;
1293
+ };
1294
+ processCustomParameters = function (currentPayload) {
1295
+ return usesMeasurementProtocol ? _this.processCustomParameters(currentPayload) : currentPayload;
1296
+ };
1297
+ return [4, [
1298
+ cleanPayloadStep,
1299
+ validateParams,
1300
+ processMeasurementProtocolConversionStep,
1301
+ removeUnknownParameters,
1302
+ processCustomParameters,
1303
+ ].reduce(function (payloadPromise, step) { return __awaiter(_this, void 0, void 0, function () {
1304
+ var payload;
1305
+ return __generator(this, function (_a) {
1306
+ switch (_a.label) {
1307
+ case 0: return [4, payloadPromise];
1308
+ case 1:
1309
+ payload = _a.sent();
1310
+ return [4, step(payload)];
1311
+ case 2: return [2, _a.sent()];
1312
+ }
1313
+ });
1314
+ }); }, Promise.resolve(parameters))];
1315
+ case 1:
1316
+ payloadToSend = _b.sent();
1317
+ return [2, payloadToSend];
1318
+ }
1319
+ });
1320
+ });
1321
+ };
1322
+ CoveoAnalyticsClient.prototype.sendEvent = function (eventType) {
1323
+ var payload = [];
1324
+ for (var _i = 1; _i < arguments.length; _i++) {
1325
+ payload[_i - 1] = arguments[_i];
1326
+ }
1327
+ return __awaiter(this, void 0, void 0, function () {
1328
+ var _a, eventTypeToSend, parametersToSend, payloadToSend;
1329
+ return __generator(this, function (_b) {
1330
+ switch (_b.label) {
1331
+ case 0:
1332
+ _a = (this.eventTypeMapping[eventType] || {}).newEventType, eventTypeToSend = _a === void 0 ? eventType : _a;
1333
+ return [4, this.resolveParameters.apply(this, __spreadArrays([eventType], payload))];
1334
+ case 1:
1335
+ parametersToSend = _b.sent();
1336
+ return [4, this.resolvePayloadForParameters(eventType, parametersToSend)];
1337
+ case 2:
1338
+ payloadToSend = _b.sent();
1339
+ this.bufferedRequests.push({
1340
+ eventType: eventTypeToSend,
1341
+ payload: payloadToSend,
1342
+ });
1343
+ return [4, Promise.all(this.afterSendHooks.map(function (hook) { return hook(eventType, parametersToSend); }))];
1344
+ case 3:
1345
+ _b.sent();
1346
+ return [4, this.deferExecution()];
1347
+ case 4:
1348
+ _b.sent();
1349
+ return [4, this.sendFromBufferWithFetch()];
1350
+ case 5: return [2, _b.sent()];
1351
+ }
1352
+ });
1353
+ });
1354
+ };
1355
+ CoveoAnalyticsClient.prototype.deferExecution = function () {
1356
+ return new Promise(function (resolve) { return setTimeout(resolve, 0); });
1357
+ };
1358
+ CoveoAnalyticsClient.prototype.sendFromBufferWithFetch = function () {
1359
+ return __awaiter(this, void 0, void 0, function () {
1360
+ var popped, eventType, payload;
1361
+ return __generator(this, function (_a) {
1362
+ popped = this.bufferedRequests.shift();
1363
+ if (popped) {
1364
+ eventType = popped.eventType, payload = popped.payload;
1365
+ return [2, this.runtime.client.sendEvent(eventType, payload)];
1366
+ }
1367
+ return [2];
1368
+ });
1369
+ });
1370
+ };
1371
+ CoveoAnalyticsClient.prototype.clear = function () {
1372
+ this.storage.removeItem('visitorId');
1373
+ var store = new HistoryStore();
1374
+ store.clear();
1375
+ };
1376
+ CoveoAnalyticsClient.prototype.deleteHttpOnlyVisitorId = function () {
1377
+ this.runtime.client.deleteHttpCookieVisitorId();
1378
+ };
1379
+ CoveoAnalyticsClient.prototype.sendSearchEvent = function (request) {
1380
+ return __awaiter(this, void 0, void 0, function () {
1381
+ return __generator(this, function (_a) {
1382
+ return [2, this.sendEvent(EventType.search, request)];
1383
+ });
1384
+ });
1385
+ };
1386
+ CoveoAnalyticsClient.prototype.sendClickEvent = function (request) {
1387
+ return __awaiter(this, void 0, void 0, function () {
1388
+ return __generator(this, function (_a) {
1389
+ return [2, this.sendEvent(EventType.click, request)];
1390
+ });
1391
+ });
1392
+ };
1393
+ CoveoAnalyticsClient.prototype.sendCustomEvent = function (request) {
1394
+ return __awaiter(this, void 0, void 0, function () {
1395
+ return __generator(this, function (_a) {
1396
+ return [2, this.sendEvent(EventType.custom, request)];
1397
+ });
1398
+ });
1399
+ };
1400
+ CoveoAnalyticsClient.prototype.sendViewEvent = function (request) {
1401
+ return __awaiter(this, void 0, void 0, function () {
1402
+ return __generator(this, function (_a) {
1403
+ return [2, this.sendEvent(EventType.view, request)];
1404
+ });
1405
+ });
1406
+ };
1407
+ CoveoAnalyticsClient.prototype.getVisit = function () {
1408
+ return __awaiter(this, void 0, void 0, function () {
1409
+ var response, visit;
1410
+ return __generator(this, function (_a) {
1411
+ switch (_a.label) {
1412
+ case 0: return [4, fetch(this.baseUrl + "/analytics/visit")];
1413
+ case 1:
1414
+ response = _a.sent();
1415
+ return [4, response.json()];
1416
+ case 2:
1417
+ visit = (_a.sent());
1418
+ this.visitorId = visit.visitorId;
1419
+ return [2, visit];
1420
+ }
1421
+ });
1422
+ });
1423
+ };
1424
+ CoveoAnalyticsClient.prototype.getHealth = function () {
1425
+ return __awaiter(this, void 0, void 0, function () {
1426
+ var response;
1427
+ return __generator(this, function (_a) {
1428
+ switch (_a.label) {
1429
+ case 0: return [4, fetch(this.baseUrl + "/analytics/monitoring/health")];
1430
+ case 1:
1431
+ response = _a.sent();
1432
+ return [4, response.json()];
1433
+ case 2: return [2, (_a.sent())];
1434
+ }
1435
+ });
1436
+ });
1437
+ };
1438
+ CoveoAnalyticsClient.prototype.registerBeforeSendEventHook = function (hook) {
1439
+ this.beforeSendHooks.push(hook);
1440
+ };
1441
+ CoveoAnalyticsClient.prototype.registerAfterSendEventHook = function (hook) {
1442
+ this.afterSendHooks.push(hook);
1443
+ };
1444
+ CoveoAnalyticsClient.prototype.addEventTypeMapping = function (eventType, eventConfig) {
1445
+ this.eventTypeMapping[eventType] = eventConfig;
1446
+ };
1447
+ CoveoAnalyticsClient.prototype.parseVariableArgumentsPayload = function (fieldsOrder, payload) {
1448
+ var parsedArguments = {};
1449
+ for (var i = 0, length_1 = payload.length; i < length_1; i++) {
1450
+ var currentArgument = payload[i];
1451
+ if (typeof currentArgument === 'string') {
1452
+ parsedArguments[fieldsOrder[i]] = currentArgument;
1453
+ }
1454
+ else if (typeof currentArgument === 'object') {
1455
+ return __assign(__assign({}, parsedArguments), currentArgument);
1456
+ }
1457
+ }
1458
+ return parsedArguments;
1459
+ };
1460
+ CoveoAnalyticsClient.prototype.isKeyAllowedEmpty = function (evtType, key) {
1461
+ var _a;
1462
+ var keysThatCanBeEmpty = (_a = {},
1463
+ _a[EventType.search] = ['queryText'],
1464
+ _a);
1465
+ var match = keysThatCanBeEmpty[evtType] || [];
1466
+ return match.indexOf(key) !== -1;
1467
+ };
1468
+ CoveoAnalyticsClient.prototype.removeEmptyPayloadValues = function (payload, eventType) {
1469
+ var _this = this;
1470
+ var isNotEmptyValue = function (value) { return typeof value !== 'undefined' && value !== null && value !== ''; };
1471
+ return Object.keys(payload)
1472
+ .filter(function (key) { return _this.isKeyAllowedEmpty(eventType, key) || isNotEmptyValue(payload[key]); })
1473
+ .reduce(function (newPayload, key) {
1474
+ var _a;
1475
+ return (__assign(__assign({}, newPayload), (_a = {}, _a[key] = payload[key], _a)));
1476
+ }, {});
1477
+ };
1478
+ CoveoAnalyticsClient.prototype.removeUnknownParameters = function (payload) {
1479
+ var newPayload = Object.keys(payload)
1480
+ .filter(function (key) {
1481
+ if (isMeasurementProtocolKey(key)) {
1482
+ return true;
1483
+ }
1484
+ else {
1485
+ console.log(key, 'is not processed by coveoua');
1486
+ }
1487
+ })
1488
+ .reduce(function (newPayload, key) {
1489
+ var _a;
1490
+ return (__assign(__assign({}, newPayload), (_a = {}, _a[key] = payload[key], _a)));
1491
+ }, {});
1492
+ return newPayload;
1493
+ };
1494
+ CoveoAnalyticsClient.prototype.processCustomParameters = function (payload) {
1495
+ var custom = payload.custom, rest = __rest(payload, ["custom"]);
1496
+ var lowercasedCustom = this.lowercaseKeys(custom);
1497
+ var newPayload = convertCustomMeasurementProtocolKeys(rest);
1498
+ return __assign(__assign({}, lowercasedCustom), newPayload);
1499
+ };
1500
+ CoveoAnalyticsClient.prototype.lowercaseKeys = function (custom) {
1501
+ var keys = Object.keys(custom || {});
1502
+ return keys.reduce(function (all, key) {
1503
+ var _a;
1504
+ return (__assign(__assign({}, all), (_a = {}, _a[key.toLowerCase()] = custom[key], _a)));
1505
+ }, {});
1506
+ };
1507
+ CoveoAnalyticsClient.prototype.validateParams = function (payload) {
1508
+ var anonymizeIp = payload.anonymizeIp, rest = __rest(payload, ["anonymizeIp"]);
1509
+ if (anonymizeIp !== undefined) {
1510
+ if (['0', 'false', 'undefined', 'null', '{}', '[]', ''].indexOf(("" + anonymizeIp).toLowerCase()) == -1) {
1511
+ rest['anonymizeIp'] = 1;
1512
+ }
1513
+ }
1514
+ return rest;
1515
+ };
1516
+ CoveoAnalyticsClient.prototype.ensureAnonymousUserWhenUsingApiKey = function (payload) {
1517
+ var userId = payload.userId, rest = __rest(payload, ["userId"]);
1518
+ if (isApiKey(this.options.token) && !userId) {
1519
+ rest['userId'] = 'anonymous';
1520
+ return rest;
1521
+ }
1522
+ else {
1523
+ return payload;
1524
+ }
1525
+ };
1526
+ Object.defineProperty(CoveoAnalyticsClient.prototype, "baseUrl", {
1527
+ get: function () {
1528
+ return buildBaseUrl(this.options.endpoint, this.options.version);
1529
+ },
1530
+ enumerable: false,
1531
+ configurable: true
1532
+ });
1533
+ return CoveoAnalyticsClient;
1534
+ }());
1535
+
1536
+ var analytics$1 = /*#__PURE__*/Object.freeze({
1537
+ __proto__: null,
1538
+ Version: Version,
1539
+ Endpoints: Endpoints,
1540
+ buildBaseUrl: buildBaseUrl,
1541
+ CoveoAnalyticsClient: CoveoAnalyticsClient,
1542
+ 'default': CoveoAnalyticsClient
1543
+ });
1544
+
1545
+ var getFormattedLocation = function (location) {
1546
+ return location.protocol + "//" + location.hostname + (location.pathname.indexOf('/') === 0 ? location.pathname : "/" + location.pathname) + location.search;
1547
+ };
1548
+
1549
+ var BasePluginEventTypes = {
1550
+ pageview: 'pageview',
1551
+ event: 'event',
1552
+ };
1553
+ var BasePlugin = (function () {
1554
+ function BasePlugin(_a) {
1555
+ var client = _a.client, _b = _a.uuidGenerator, uuidGenerator = _b === void 0 ? uuidv4 : _b;
1556
+ this.actionData = {};
1557
+ this.client = client;
1558
+ this.uuidGenerator = uuidGenerator;
1559
+ this.pageViewId = uuidGenerator();
1560
+ this.nextPageViewId = this.pageViewId;
1561
+ this.currentLocation = getFormattedLocation(window.location);
1562
+ this.lastReferrer = hasDocument() ? document.referrer : '';
1563
+ this.addHooks();
1564
+ }
1565
+ BasePlugin.prototype.setAction = function (action, options) {
1566
+ this.action = action;
1567
+ this.actionData = options;
1568
+ };
1569
+ BasePlugin.prototype.clearData = function () {
1570
+ this.clearPluginData();
1571
+ this.action = undefined;
1572
+ this.actionData = {};
1573
+ };
1574
+ BasePlugin.prototype.getLocationInformation = function (eventType, payload) {
1575
+ return __assign({ hitType: eventType }, this.getNextValues(eventType, payload));
1576
+ };
1577
+ BasePlugin.prototype.updateLocationInformation = function (eventType, payload) {
1578
+ this.updateLocationForNextPageView(eventType, payload);
1579
+ };
1580
+ BasePlugin.prototype.getDefaultContextInformation = function (eventType) {
1581
+ var documentContext = {
1582
+ title: hasDocument() ? document.title : '',
1583
+ encoding: hasDocument() ? document.characterSet : 'UTF-8',
1584
+ };
1585
+ var screenContext = {
1586
+ screenResolution: screen.width + "x" + screen.height,
1587
+ screenColor: screen.colorDepth + "-bit",
1588
+ };
1589
+ var navigatorContext = {
1590
+ language: navigator.language,
1591
+ userAgent: navigator.userAgent,
1592
+ };
1593
+ var eventContext = {
1594
+ time: Date.now().toString(),
1595
+ eventId: this.uuidGenerator(),
1596
+ };
1597
+ return __assign(__assign(__assign(__assign({}, eventContext), screenContext), navigatorContext), documentContext);
1598
+ };
1599
+ BasePlugin.prototype.updateLocationForNextPageView = function (eventType, payload) {
1600
+ var _a = this.getNextValues(eventType, payload), pageViewId = _a.pageViewId, referrer = _a.referrer, location = _a.location;
1601
+ this.lastReferrer = referrer;
1602
+ this.pageViewId = pageViewId;
1603
+ this.currentLocation = location;
1604
+ if (eventType === BasePluginEventTypes.pageview) {
1605
+ this.nextPageViewId = this.uuidGenerator();
1606
+ this.hasSentFirstPageView = true;
1607
+ }
1608
+ };
1609
+ BasePlugin.prototype.getNextValues = function (eventType, payload) {
1610
+ return {
1611
+ pageViewId: eventType === BasePluginEventTypes.pageview ? this.nextPageViewId : this.pageViewId,
1612
+ referrer: eventType === BasePluginEventTypes.pageview && this.hasSentFirstPageView
1613
+ ? this.currentLocation
1614
+ : this.lastReferrer,
1615
+ location: eventType === BasePluginEventTypes.pageview
1616
+ ? this.getCurrentLocationFromPayload(payload)
1617
+ : this.currentLocation,
1618
+ };
1619
+ };
1620
+ BasePlugin.prototype.getCurrentLocationFromPayload = function (payload) {
1621
+ if (!!payload.page) {
1622
+ var removeStartingSlash = function (page) { return page.replace(/^\/?(.*)$/, '/$1'); };
1623
+ var extractHostnamePart = function (location) { return location.split('/').slice(0, 3).join('/'); };
1624
+ return "" + extractHostnamePart(this.currentLocation) + removeStartingSlash(payload.page);
1625
+ }
1626
+ else {
1627
+ return getFormattedLocation(window.location);
1628
+ }
1629
+ };
1630
+ return BasePlugin;
1631
+ }());
1632
+
1633
+ var ECPluginEventTypes = __assign({}, BasePluginEventTypes);
1634
+ var allECEventTypes = Object.keys(ECPluginEventTypes).map(function (key) { return ECPluginEventTypes[key]; });
1635
+ var ECPlugin = (function (_super) {
1636
+ __extends(ECPlugin, _super);
1637
+ function ECPlugin(_a) {
1638
+ var client = _a.client, _b = _a.uuidGenerator, uuidGenerator = _b === void 0 ? uuidv4 : _b;
1639
+ var _this = _super.call(this, { client: client, uuidGenerator: uuidGenerator }) || this;
1640
+ _this.products = [];
1641
+ _this.impressions = [];
1642
+ return _this;
1643
+ }
1644
+ ECPlugin.prototype.addHooks = function () {
1645
+ this.addHooksForPageView();
1646
+ this.addHooksForEvent();
1647
+ this.addHooksForECEvents();
1648
+ };
1649
+ ECPlugin.prototype.addProduct = function (product) {
1650
+ this.products.push(product);
1651
+ };
1652
+ ECPlugin.prototype.addImpression = function (impression) {
1653
+ this.impressions.push(impression);
1654
+ };
1655
+ ECPlugin.prototype.clearPluginData = function () {
1656
+ this.products = [];
1657
+ this.impressions = [];
1658
+ };
1659
+ ECPlugin.prototype.addHooksForECEvents = function () {
1660
+ var _this = this;
1661
+ this.client.registerBeforeSendEventHook(function (eventType) {
1662
+ var _a = [];
1663
+ for (var _i = 1; _i < arguments.length; _i++) {
1664
+ _a[_i - 1] = arguments[_i];
1665
+ }
1666
+ var payload = _a[0];
1667
+ return allECEventTypes.indexOf(eventType) !== -1 ? _this.addECDataToPayload(eventType, payload) : payload;
1668
+ });
1669
+ this.client.registerAfterSendEventHook(function (eventType) {
1670
+ var _a = [];
1671
+ for (var _i = 1; _i < arguments.length; _i++) {
1672
+ _a[_i - 1] = arguments[_i];
1673
+ }
1674
+ var payload = _a[0];
1675
+ if (allECEventTypes.indexOf(eventType) !== -1) {
1676
+ _this.updateLocationInformation(eventType, payload);
1677
+ }
1678
+ return payload;
1679
+ });
1680
+ };
1681
+ ECPlugin.prototype.addHooksForPageView = function () {
1682
+ this.client.addEventTypeMapping(ECPluginEventTypes.pageview, {
1683
+ newEventType: EventType.collect,
1684
+ variableLengthArgumentsNames: ['page'],
1685
+ addVisitorIdParameter: true,
1686
+ usesMeasurementProtocol: true,
1687
+ });
1688
+ };
1689
+ ECPlugin.prototype.addHooksForEvent = function () {
1690
+ this.client.addEventTypeMapping(ECPluginEventTypes.event, {
1691
+ newEventType: EventType.collect,
1692
+ variableLengthArgumentsNames: ['eventCategory', 'eventAction', 'eventLabel', 'eventValue'],
1693
+ addVisitorIdParameter: true,
1694
+ usesMeasurementProtocol: true,
1695
+ });
1696
+ };
1697
+ ECPlugin.prototype.addECDataToPayload = function (eventType, payload) {
1698
+ var ecPayload = __assign(__assign(__assign(__assign({}, this.getLocationInformation(eventType, payload)), this.getDefaultContextInformation(eventType)), (this.action ? { action: this.action } : {})), (this.actionData || {}));
1699
+ var productPayload = this.getProductPayload();
1700
+ var impressionPayload = this.getImpressionPayload();
1701
+ this.clearData();
1702
+ return __assign(__assign(__assign(__assign({}, impressionPayload), productPayload), ecPayload), payload);
1703
+ };
1704
+ ECPlugin.prototype.getProductPayload = function () {
1705
+ var _this = this;
1706
+ return this.products
1707
+ .map(function (product) { return _this.assureProductValidity(product); })
1708
+ .reduce(function (newPayload, product, index) {
1709
+ return __assign(__assign({}, newPayload), convertProductToMeasurementProtocol(product, index));
1710
+ }, {});
1711
+ };
1712
+ ECPlugin.prototype.getImpressionPayload = function () {
1713
+ var _this = this;
1714
+ var impressionsByList = this.getImpressionsByList();
1715
+ return impressionsByList
1716
+ .map(function (_a) {
1717
+ var impressions = _a.impressions, rest = __rest(_a, ["impressions"]);
1718
+ return (__assign(__assign({}, rest), { impressions: impressions.map(function (baseImpression) {
1719
+ return _this.assureBaseImpressionValidity(baseImpression);
1720
+ }) }));
1721
+ })
1722
+ .reduce(function (newPayload, impressionList, index) {
1723
+ return __assign(__assign({}, newPayload), convertImpressionListToMeasurementProtocol(impressionList, index, 'pi'));
1724
+ }, {});
1725
+ };
1726
+ ECPlugin.prototype.assureProductValidity = function (product) {
1727
+ var position = product.position, productRest = __rest(product, ["position"]);
1728
+ if (position !== undefined && position < 1) {
1729
+ console.warn("The position for product '" + (product.name || product.id) + "' must be greater " + "than 0 when provided.");
1730
+ return productRest;
1731
+ }
1732
+ return product;
1733
+ };
1734
+ ECPlugin.prototype.assureBaseImpressionValidity = function (baseImpression) {
1735
+ var position = baseImpression.position, baseImpressionRest = __rest(baseImpression, ["position"]);
1736
+ if (position !== undefined && position < 1) {
1737
+ console.warn("The position for impression '" + (baseImpression.name || baseImpression.id) + "'" +
1738
+ " must be greater than 0 when provided.");
1739
+ return baseImpressionRest;
1740
+ }
1741
+ return baseImpression;
1742
+ };
1743
+ ECPlugin.prototype.getImpressionsByList = function () {
1744
+ return this.impressions.reduce(function (lists, impression) {
1745
+ var listName = impression.list, baseImpression = __rest(impression, ["list"]);
1746
+ var list = lists.find(function (list) { return list.listName === listName; });
1747
+ if (list) {
1748
+ list.impressions.push(baseImpression);
1749
+ }
1750
+ else {
1751
+ lists.push({ listName: listName, impressions: [baseImpression] });
1752
+ }
1753
+ return lists;
1754
+ }, []);
1755
+ };
1756
+ ECPlugin.Id = 'ec';
1757
+ return ECPlugin;
1758
+ }(BasePlugin));
1759
+ var EC = ECPlugin;
1760
+
1761
+ var SVCPluginEventTypes = __assign({}, BasePluginEventTypes);
1762
+ var allSVCEventTypes = Object.keys(SVCPluginEventTypes).map(function (key) { return SVCPluginEventTypes[key]; });
1763
+ var SVCPlugin = (function (_super) {
1764
+ __extends(SVCPlugin, _super);
1765
+ function SVCPlugin(_a) {
1766
+ var client = _a.client, _b = _a.uuidGenerator, uuidGenerator = _b === void 0 ? uuidv4 : _b;
1767
+ var _this = _super.call(this, { client: client, uuidGenerator: uuidGenerator }) || this;
1768
+ _this.ticket = {};
1769
+ return _this;
1770
+ }
1771
+ SVCPlugin.prototype.addHooks = function () {
1772
+ this.addHooksForEvent();
1773
+ this.addHooksForPageView();
1774
+ this.addHooksForSVCEvents();
1775
+ };
1776
+ SVCPlugin.prototype.setTicket = function (ticket) {
1777
+ this.ticket = ticket;
1778
+ };
1779
+ SVCPlugin.prototype.clearPluginData = function () {
1780
+ this.ticket = {};
1781
+ };
1782
+ SVCPlugin.prototype.addHooksForSVCEvents = function () {
1783
+ var _this = this;
1784
+ this.client.registerBeforeSendEventHook(function (eventType) {
1785
+ var _a = [];
1786
+ for (var _i = 1; _i < arguments.length; _i++) {
1787
+ _a[_i - 1] = arguments[_i];
1788
+ }
1789
+ var payload = _a[0];
1790
+ return allSVCEventTypes.indexOf(eventType) !== -1 ? _this.addSVCDataToPayload(eventType, payload) : payload;
1791
+ });
1792
+ this.client.registerAfterSendEventHook(function (eventType) {
1793
+ var _a = [];
1794
+ for (var _i = 1; _i < arguments.length; _i++) {
1795
+ _a[_i - 1] = arguments[_i];
1796
+ }
1797
+ var payload = _a[0];
1798
+ if (allSVCEventTypes.indexOf(eventType) !== -1) {
1799
+ _this.updateLocationInformation(eventType, payload);
1800
+ }
1801
+ return payload;
1802
+ });
1803
+ };
1804
+ SVCPlugin.prototype.addHooksForPageView = function () {
1805
+ this.client.addEventTypeMapping(SVCPluginEventTypes.pageview, {
1806
+ newEventType: EventType.collect,
1807
+ variableLengthArgumentsNames: ['page'],
1808
+ addVisitorIdParameter: true,
1809
+ usesMeasurementProtocol: true,
1810
+ });
1811
+ };
1812
+ SVCPlugin.prototype.addHooksForEvent = function () {
1813
+ this.client.addEventTypeMapping(SVCPluginEventTypes.event, {
1814
+ newEventType: EventType.collect,
1815
+ variableLengthArgumentsNames: ['eventCategory', 'eventAction', 'eventLabel', 'eventValue'],
1816
+ addVisitorIdParameter: true,
1817
+ usesMeasurementProtocol: true,
1818
+ });
1819
+ };
1820
+ SVCPlugin.prototype.addSVCDataToPayload = function (eventType, payload) {
1821
+ var _a;
1822
+ var svcPayload = __assign(__assign(__assign(__assign({}, this.getLocationInformation(eventType, payload)), this.getDefaultContextInformation(eventType)), (this.action ? { svcAction: this.action } : {})), (Object.keys((_a = this.actionData) !== null && _a !== void 0 ? _a : {}).length > 0 ? { svcActionData: this.actionData } : {}));
1823
+ var ticketPayload = this.getTicketPayload();
1824
+ this.clearData();
1825
+ return __assign(__assign(__assign({}, ticketPayload), svcPayload), payload);
1826
+ };
1827
+ SVCPlugin.prototype.getTicketPayload = function () {
1828
+ return convertTicketToMeasurementProtocol(this.ticket);
1829
+ };
1830
+ SVCPlugin.Id = 'svc';
1831
+ return SVCPlugin;
1832
+ }(BasePlugin));
1833
+ var SVC = SVCPlugin;
1834
+
1835
+ var Plugins = (function () {
1836
+ function Plugins() {
1837
+ var _a;
1838
+ this.registeredPluginsMap = (_a = {},
1839
+ _a[EC.Id] = EC,
1840
+ _a[SVC.Id] = SVC,
1841
+ _a);
1842
+ this.requiredPlugins = {};
1843
+ }
1844
+ Plugins.prototype.require = function (name, options) {
1845
+ var pluginClass = this.registeredPluginsMap[name];
1846
+ if (!pluginClass) {
1847
+ throw new Error("No plugin named \"" + name + "\" is currently registered. If you use a custom plugin, use 'provide' first.");
1848
+ }
1849
+ this.requiredPlugins[name] = new pluginClass(options);
1850
+ };
1851
+ Plugins.prototype.provide = function (name, plugin) {
1852
+ this.registeredPluginsMap[name] = plugin;
1853
+ };
1854
+ Plugins.prototype.clearRequired = function () {
1855
+ this.requiredPlugins = {};
1856
+ };
1857
+ Plugins.prototype.execute = function (name, fn) {
1858
+ var pluginOptions = [];
1859
+ for (var _i = 2; _i < arguments.length; _i++) {
1860
+ pluginOptions[_i - 2] = arguments[_i];
1861
+ }
1862
+ var plugin = this.requiredPlugins[name];
1863
+ if (!plugin) {
1864
+ throw new Error("The plugin \"" + name + "\" is not required. Check that you required it on initialization.");
1865
+ }
1866
+ var actionFunction = plugin[fn];
1867
+ if (!actionFunction) {
1868
+ throw new Error("The function \"" + fn + "\" does not exists on the plugin \"" + name + "\".");
1869
+ }
1870
+ if (typeof actionFunction !== 'function') {
1871
+ throw new Error("\"" + fn + "\" of the plugin \"" + name + "\" is not a function.");
1872
+ }
1873
+ return actionFunction.apply(plugin, pluginOptions);
1874
+ };
1875
+ Plugins.DefaultPlugins = [EC.Id, SVC.Id];
1876
+ return Plugins;
1877
+ }());
1878
+
1879
+ var CoveoUA = (function () {
1880
+ function CoveoUA() {
1881
+ this.plugins = new Plugins();
1882
+ this.params = {};
1883
+ }
1884
+ CoveoUA.prototype.init = function (token, optionsOrEndpoint) {
1885
+ var _this = this;
1886
+ if (!token) {
1887
+ throw new Error("You must pass your token when you call 'init'");
1888
+ }
1889
+ if (typeof token === 'string') {
1890
+ this.client = new CoveoAnalyticsClient({
1891
+ token: token,
1892
+ endpoint: this.getEndpoint(optionsOrEndpoint),
1893
+ });
1894
+ }
1895
+ else if (this.isAnalyticsClient(token)) {
1896
+ this.client = token;
1897
+ }
1898
+ if (this.client) {
1899
+ var pluginOptions_1 = { client: this.client };
1900
+ this.plugins.clearRequired();
1901
+ this.getPluginKeys(optionsOrEndpoint).forEach(function (pluginKey) {
1902
+ return _this.plugins.require(pluginKey, pluginOptions_1);
1903
+ });
1904
+ this.client.registerBeforeSendEventHook(function (eventType, payload) { return (__assign(__assign({}, payload), _this.params)); });
1905
+ this.client.addEventTypeMapping(EventType.view, { newEventType: EventType.view, addClientIdParameter: true });
1906
+ }
1907
+ else {
1908
+ throw new Error("You must pass either your token or a valid object when you call 'init'");
1909
+ }
1910
+ };
1911
+ CoveoUA.prototype.isAnalyticsClient = function (token) {
1912
+ return typeof token === 'object' && typeof token.sendEvent !== 'undefined';
1913
+ };
1914
+ CoveoUA.prototype.getPluginKeys = function (optionsOrEndpoint) {
1915
+ if (typeof optionsOrEndpoint === 'string') {
1916
+ return Plugins.DefaultPlugins;
1917
+ }
1918
+ return Array.isArray(optionsOrEndpoint === null || optionsOrEndpoint === void 0 ? void 0 : optionsOrEndpoint.plugins) ? optionsOrEndpoint.plugins : Plugins.DefaultPlugins;
1919
+ };
1920
+ CoveoUA.prototype.getEndpoint = function (optionsOrEndpoint) {
1921
+ if (typeof optionsOrEndpoint === 'string') {
1922
+ return optionsOrEndpoint || Endpoints.default;
1923
+ }
1924
+ else if (optionsOrEndpoint === null || optionsOrEndpoint === void 0 ? void 0 : optionsOrEndpoint.endpoint) {
1925
+ return optionsOrEndpoint.endpoint;
1926
+ }
1927
+ return Endpoints.default;
1928
+ };
1929
+ CoveoUA.prototype.initForProxy = function (endpoint) {
1930
+ if (!endpoint) {
1931
+ throw new Error("You must pass your endpoint when you call 'initForProxy'");
1932
+ }
1933
+ if (typeof endpoint !== 'string') {
1934
+ throw new Error("You must pass a string as the endpoint parameter when you call 'initForProxy'");
1935
+ }
1936
+ this.client = new CoveoAnalyticsClient({
1937
+ endpoint: endpoint,
1938
+ });
1939
+ };
1940
+ CoveoUA.prototype.set = function (keyOrObject, value) {
1941
+ var _this = this;
1942
+ if (typeof keyOrObject === 'string') {
1943
+ this.params[keyOrObject] = value;
1944
+ }
1945
+ else {
1946
+ Object.keys(keyOrObject).map(function (key) {
1947
+ _this.params[key] = keyOrObject[key];
1948
+ });
1949
+ }
1950
+ };
1951
+ CoveoUA.prototype.send = function () {
1952
+ var _a;
1953
+ var _b = [];
1954
+ for (var _i = 0; _i < arguments.length; _i++) {
1955
+ _b[_i] = arguments[_i];
1956
+ }
1957
+ var event = _b[0], payload = _b.slice(1);
1958
+ if (typeof this.client == 'undefined') {
1959
+ throw new Error("You must call init before sending an event");
1960
+ }
1961
+ if (!event) {
1962
+ throw new Error("You must provide an event type when calling \"send\".");
1963
+ }
1964
+ return (_a = this.client).sendEvent.apply(_a, __spreadArrays([event.toLowerCase()], payload));
1965
+ };
1966
+ CoveoUA.prototype.onLoad = function (callback) {
1967
+ if (typeof callback == 'undefined') {
1968
+ throw new Error("You must pass a function when you call 'onLoad'");
1969
+ }
1970
+ callback();
1971
+ };
1972
+ CoveoUA.prototype.provide = function (name, plugin) {
1973
+ this.plugins.provide(name, plugin);
1974
+ };
1975
+ CoveoUA.prototype.require = function (name, options) {
1976
+ if (!this.client) {
1977
+ throw new Error("You must call init before requiring a plugin");
1978
+ }
1979
+ this.plugins.require(name, __assign(__assign({}, options), { client: this.client }));
1980
+ };
1981
+ CoveoUA.prototype.callPlugin = function (pluginName, fn) {
1982
+ var _a;
1983
+ var args = [];
1984
+ for (var _i = 2; _i < arguments.length; _i++) {
1985
+ args[_i - 2] = arguments[_i];
1986
+ }
1987
+ (_a = this.plugins).execute.apply(_a, __spreadArrays([pluginName, fn], args));
1988
+ };
1989
+ CoveoUA.prototype.reset = function () {
1990
+ this.client = undefined;
1991
+ this.plugins = new Plugins();
1992
+ this.params = {};
1993
+ };
1994
+ return CoveoUA;
1995
+ }());
1996
+ var coveoua$1 = new CoveoUA();
1997
+ var getCurrentClient = function () { return coveoua$1.client; };
1998
+ var handleOneAnalyticsEvent = function (command) {
1999
+ var params = [];
2000
+ for (var _i = 1; _i < arguments.length; _i++) {
2001
+ params[_i - 1] = arguments[_i];
2002
+ }
2003
+ var _a = /^(?:(\w+)\.)?(?:(\w+):)?(\w+)$/.exec(command); _a[1]; var pluginName = _a[2], fn = _a[3];
2004
+ var actionFunction = coveoua$1[fn];
2005
+ if (pluginName && fn) {
2006
+ return coveoua$1.callPlugin.apply(coveoua$1, __spreadArrays([pluginName, fn], params));
2007
+ }
2008
+ else if (actionFunction) {
2009
+ return actionFunction.apply(coveoua$1, params);
2010
+ }
2011
+ else {
2012
+ var actions = [
2013
+ 'init',
2014
+ 'set',
2015
+ 'send',
2016
+ 'onLoad',
2017
+ 'callPlugin',
2018
+ 'reset',
2019
+ 'require',
2020
+ 'provide',
2021
+ ];
2022
+ throw new Error("The action \"" + command + "\" does not exist. Available actions: " + actions.join(', ') + ".");
2023
+ }
2024
+ };
2025
+
2026
+ var simpleanalytics = /*#__PURE__*/Object.freeze({
2027
+ __proto__: null,
2028
+ CoveoUA: CoveoUA,
2029
+ coveoua: coveoua$1,
2030
+ getCurrentClient: getCurrentClient,
2031
+ handleOneAnalyticsEvent: handleOneAnalyticsEvent,
2032
+ 'default': handleOneAnalyticsEvent
2033
+ });
2034
+
2035
+ var InsightEvents;
2036
+ (function (InsightEvents) {
2037
+ InsightEvents["contextChanged"] = "contextChanged";
2038
+ InsightEvents["expandToFullUI"] = "expandToFullUI";
2039
+ })(InsightEvents || (InsightEvents = {}));
2040
+
2041
+ var _a;
2042
+ var SearchPageEvents;
2043
+ (function (SearchPageEvents) {
2044
+ SearchPageEvents["interfaceLoad"] = "interfaceLoad";
2045
+ SearchPageEvents["interfaceChange"] = "interfaceChange";
2046
+ SearchPageEvents["didyoumeanAutomatic"] = "didyoumeanAutomatic";
2047
+ SearchPageEvents["didyoumeanClick"] = "didyoumeanClick";
2048
+ SearchPageEvents["resultsSort"] = "resultsSort";
2049
+ SearchPageEvents["searchboxSubmit"] = "searchboxSubmit";
2050
+ SearchPageEvents["searchboxClear"] = "searchboxClear";
2051
+ SearchPageEvents["searchboxAsYouType"] = "searchboxAsYouType";
2052
+ SearchPageEvents["breadcrumbFacet"] = "breadcrumbFacet";
2053
+ SearchPageEvents["breadcrumbResetAll"] = "breadcrumbResetAll";
2054
+ SearchPageEvents["documentQuickview"] = "documentQuickview";
2055
+ SearchPageEvents["documentOpen"] = "documentOpen";
2056
+ SearchPageEvents["omniboxAnalytics"] = "omniboxAnalytics";
2057
+ SearchPageEvents["omniboxFromLink"] = "omniboxFromLink";
2058
+ SearchPageEvents["searchFromLink"] = "searchFromLink";
2059
+ SearchPageEvents["triggerNotify"] = "notify";
2060
+ SearchPageEvents["triggerExecute"] = "execute";
2061
+ SearchPageEvents["triggerQuery"] = "query";
2062
+ SearchPageEvents["undoTriggerQuery"] = "undoQuery";
2063
+ SearchPageEvents["triggerRedirect"] = "redirect";
2064
+ SearchPageEvents["pagerResize"] = "pagerResize";
2065
+ SearchPageEvents["pagerNumber"] = "pagerNumber";
2066
+ SearchPageEvents["pagerNext"] = "pagerNext";
2067
+ SearchPageEvents["pagerPrevious"] = "pagerPrevious";
2068
+ SearchPageEvents["pagerScrolling"] = "pagerScrolling";
2069
+ SearchPageEvents["staticFilterClearAll"] = "staticFilterClearAll";
2070
+ SearchPageEvents["staticFilterSelect"] = "staticFilterSelect";
2071
+ SearchPageEvents["staticFilterDeselect"] = "staticFilterDeselect";
2072
+ SearchPageEvents["facetClearAll"] = "facetClearAll";
2073
+ SearchPageEvents["facetSearch"] = "facetSearch";
2074
+ SearchPageEvents["facetSelect"] = "facetSelect";
2075
+ SearchPageEvents["facetSelectAll"] = "facetSelectAll";
2076
+ SearchPageEvents["facetDeselect"] = "facetDeselect";
2077
+ SearchPageEvents["facetExclude"] = "facetExclude";
2078
+ SearchPageEvents["facetUnexclude"] = "facetUnexclude";
2079
+ SearchPageEvents["facetUpdateSort"] = "facetUpdateSort";
2080
+ SearchPageEvents["facetShowMore"] = "showMoreFacetResults";
2081
+ SearchPageEvents["facetShowLess"] = "showLessFacetResults";
2082
+ SearchPageEvents["queryError"] = "query";
2083
+ SearchPageEvents["queryErrorBack"] = "errorBack";
2084
+ SearchPageEvents["queryErrorClear"] = "errorClearQuery";
2085
+ SearchPageEvents["queryErrorRetry"] = "errorRetry";
2086
+ SearchPageEvents["recommendation"] = "recommendation";
2087
+ SearchPageEvents["recommendationInterfaceLoad"] = "recommendationInterfaceLoad";
2088
+ SearchPageEvents["recommendationOpen"] = "recommendationOpen";
2089
+ SearchPageEvents["likeSmartSnippet"] = "likeSmartSnippet";
2090
+ SearchPageEvents["dislikeSmartSnippet"] = "dislikeSmartSnippet";
2091
+ SearchPageEvents["expandSmartSnippet"] = "expandSmartSnippet";
2092
+ SearchPageEvents["collapseSmartSnippet"] = "collapseSmartSnippet";
2093
+ SearchPageEvents["openSmartSnippetFeedbackModal"] = "openSmartSnippetFeedbackModal";
2094
+ SearchPageEvents["closeSmartSnippetFeedbackModal"] = "closeSmartSnippetFeedbackModal";
2095
+ SearchPageEvents["sendSmartSnippetReason"] = "sendSmartSnippetReason";
2096
+ SearchPageEvents["expandSmartSnippetSuggestion"] = "expandSmartSnippetSuggestion";
2097
+ SearchPageEvents["collapseSmartSnippetSuggestion"] = "collapseSmartSnippetSuggestion";
2098
+ SearchPageEvents["showMoreSmartSnippetSuggestion"] = "showMoreSmartSnippetSuggestion";
2099
+ SearchPageEvents["showLessSmartSnippetSuggestion"] = "showLessSmartSnippetSuggestion";
2100
+ SearchPageEvents["openSmartSnippetSource"] = "openSmartSnippetSource";
2101
+ SearchPageEvents["openSmartSnippetSuggestionSource"] = "openSmartSnippetSuggestionSource";
2102
+ SearchPageEvents["openSmartSnippetInlineLink"] = "openSmartSnippetInlineLink";
2103
+ SearchPageEvents["openSmartSnippetSuggestionInlineLink"] = "openSmartSnippetSuggestionInlineLink";
2104
+ SearchPageEvents["recentQueryClick"] = "recentQueriesClick";
2105
+ SearchPageEvents["clearRecentQueries"] = "clearRecentQueries";
2106
+ SearchPageEvents["recentResultClick"] = "recentResultClick";
2107
+ SearchPageEvents["clearRecentResults"] = "clearRecentResults";
2108
+ SearchPageEvents["noResultsBack"] = "noResultsBack";
2109
+ SearchPageEvents["showMoreFoldedResults"] = "showMoreFoldedResults";
2110
+ SearchPageEvents["showLessFoldedResults"] = "showLessFoldedResults";
2111
+ SearchPageEvents["copyToClipboard"] = "copyToClipboard";
2112
+ })(SearchPageEvents || (SearchPageEvents = {}));
2113
+ var CustomEventsTypes = (_a = {},
2114
+ _a[SearchPageEvents.triggerNotify] = 'queryPipelineTriggers',
2115
+ _a[SearchPageEvents.triggerExecute] = 'queryPipelineTriggers',
2116
+ _a[SearchPageEvents.triggerQuery] = 'queryPipelineTriggers',
2117
+ _a[SearchPageEvents.triggerRedirect] = 'queryPipelineTriggers',
2118
+ _a[SearchPageEvents.queryError] = 'errors',
2119
+ _a[SearchPageEvents.queryErrorBack] = 'errors',
2120
+ _a[SearchPageEvents.queryErrorClear] = 'errors',
2121
+ _a[SearchPageEvents.queryErrorRetry] = 'errors',
2122
+ _a[SearchPageEvents.pagerNext] = 'getMoreResults',
2123
+ _a[SearchPageEvents.pagerPrevious] = 'getMoreResults',
2124
+ _a[SearchPageEvents.pagerNumber] = 'getMoreResults',
2125
+ _a[SearchPageEvents.pagerResize] = 'getMoreResults',
2126
+ _a[SearchPageEvents.pagerScrolling] = 'getMoreResults',
2127
+ _a[SearchPageEvents.facetSearch] = 'facet',
2128
+ _a[SearchPageEvents.facetShowLess] = 'facet',
2129
+ _a[SearchPageEvents.facetShowMore] = 'facet',
2130
+ _a[SearchPageEvents.recommendation] = 'recommendation',
2131
+ _a[SearchPageEvents.likeSmartSnippet] = 'smartSnippet',
2132
+ _a[SearchPageEvents.dislikeSmartSnippet] = 'smartSnippet',
2133
+ _a[SearchPageEvents.expandSmartSnippet] = 'smartSnippet',
2134
+ _a[SearchPageEvents.collapseSmartSnippet] = 'smartSnippet',
2135
+ _a[SearchPageEvents.openSmartSnippetFeedbackModal] = 'smartSnippet',
2136
+ _a[SearchPageEvents.closeSmartSnippetFeedbackModal] = 'smartSnippet',
2137
+ _a[SearchPageEvents.sendSmartSnippetReason] = 'smartSnippet',
2138
+ _a[SearchPageEvents.expandSmartSnippetSuggestion] = 'smartSnippetSuggestions',
2139
+ _a[SearchPageEvents.collapseSmartSnippetSuggestion] = 'smartSnippetSuggestions',
2140
+ _a[SearchPageEvents.showMoreSmartSnippetSuggestion] = 'smartSnippetSuggestions',
2141
+ _a[SearchPageEvents.showLessSmartSnippetSuggestion] = 'smartSnippetSuggestions',
2142
+ _a[SearchPageEvents.clearRecentQueries] = 'recentQueries',
2143
+ _a[SearchPageEvents.recentResultClick] = 'recentlyClickedDocuments',
2144
+ _a[SearchPageEvents.clearRecentResults] = 'recentlyClickedDocuments',
2145
+ _a[SearchPageEvents.showLessFoldedResults] = 'folding',
2146
+ _a[InsightEvents.expandToFullUI] = 'interface',
2147
+ _a);
2148
+
2149
+ var NoopAnalytics = (function () {
2150
+ function NoopAnalytics() {
2151
+ this.runtime = new NoopRuntime();
2152
+ this.currentVisitorId = '';
2153
+ }
2154
+ NoopAnalytics.prototype.getPayload = function () {
2155
+ return Promise.resolve();
2156
+ };
2157
+ NoopAnalytics.prototype.getParameters = function () {
2158
+ return Promise.resolve();
2159
+ };
2160
+ NoopAnalytics.prototype.sendEvent = function () {
2161
+ return Promise.resolve();
2162
+ };
2163
+ NoopAnalytics.prototype.sendSearchEvent = function () {
2164
+ return Promise.resolve();
2165
+ };
2166
+ NoopAnalytics.prototype.sendClickEvent = function () {
2167
+ return Promise.resolve();
2168
+ };
2169
+ NoopAnalytics.prototype.sendCustomEvent = function () {
2170
+ return Promise.resolve();
2171
+ };
2172
+ NoopAnalytics.prototype.sendViewEvent = function () {
2173
+ return Promise.resolve();
2174
+ };
2175
+ NoopAnalytics.prototype.getVisit = function () {
2176
+ return Promise.resolve({ id: '', visitorId: '' });
2177
+ };
2178
+ NoopAnalytics.prototype.getHealth = function () {
2179
+ return Promise.resolve({ status: '' });
2180
+ };
2181
+ NoopAnalytics.prototype.registerBeforeSendEventHook = function () { };
2182
+ NoopAnalytics.prototype.registerAfterSendEventHook = function () { };
2183
+ NoopAnalytics.prototype.addEventTypeMapping = function () { };
2184
+ return NoopAnalytics;
2185
+ }());
2186
+
2187
+ function filterConsecutiveRepeatedValues(rawData) {
2188
+ var prev = '';
2189
+ return rawData.filter(function (value) {
2190
+ var isDifferent = value !== prev;
2191
+ prev = value;
2192
+ return isDifferent;
2193
+ });
2194
+ }
2195
+ function removeSemicolons(rawData) {
2196
+ return rawData.map(function (value) {
2197
+ return value.replace(/;/g, '');
2198
+ });
2199
+ }
2200
+ function getDataString(data) {
2201
+ var ANALYTICS_LENGTH_LIMIT = 256;
2202
+ var formattedData = data.join(';');
2203
+ if (formattedData.length <= ANALYTICS_LENGTH_LIMIT) {
2204
+ return formattedData;
2205
+ }
2206
+ return getDataString(data.slice(1));
2207
+ }
2208
+ var formatArrayForCoveoCustomData = function (rawData) {
2209
+ var dataWithoutSemicolons = removeSemicolons(rawData);
2210
+ var dataWithoutRepeatedValues = filterConsecutiveRepeatedValues(dataWithoutSemicolons);
2211
+ return getDataString(dataWithoutRepeatedValues);
2212
+ };
2213
+
2214
+ function formatOmniboxMetadata(meta) {
2215
+ var partialQueries = typeof meta.partialQueries === 'string'
2216
+ ? meta.partialQueries
2217
+ : formatArrayForCoveoCustomData(meta.partialQueries);
2218
+ var suggestions = typeof meta.suggestions === 'string' ? meta.suggestions : formatArrayForCoveoCustomData(meta.suggestions);
2219
+ return __assign(__assign({}, meta), { partialQueries: partialQueries,
2220
+ suggestions: suggestions });
2221
+ }
2222
+
2223
+ var CoveoSearchPageClient = (function () {
2224
+ function CoveoSearchPageClient(opts, provider) {
2225
+ this.opts = opts;
2226
+ this.provider = provider;
2227
+ var shouldDisableAnalytics = opts.enableAnalytics === false || doNotTrack();
2228
+ this.coveoAnalyticsClient = shouldDisableAnalytics ? new NoopAnalytics() : new CoveoAnalyticsClient(opts);
2229
+ }
2230
+ CoveoSearchPageClient.prototype.disable = function () {
2231
+ if (this.coveoAnalyticsClient instanceof CoveoAnalyticsClient) {
2232
+ this.coveoAnalyticsClient.clear();
2233
+ }
2234
+ this.coveoAnalyticsClient = new NoopAnalytics();
2235
+ };
2236
+ CoveoSearchPageClient.prototype.enable = function () {
2237
+ this.coveoAnalyticsClient = new CoveoAnalyticsClient(this.opts);
2238
+ };
2239
+ CoveoSearchPageClient.prototype.makeInterfaceLoad = function () {
2240
+ return this.makeSearchEvent(SearchPageEvents.interfaceLoad);
2241
+ };
2242
+ CoveoSearchPageClient.prototype.logInterfaceLoad = function () {
2243
+ return this.makeInterfaceLoad().log();
2244
+ };
2245
+ CoveoSearchPageClient.prototype.makeRecommendationInterfaceLoad = function () {
2246
+ return this.makeSearchEvent(SearchPageEvents.recommendationInterfaceLoad);
2247
+ };
2248
+ CoveoSearchPageClient.prototype.logRecommendationInterfaceLoad = function () {
2249
+ return this.makeRecommendationInterfaceLoad().log();
2250
+ };
2251
+ CoveoSearchPageClient.prototype.makeRecommendation = function () {
2252
+ return this.makeCustomEvent(SearchPageEvents.recommendation);
2253
+ };
2254
+ CoveoSearchPageClient.prototype.logRecommendation = function () {
2255
+ return this.makeRecommendation().log();
2256
+ };
2257
+ CoveoSearchPageClient.prototype.makeRecommendationOpen = function (info, identifier) {
2258
+ return this.makeClickEvent(SearchPageEvents.recommendationOpen, info, identifier);
2259
+ };
2260
+ CoveoSearchPageClient.prototype.logRecommendationOpen = function (info, identifier) {
2261
+ return this.makeRecommendationOpen(info, identifier).log();
2262
+ };
2263
+ CoveoSearchPageClient.prototype.makeStaticFilterClearAll = function (meta) {
2264
+ return this.makeSearchEvent(SearchPageEvents.staticFilterClearAll, meta);
2265
+ };
2266
+ CoveoSearchPageClient.prototype.logStaticFilterClearAll = function (meta) {
2267
+ return this.makeStaticFilterClearAll(meta).log();
2268
+ };
2269
+ CoveoSearchPageClient.prototype.makeStaticFilterSelect = function (meta) {
2270
+ return this.makeSearchEvent(SearchPageEvents.staticFilterSelect, meta);
2271
+ };
2272
+ CoveoSearchPageClient.prototype.logStaticFilterSelect = function (meta) {
2273
+ return this.makeStaticFilterSelect(meta).log();
2274
+ };
2275
+ CoveoSearchPageClient.prototype.makeStaticFilterDeselect = function (meta) {
2276
+ return this.makeSearchEvent(SearchPageEvents.staticFilterDeselect, meta);
2277
+ };
2278
+ CoveoSearchPageClient.prototype.logStaticFilterDeselect = function (meta) {
2279
+ return this.makeStaticFilterDeselect(meta).log();
2280
+ };
2281
+ CoveoSearchPageClient.prototype.makeFetchMoreResults = function () {
2282
+ return this.makeCustomEvent(SearchPageEvents.pagerScrolling, { type: 'getMoreResults' });
2283
+ };
2284
+ CoveoSearchPageClient.prototype.logFetchMoreResults = function () {
2285
+ return this.makeFetchMoreResults().log();
2286
+ };
2287
+ CoveoSearchPageClient.prototype.makeInterfaceChange = function (metadata) {
2288
+ return this.makeSearchEvent(SearchPageEvents.interfaceChange, metadata);
2289
+ };
2290
+ CoveoSearchPageClient.prototype.logInterfaceChange = function (metadata) {
2291
+ return this.makeInterfaceChange(metadata).log();
2292
+ };
2293
+ CoveoSearchPageClient.prototype.makeDidYouMeanAutomatic = function () {
2294
+ return this.makeSearchEvent(SearchPageEvents.didyoumeanAutomatic);
2295
+ };
2296
+ CoveoSearchPageClient.prototype.logDidYouMeanAutomatic = function () {
2297
+ return this.makeDidYouMeanAutomatic().log();
2298
+ };
2299
+ CoveoSearchPageClient.prototype.makeDidYouMeanClick = function () {
2300
+ return this.makeSearchEvent(SearchPageEvents.didyoumeanClick);
2301
+ };
2302
+ CoveoSearchPageClient.prototype.logDidYouMeanClick = function () {
2303
+ return this.makeDidYouMeanClick().log();
2304
+ };
2305
+ CoveoSearchPageClient.prototype.makeResultsSort = function (metadata) {
2306
+ return this.makeSearchEvent(SearchPageEvents.resultsSort, metadata);
2307
+ };
2308
+ CoveoSearchPageClient.prototype.logResultsSort = function (metadata) {
2309
+ return this.makeResultsSort(metadata).log();
2310
+ };
2311
+ CoveoSearchPageClient.prototype.makeSearchboxSubmit = function () {
2312
+ return this.makeSearchEvent(SearchPageEvents.searchboxSubmit);
2313
+ };
2314
+ CoveoSearchPageClient.prototype.logSearchboxSubmit = function () {
2315
+ return this.makeSearchboxSubmit().log();
2316
+ };
2317
+ CoveoSearchPageClient.prototype.makeSearchboxClear = function () {
2318
+ return this.makeSearchEvent(SearchPageEvents.searchboxClear);
2319
+ };
2320
+ CoveoSearchPageClient.prototype.logSearchboxClear = function () {
2321
+ return this.makeSearchboxClear().log();
2322
+ };
2323
+ CoveoSearchPageClient.prototype.makeSearchboxAsYouType = function () {
2324
+ return this.makeSearchEvent(SearchPageEvents.searchboxAsYouType);
2325
+ };
2326
+ CoveoSearchPageClient.prototype.logSearchboxAsYouType = function () {
2327
+ return this.makeSearchboxAsYouType().log();
2328
+ };
2329
+ CoveoSearchPageClient.prototype.makeBreadcrumbFacet = function (metadata) {
2330
+ return this.makeSearchEvent(SearchPageEvents.breadcrumbFacet, metadata);
2331
+ };
2332
+ CoveoSearchPageClient.prototype.logBreadcrumbFacet = function (metadata) {
2333
+ return this.makeBreadcrumbFacet(metadata).log();
2334
+ };
2335
+ CoveoSearchPageClient.prototype.makeBreadcrumbResetAll = function () {
2336
+ return this.makeSearchEvent(SearchPageEvents.breadcrumbResetAll);
2337
+ };
2338
+ CoveoSearchPageClient.prototype.logBreadcrumbResetAll = function () {
2339
+ return this.makeBreadcrumbResetAll().log();
2340
+ };
2341
+ CoveoSearchPageClient.prototype.makeDocumentQuickview = function (info, identifier) {
2342
+ return this.makeClickEvent(SearchPageEvents.documentQuickview, info, identifier);
2343
+ };
2344
+ CoveoSearchPageClient.prototype.logDocumentQuickview = function (info, identifier) {
2345
+ return this.makeDocumentQuickview(info, identifier).log();
2346
+ };
2347
+ CoveoSearchPageClient.prototype.makeDocumentOpen = function (info, identifier) {
2348
+ return this.makeClickEvent(SearchPageEvents.documentOpen, info, identifier);
2349
+ };
2350
+ CoveoSearchPageClient.prototype.logDocumentOpen = function (info, identifier) {
2351
+ return this.makeDocumentOpen(info, identifier).log();
2352
+ };
2353
+ CoveoSearchPageClient.prototype.makeOmniboxAnalytics = function (meta) {
2354
+ return this.makeSearchEvent(SearchPageEvents.omniboxAnalytics, formatOmniboxMetadata(meta));
2355
+ };
2356
+ CoveoSearchPageClient.prototype.logOmniboxAnalytics = function (meta) {
2357
+ return this.makeOmniboxAnalytics(meta).log();
2358
+ };
2359
+ CoveoSearchPageClient.prototype.makeOmniboxFromLink = function (meta) {
2360
+ return this.makeSearchEvent(SearchPageEvents.omniboxFromLink, formatOmniboxMetadata(meta));
2361
+ };
2362
+ CoveoSearchPageClient.prototype.logOmniboxFromLink = function (meta) {
2363
+ return this.makeOmniboxFromLink(meta).log();
2364
+ };
2365
+ CoveoSearchPageClient.prototype.makeSearchFromLink = function () {
2366
+ return this.makeSearchEvent(SearchPageEvents.searchFromLink);
2367
+ };
2368
+ CoveoSearchPageClient.prototype.logSearchFromLink = function () {
2369
+ return this.makeSearchFromLink().log();
2370
+ };
2371
+ CoveoSearchPageClient.prototype.makeTriggerNotify = function (meta) {
2372
+ return this.makeCustomEvent(SearchPageEvents.triggerNotify, meta);
2373
+ };
2374
+ CoveoSearchPageClient.prototype.logTriggerNotify = function (meta) {
2375
+ return this.makeTriggerNotify(meta).log();
2376
+ };
2377
+ CoveoSearchPageClient.prototype.makeTriggerExecute = function (meta) {
2378
+ return this.makeCustomEvent(SearchPageEvents.triggerExecute, meta);
2379
+ };
2380
+ CoveoSearchPageClient.prototype.logTriggerExecute = function (meta) {
2381
+ return this.makeTriggerExecute(meta).log();
2382
+ };
2383
+ CoveoSearchPageClient.prototype.makeTriggerQuery = function () {
2384
+ return this.makeCustomEvent(SearchPageEvents.triggerQuery, { query: this.provider.getSearchEventRequestPayload().queryText }, 'queryPipelineTriggers');
2385
+ };
2386
+ CoveoSearchPageClient.prototype.logTriggerQuery = function () {
2387
+ return this.makeTriggerQuery().log();
2388
+ };
2389
+ CoveoSearchPageClient.prototype.makeUndoTriggerQuery = function (meta) {
2390
+ return this.makeSearchEvent(SearchPageEvents.undoTriggerQuery, meta);
2391
+ };
2392
+ CoveoSearchPageClient.prototype.logUndoTriggerQuery = function (meta) {
2393
+ return this.makeUndoTriggerQuery(meta).log();
2394
+ };
2395
+ CoveoSearchPageClient.prototype.makeTriggerRedirect = function (meta) {
2396
+ return this.makeCustomEvent(SearchPageEvents.triggerRedirect, __assign(__assign({}, meta), { query: this.provider.getSearchEventRequestPayload().queryText }));
2397
+ };
2398
+ CoveoSearchPageClient.prototype.logTriggerRedirect = function (meta) {
2399
+ return this.makeTriggerRedirect(meta).log();
2400
+ };
2401
+ CoveoSearchPageClient.prototype.makePagerResize = function (meta) {
2402
+ return this.makeCustomEvent(SearchPageEvents.pagerResize, meta);
2403
+ };
2404
+ CoveoSearchPageClient.prototype.logPagerResize = function (meta) {
2405
+ return this.makePagerResize(meta).log();
2406
+ };
2407
+ CoveoSearchPageClient.prototype.makePagerNumber = function (meta) {
2408
+ return this.makeCustomEvent(SearchPageEvents.pagerNumber, meta);
2409
+ };
2410
+ CoveoSearchPageClient.prototype.logPagerNumber = function (meta) {
2411
+ return this.makePagerNumber(meta).log();
2412
+ };
2413
+ CoveoSearchPageClient.prototype.makePagerNext = function (meta) {
2414
+ return this.makeCustomEvent(SearchPageEvents.pagerNext, meta);
2415
+ };
2416
+ CoveoSearchPageClient.prototype.logPagerNext = function (meta) {
2417
+ return this.makePagerNext(meta).log();
2418
+ };
2419
+ CoveoSearchPageClient.prototype.makePagerPrevious = function (meta) {
2420
+ return this.makeCustomEvent(SearchPageEvents.pagerPrevious, meta);
2421
+ };
2422
+ CoveoSearchPageClient.prototype.logPagerPrevious = function (meta) {
2423
+ return this.makePagerPrevious(meta).log();
2424
+ };
2425
+ CoveoSearchPageClient.prototype.makePagerScrolling = function () {
2426
+ return this.makeCustomEvent(SearchPageEvents.pagerScrolling);
2427
+ };
2428
+ CoveoSearchPageClient.prototype.logPagerScrolling = function () {
2429
+ return this.makePagerScrolling().log();
2430
+ };
2431
+ CoveoSearchPageClient.prototype.makeFacetClearAll = function (meta) {
2432
+ return this.makeSearchEvent(SearchPageEvents.facetClearAll, meta);
2433
+ };
2434
+ CoveoSearchPageClient.prototype.logFacetClearAll = function (meta) {
2435
+ return this.makeFacetClearAll(meta).log();
2436
+ };
2437
+ CoveoSearchPageClient.prototype.makeFacetSearch = function (meta) {
2438
+ return this.makeSearchEvent(SearchPageEvents.facetSearch, meta);
2439
+ };
2440
+ CoveoSearchPageClient.prototype.logFacetSearch = function (meta) {
2441
+ return this.makeFacetSearch(meta).log();
2442
+ };
2443
+ CoveoSearchPageClient.prototype.makeFacetSelect = function (meta) {
2444
+ return this.makeSearchEvent(SearchPageEvents.facetSelect, meta);
2445
+ };
2446
+ CoveoSearchPageClient.prototype.logFacetSelect = function (meta) {
2447
+ return this.makeFacetSelect(meta).log();
2448
+ };
2449
+ CoveoSearchPageClient.prototype.makeFacetDeselect = function (meta) {
2450
+ return this.makeSearchEvent(SearchPageEvents.facetDeselect, meta);
2451
+ };
2452
+ CoveoSearchPageClient.prototype.logFacetDeselect = function (meta) {
2453
+ return this.makeFacetDeselect(meta).log();
2454
+ };
2455
+ CoveoSearchPageClient.prototype.makeFacetExclude = function (meta) {
2456
+ return this.makeSearchEvent(SearchPageEvents.facetExclude, meta);
2457
+ };
2458
+ CoveoSearchPageClient.prototype.logFacetExclude = function (meta) {
2459
+ return this.makeFacetExclude(meta).log();
2460
+ };
2461
+ CoveoSearchPageClient.prototype.makeFacetUnexclude = function (meta) {
2462
+ return this.makeSearchEvent(SearchPageEvents.facetUnexclude, meta);
2463
+ };
2464
+ CoveoSearchPageClient.prototype.logFacetUnexclude = function (meta) {
2465
+ return this.makeFacetUnexclude(meta).log();
2466
+ };
2467
+ CoveoSearchPageClient.prototype.makeFacetSelectAll = function (meta) {
2468
+ return this.makeSearchEvent(SearchPageEvents.facetSelectAll, meta);
2469
+ };
2470
+ CoveoSearchPageClient.prototype.logFacetSelectAll = function (meta) {
2471
+ return this.makeFacetSelectAll(meta).log();
2472
+ };
2473
+ CoveoSearchPageClient.prototype.makeFacetUpdateSort = function (meta) {
2474
+ return this.makeSearchEvent(SearchPageEvents.facetUpdateSort, meta);
2475
+ };
2476
+ CoveoSearchPageClient.prototype.logFacetUpdateSort = function (meta) {
2477
+ return this.makeFacetUpdateSort(meta).log();
2478
+ };
2479
+ CoveoSearchPageClient.prototype.makeFacetShowMore = function (meta) {
2480
+ return this.makeCustomEvent(SearchPageEvents.facetShowMore, meta);
2481
+ };
2482
+ CoveoSearchPageClient.prototype.logFacetShowMore = function (meta) {
2483
+ return this.makeFacetShowMore(meta).log();
2484
+ };
2485
+ CoveoSearchPageClient.prototype.makeFacetShowLess = function (meta) {
2486
+ return this.makeCustomEvent(SearchPageEvents.facetShowLess, meta);
2487
+ };
2488
+ CoveoSearchPageClient.prototype.logFacetShowLess = function (meta) {
2489
+ return this.makeFacetShowLess(meta).log();
2490
+ };
2491
+ CoveoSearchPageClient.prototype.makeQueryError = function (meta) {
2492
+ return this.makeCustomEvent(SearchPageEvents.queryError, meta);
2493
+ };
2494
+ CoveoSearchPageClient.prototype.logQueryError = function (meta) {
2495
+ return this.makeQueryError(meta).log();
2496
+ };
2497
+ CoveoSearchPageClient.prototype.makeQueryErrorBack = function () {
2498
+ var _this = this;
2499
+ return {
2500
+ description: this.makeDescription(SearchPageEvents.queryErrorBack),
2501
+ log: function () { return __awaiter(_this, void 0, void 0, function () {
2502
+ return __generator(this, function (_a) {
2503
+ switch (_a.label) {
2504
+ case 0: return [4, this.logCustomEvent(SearchPageEvents.queryErrorBack)];
2505
+ case 1:
2506
+ _a.sent();
2507
+ return [2, this.logSearchEvent(SearchPageEvents.queryErrorBack)];
2508
+ }
2509
+ });
2510
+ }); },
2511
+ };
2512
+ };
2513
+ CoveoSearchPageClient.prototype.logQueryErrorBack = function () {
2514
+ return this.makeQueryErrorBack().log();
2515
+ };
2516
+ CoveoSearchPageClient.prototype.makeQueryErrorRetry = function () {
2517
+ var _this = this;
2518
+ return {
2519
+ description: this.makeDescription(SearchPageEvents.queryErrorRetry),
2520
+ log: function () { return __awaiter(_this, void 0, void 0, function () {
2521
+ return __generator(this, function (_a) {
2522
+ switch (_a.label) {
2523
+ case 0: return [4, this.logCustomEvent(SearchPageEvents.queryErrorRetry)];
2524
+ case 1:
2525
+ _a.sent();
2526
+ return [2, this.logSearchEvent(SearchPageEvents.queryErrorRetry)];
2527
+ }
2528
+ });
2529
+ }); },
2530
+ };
2531
+ };
2532
+ CoveoSearchPageClient.prototype.logQueryErrorRetry = function () {
2533
+ return this.makeQueryErrorRetry().log();
2534
+ };
2535
+ CoveoSearchPageClient.prototype.makeQueryErrorClear = function () {
2536
+ var _this = this;
2537
+ return {
2538
+ description: this.makeDescription(SearchPageEvents.queryErrorClear),
2539
+ log: function () { return __awaiter(_this, void 0, void 0, function () {
2540
+ return __generator(this, function (_a) {
2541
+ switch (_a.label) {
2542
+ case 0: return [4, this.logCustomEvent(SearchPageEvents.queryErrorClear)];
2543
+ case 1:
2544
+ _a.sent();
2545
+ return [2, this.logSearchEvent(SearchPageEvents.queryErrorClear)];
2546
+ }
2547
+ });
2548
+ }); },
2549
+ };
2550
+ };
2551
+ CoveoSearchPageClient.prototype.logQueryErrorClear = function () {
2552
+ return this.makeQueryErrorClear().log();
2553
+ };
2554
+ CoveoSearchPageClient.prototype.makeLikeSmartSnippet = function () {
2555
+ return this.makeCustomEvent(SearchPageEvents.likeSmartSnippet);
2556
+ };
2557
+ CoveoSearchPageClient.prototype.logLikeSmartSnippet = function () {
2558
+ return this.makeLikeSmartSnippet().log();
2559
+ };
2560
+ CoveoSearchPageClient.prototype.makeDislikeSmartSnippet = function () {
2561
+ return this.makeCustomEvent(SearchPageEvents.dislikeSmartSnippet);
2562
+ };
2563
+ CoveoSearchPageClient.prototype.logDislikeSmartSnippet = function () {
2564
+ return this.makeDislikeSmartSnippet().log();
2565
+ };
2566
+ CoveoSearchPageClient.prototype.makeExpandSmartSnippet = function () {
2567
+ return this.makeCustomEvent(SearchPageEvents.expandSmartSnippet);
2568
+ };
2569
+ CoveoSearchPageClient.prototype.logExpandSmartSnippet = function () {
2570
+ return this.makeExpandSmartSnippet().log();
2571
+ };
2572
+ CoveoSearchPageClient.prototype.makeCollapseSmartSnippet = function () {
2573
+ return this.makeCustomEvent(SearchPageEvents.collapseSmartSnippet);
2574
+ };
2575
+ CoveoSearchPageClient.prototype.logCollapseSmartSnippet = function () {
2576
+ return this.makeCollapseSmartSnippet().log();
2577
+ };
2578
+ CoveoSearchPageClient.prototype.makeOpenSmartSnippetFeedbackModal = function () {
2579
+ return this.makeCustomEvent(SearchPageEvents.openSmartSnippetFeedbackModal);
2580
+ };
2581
+ CoveoSearchPageClient.prototype.logOpenSmartSnippetFeedbackModal = function () {
2582
+ return this.makeOpenSmartSnippetFeedbackModal().log();
2583
+ };
2584
+ CoveoSearchPageClient.prototype.makeCloseSmartSnippetFeedbackModal = function () {
2585
+ return this.makeCustomEvent(SearchPageEvents.closeSmartSnippetFeedbackModal);
2586
+ };
2587
+ CoveoSearchPageClient.prototype.logCloseSmartSnippetFeedbackModal = function () {
2588
+ return this.makeCloseSmartSnippetFeedbackModal().log();
2589
+ };
2590
+ CoveoSearchPageClient.prototype.makeSmartSnippetFeedbackReason = function (reason, details) {
2591
+ return this.makeCustomEvent(SearchPageEvents.sendSmartSnippetReason, { reason: reason, details: details });
2592
+ };
2593
+ CoveoSearchPageClient.prototype.logSmartSnippetFeedbackReason = function (reason, details) {
2594
+ return this.makeSmartSnippetFeedbackReason(reason, details).log();
2595
+ };
2596
+ CoveoSearchPageClient.prototype.makeExpandSmartSnippetSuggestion = function (snippet) {
2597
+ return this.makeCustomEvent(SearchPageEvents.expandSmartSnippetSuggestion, 'documentId' in snippet ? snippet : { documentId: snippet });
2598
+ };
2599
+ CoveoSearchPageClient.prototype.logExpandSmartSnippetSuggestion = function (snippet) {
2600
+ return this.makeExpandSmartSnippetSuggestion(snippet).log();
2601
+ };
2602
+ CoveoSearchPageClient.prototype.makeCollapseSmartSnippetSuggestion = function (snippet) {
2603
+ return this.makeCustomEvent(SearchPageEvents.collapseSmartSnippetSuggestion, 'documentId' in snippet ? snippet : { documentId: snippet });
2604
+ };
2605
+ CoveoSearchPageClient.prototype.logCollapseSmartSnippetSuggestion = function (snippet) {
2606
+ return this.makeCollapseSmartSnippetSuggestion(snippet).log();
2607
+ };
2608
+ CoveoSearchPageClient.prototype.makeShowMoreSmartSnippetSuggestion = function (snippet) {
2609
+ return this.makeCustomEvent(SearchPageEvents.showMoreSmartSnippetSuggestion, snippet);
2610
+ };
2611
+ CoveoSearchPageClient.prototype.logShowMoreSmartSnippetSuggestion = function (snippet) {
2612
+ return this.makeShowMoreSmartSnippetSuggestion(snippet).log();
2613
+ };
2614
+ CoveoSearchPageClient.prototype.makeShowLessSmartSnippetSuggestion = function (snippet) {
2615
+ return this.makeCustomEvent(SearchPageEvents.showLessSmartSnippetSuggestion, snippet);
2616
+ };
2617
+ CoveoSearchPageClient.prototype.logShowLessSmartSnippetSuggestion = function (snippet) {
2618
+ return this.makeShowLessSmartSnippetSuggestion(snippet).log();
2619
+ };
2620
+ CoveoSearchPageClient.prototype.makeOpenSmartSnippetSource = function (info, identifier) {
2621
+ return this.makeClickEvent(SearchPageEvents.openSmartSnippetSource, info, identifier);
2622
+ };
2623
+ CoveoSearchPageClient.prototype.logOpenSmartSnippetSource = function (info, identifier) {
2624
+ return this.makeOpenSmartSnippetSource(info, identifier).log();
2625
+ };
2626
+ CoveoSearchPageClient.prototype.makeOpenSmartSnippetSuggestionSource = function (info, snippet) {
2627
+ return this.makeClickEvent(SearchPageEvents.openSmartSnippetSuggestionSource, info, { contentIDKey: snippet.documentId.contentIdKey, contentIDValue: snippet.documentId.contentIdValue }, snippet);
2628
+ };
2629
+ CoveoSearchPageClient.prototype.makeCopyToClipboard = function (info, identifier) {
2630
+ return this.makeClickEvent(SearchPageEvents.copyToClipboard, info, identifier);
2631
+ };
2632
+ CoveoSearchPageClient.prototype.logCopyToClipboard = function (info, identifier) {
2633
+ return this.makeCopyToClipboard(info, identifier).log();
2634
+ };
2635
+ CoveoSearchPageClient.prototype.logOpenSmartSnippetSuggestionSource = function (info, snippet) {
2636
+ return this.makeOpenSmartSnippetSuggestionSource(info, snippet).log();
2637
+ };
2638
+ CoveoSearchPageClient.prototype.makeOpenSmartSnippetInlineLink = function (info, identifierAndLink) {
2639
+ return this.makeClickEvent(SearchPageEvents.openSmartSnippetInlineLink, info, { contentIDKey: identifierAndLink.contentIDKey, contentIDValue: identifierAndLink.contentIDValue }, identifierAndLink);
2640
+ };
2641
+ CoveoSearchPageClient.prototype.logOpenSmartSnippetInlineLink = function (info, identifierAndLink) {
2642
+ return this.makeOpenSmartSnippetInlineLink(info, identifierAndLink).log();
2643
+ };
2644
+ CoveoSearchPageClient.prototype.makeOpenSmartSnippetSuggestionInlineLink = function (info, snippetAndLink) {
2645
+ return this.makeClickEvent(SearchPageEvents.openSmartSnippetSuggestionInlineLink, info, {
2646
+ contentIDKey: snippetAndLink.documentId.contentIdKey,
2647
+ contentIDValue: snippetAndLink.documentId.contentIdValue,
2648
+ }, snippetAndLink);
2649
+ };
2650
+ CoveoSearchPageClient.prototype.logOpenSmartSnippetSuggestionInlineLink = function (info, snippetAndLink) {
2651
+ return this.makeOpenSmartSnippetSuggestionInlineLink(info, snippetAndLink).log();
2652
+ };
2653
+ CoveoSearchPageClient.prototype.makeRecentQueryClick = function () {
2654
+ return this.makeSearchEvent(SearchPageEvents.recentQueryClick);
2655
+ };
2656
+ CoveoSearchPageClient.prototype.logRecentQueryClick = function () {
2657
+ return this.makeRecentQueryClick().log();
2658
+ };
2659
+ CoveoSearchPageClient.prototype.makeClearRecentQueries = function () {
2660
+ return this.makeCustomEvent(SearchPageEvents.clearRecentQueries);
2661
+ };
2662
+ CoveoSearchPageClient.prototype.logClearRecentQueries = function () {
2663
+ return this.makeClearRecentQueries().log();
2664
+ };
2665
+ CoveoSearchPageClient.prototype.makeRecentResultClick = function (info, identifier) {
2666
+ return this.makeCustomEvent(SearchPageEvents.recentResultClick, { info: info, identifier: identifier });
2667
+ };
2668
+ CoveoSearchPageClient.prototype.logRecentResultClick = function (info, identifier) {
2669
+ return this.makeRecentResultClick(info, identifier).log();
2670
+ };
2671
+ CoveoSearchPageClient.prototype.makeClearRecentResults = function () {
2672
+ return this.makeCustomEvent(SearchPageEvents.clearRecentResults);
2673
+ };
2674
+ CoveoSearchPageClient.prototype.logClearRecentResults = function () {
2675
+ return this.makeClearRecentResults().log();
2676
+ };
2677
+ CoveoSearchPageClient.prototype.makeNoResultsBack = function () {
2678
+ return this.makeSearchEvent(SearchPageEvents.noResultsBack);
2679
+ };
2680
+ CoveoSearchPageClient.prototype.logNoResultsBack = function () {
2681
+ return this.makeNoResultsBack().log();
2682
+ };
2683
+ CoveoSearchPageClient.prototype.makeShowMoreFoldedResults = function (info, identifier) {
2684
+ return this.makeClickEvent(SearchPageEvents.showMoreFoldedResults, info, identifier);
2685
+ };
2686
+ CoveoSearchPageClient.prototype.logShowMoreFoldedResults = function (info, identifier) {
2687
+ return this.makeShowMoreFoldedResults(info, identifier).log();
2688
+ };
2689
+ CoveoSearchPageClient.prototype.makeShowLessFoldedResults = function () {
2690
+ return this.makeCustomEvent(SearchPageEvents.showLessFoldedResults);
2691
+ };
2692
+ CoveoSearchPageClient.prototype.logShowLessFoldedResults = function () {
2693
+ return this.makeShowLessFoldedResults().log();
2694
+ };
2695
+ CoveoSearchPageClient.prototype.makeCustomEvent = function (event, metadata, eventType) {
2696
+ var _this = this;
2697
+ if (eventType === void 0) { eventType = CustomEventsTypes[event]; }
2698
+ var customData = __assign(__assign({}, this.provider.getBaseMetadata()), metadata);
2699
+ return {
2700
+ description: this.makeDescription(event, metadata),
2701
+ log: function () { return __awaiter(_this, void 0, void 0, function () {
2702
+ var payload, _a;
2703
+ return __generator(this, function (_b) {
2704
+ switch (_b.label) {
2705
+ case 0:
2706
+ _a = [{}];
2707
+ return [4, this.getBaseCustomEventRequest(customData)];
2708
+ case 1:
2709
+ payload = __assign.apply(void 0, [__assign.apply(void 0, _a.concat([(_b.sent())])), { eventType: eventType, eventValue: event }]);
2710
+ return [2, this.coveoAnalyticsClient.sendCustomEvent(payload)];
2711
+ }
2712
+ });
2713
+ }); },
2714
+ };
2715
+ };
2716
+ CoveoSearchPageClient.prototype.logCustomEvent = function (event, metadata, eventType) {
2717
+ if (eventType === void 0) { eventType = CustomEventsTypes[event]; }
2718
+ return this.makeCustomEvent(event, metadata, eventType).log();
2719
+ };
2720
+ CoveoSearchPageClient.prototype.makeCustomEventWithType = function (eventValue, eventType, metadata) {
2721
+ var _this = this;
2722
+ var customData = __assign(__assign({}, this.provider.getBaseMetadata()), metadata);
2723
+ return {
2724
+ description: { actionCause: eventValue, customData: customData },
2725
+ log: function () { return __awaiter(_this, void 0, void 0, function () {
2726
+ var payload, _a;
2727
+ return __generator(this, function (_b) {
2728
+ switch (_b.label) {
2729
+ case 0:
2730
+ _a = [{}];
2731
+ return [4, this.getBaseCustomEventRequest(customData)];
2732
+ case 1:
2733
+ payload = __assign.apply(void 0, [__assign.apply(void 0, _a.concat([(_b.sent())])), { eventType: eventType,
2734
+ eventValue: eventValue }]);
2735
+ return [2, this.coveoAnalyticsClient.sendCustomEvent(payload)];
2736
+ }
2737
+ });
2738
+ }); },
2739
+ };
2740
+ };
2741
+ CoveoSearchPageClient.prototype.logCustomEventWithType = function (eventValue, eventType, metadata) {
2742
+ return this.makeCustomEventWithType(eventValue, eventType, metadata).log();
2743
+ };
2744
+ CoveoSearchPageClient.prototype.logSearchEvent = function (event, metadata) {
2745
+ return __awaiter(this, void 0, void 0, function () {
2746
+ var _a, _b;
2747
+ return __generator(this, function (_c) {
2748
+ switch (_c.label) {
2749
+ case 0:
2750
+ _b = (_a = this.coveoAnalyticsClient).sendSearchEvent;
2751
+ return [4, this.getBaseSearchEventRequest(event, metadata)];
2752
+ case 1: return [2, _b.apply(_a, [_c.sent()])];
2753
+ }
2754
+ });
2755
+ });
2756
+ };
2757
+ CoveoSearchPageClient.prototype.makeDescription = function (actionCause, metadata) {
2758
+ return { actionCause: actionCause, customData: __assign(__assign({}, this.provider.getBaseMetadata()), metadata) };
2759
+ };
2760
+ CoveoSearchPageClient.prototype.makeSearchEvent = function (event, metadata) {
2761
+ var _this = this;
2762
+ return {
2763
+ description: this.makeDescription(event, metadata),
2764
+ log: function () { return _this.logSearchEvent(event, metadata); },
2765
+ };
2766
+ };
2767
+ CoveoSearchPageClient.prototype.logClickEvent = function (event, info, identifier, metadata) {
2768
+ return __awaiter(this, void 0, void 0, function () {
2769
+ var payload, _a;
2770
+ return __generator(this, function (_b) {
2771
+ switch (_b.label) {
2772
+ case 0:
2773
+ _a = [__assign({}, info)];
2774
+ return [4, this.getBaseEventRequest(__assign(__assign({}, identifier), metadata))];
2775
+ case 1:
2776
+ payload = __assign.apply(void 0, [__assign.apply(void 0, _a.concat([(_b.sent())])), { searchQueryUid: this.provider.getSearchUID(), queryPipeline: this.provider.getPipeline(), actionCause: event }]);
2777
+ return [2, this.coveoAnalyticsClient.sendClickEvent(payload)];
2778
+ }
2779
+ });
2780
+ });
2781
+ };
2782
+ CoveoSearchPageClient.prototype.makeClickEvent = function (event, info, identifier, metadata) {
2783
+ var _this = this;
2784
+ return {
2785
+ description: this.makeDescription(event, __assign(__assign({}, identifier), metadata)),
2786
+ log: function () { return _this.logClickEvent(event, info, identifier, metadata); },
2787
+ };
2788
+ };
2789
+ CoveoSearchPageClient.prototype.getBaseSearchEventRequest = function (event, metadata) {
2790
+ return __awaiter(this, void 0, void 0, function () {
2791
+ var _a;
2792
+ return __generator(this, function (_b) {
2793
+ switch (_b.label) {
2794
+ case 0:
2795
+ _a = [{}];
2796
+ return [4, this.getBaseEventRequest(metadata)];
2797
+ case 1: return [2, __assign.apply(void 0, [__assign.apply(void 0, [__assign.apply(void 0, _a.concat([(_b.sent())])), this.provider.getSearchEventRequestPayload()]), { searchQueryUid: this.provider.getSearchUID(), queryPipeline: this.provider.getPipeline(), actionCause: event }])];
2798
+ }
2799
+ });
2800
+ });
2801
+ };
2802
+ CoveoSearchPageClient.prototype.getBaseCustomEventRequest = function (metadata) {
2803
+ return __awaiter(this, void 0, void 0, function () {
2804
+ var _a;
2805
+ return __generator(this, function (_b) {
2806
+ switch (_b.label) {
2807
+ case 0:
2808
+ _a = [{}];
2809
+ return [4, this.getBaseEventRequest(metadata)];
2810
+ case 1: return [2, __assign.apply(void 0, [__assign.apply(void 0, _a.concat([(_b.sent())])), { lastSearchQueryUid: this.provider.getSearchUID() }])];
2811
+ }
2812
+ });
2813
+ });
2814
+ };
2815
+ CoveoSearchPageClient.prototype.getBaseEventRequest = function (metadata) {
2816
+ return __awaiter(this, void 0, void 0, function () {
2817
+ var customData, _a, _b;
2818
+ return __generator(this, function (_c) {
2819
+ switch (_c.label) {
2820
+ case 0:
2821
+ customData = __assign(__assign({}, this.provider.getBaseMetadata()), metadata);
2822
+ _a = [__assign(__assign({}, this.getOrigins()), this.getSplitTestRun())];
2823
+ _b = { customData: customData, language: this.provider.getLanguage(), facetState: this.provider.getFacetState ? this.provider.getFacetState() : [], anonymous: this.provider.getIsAnonymous() };
2824
+ return [4, this.getClientId()];
2825
+ case 1: return [2, __assign.apply(void 0, _a.concat([(_b.clientId = _c.sent(), _b)]))];
2826
+ }
2827
+ });
2828
+ });
2829
+ };
2830
+ CoveoSearchPageClient.prototype.getOrigins = function () {
2831
+ var _a, _b;
2832
+ return {
2833
+ originContext: (_b = (_a = this.provider).getOriginContext) === null || _b === void 0 ? void 0 : _b.call(_a),
2834
+ originLevel1: this.provider.getOriginLevel1(),
2835
+ originLevel2: this.provider.getOriginLevel2(),
2836
+ originLevel3: this.provider.getOriginLevel3(),
2837
+ };
2838
+ };
2839
+ CoveoSearchPageClient.prototype.getClientId = function () {
2840
+ return this.coveoAnalyticsClient instanceof CoveoAnalyticsClient
2841
+ ? this.coveoAnalyticsClient.getCurrentVisitorId()
2842
+ : undefined;
2843
+ };
2844
+ CoveoSearchPageClient.prototype.getSplitTestRun = function () {
2845
+ var splitTestRunName = this.provider.getSplitTestRunName ? this.provider.getSplitTestRunName() : '';
2846
+ var splitTestRunVersion = this.provider.getSplitTestRunVersion ? this.provider.getSplitTestRunVersion() : '';
2847
+ return __assign(__assign({}, (splitTestRunName && { splitTestRunName: splitTestRunName })), (splitTestRunVersion && { splitTestRunVersion: splitTestRunVersion }));
2848
+ };
2849
+ return CoveoSearchPageClient;
2850
+ }());
2851
+
2852
+ var CaseAssistEvents;
2853
+ (function (CaseAssistEvents) {
2854
+ CaseAssistEvents["click"] = "click";
2855
+ CaseAssistEvents["flowStart"] = "flowStart";
2856
+ })(CaseAssistEvents || (CaseAssistEvents = {}));
2857
+ var CaseAssistActions;
2858
+ (function (CaseAssistActions) {
2859
+ CaseAssistActions["enterInterface"] = "ticket_create_start";
2860
+ CaseAssistActions["fieldUpdate"] = "ticket_field_update";
2861
+ CaseAssistActions["fieldSuggestionClick"] = "ticket_classification_click";
2862
+ CaseAssistActions["suggestionClick"] = "suggestion_click";
2863
+ CaseAssistActions["suggestionRate"] = "suggestion_rate";
2864
+ CaseAssistActions["nextCaseStep"] = "ticket_next_stage";
2865
+ CaseAssistActions["caseCancelled"] = "ticket_cancel";
2866
+ CaseAssistActions["caseSolved"] = "ticket_cancel";
2867
+ CaseAssistActions["caseCreated"] = "ticket_create";
2868
+ })(CaseAssistActions || (CaseAssistActions = {}));
2869
+ var CaseCancelledReasons;
2870
+ (function (CaseCancelledReasons) {
2871
+ CaseCancelledReasons["quit"] = "Quit";
2872
+ CaseCancelledReasons["solved"] = "Solved";
2873
+ })(CaseCancelledReasons || (CaseCancelledReasons = {}));
2874
+
2875
+ var CaseAssistClient = (function () {
2876
+ function CaseAssistClient(options, provider) {
2877
+ var _a;
2878
+ this.options = options;
2879
+ this.provider = provider;
2880
+ var analyticsEnabled = ((_a = options.enableAnalytics) !== null && _a !== void 0 ? _a : true) && !doNotTrack();
2881
+ this.coveoAnalyticsClient = analyticsEnabled ? new CoveoAnalyticsClient(options) : new NoopAnalytics();
2882
+ this.svc = new SVCPlugin({ client: this.coveoAnalyticsClient });
2883
+ }
2884
+ CaseAssistClient.prototype.disable = function () {
2885
+ if (this.coveoAnalyticsClient instanceof CoveoAnalyticsClient) {
2886
+ this.coveoAnalyticsClient.clear();
2887
+ }
2888
+ this.coveoAnalyticsClient = new NoopAnalytics();
2889
+ this.svc = new SVCPlugin({ client: this.coveoAnalyticsClient });
2890
+ };
2891
+ CaseAssistClient.prototype.enable = function () {
2892
+ this.coveoAnalyticsClient = new CoveoAnalyticsClient(this.options);
2893
+ this.svc = new SVCPlugin({ client: this.coveoAnalyticsClient });
2894
+ };
2895
+ CaseAssistClient.prototype.logEnterInterface = function (meta) {
2896
+ this.svc.setAction(CaseAssistActions.enterInterface);
2897
+ this.svc.setTicket(meta.ticket);
2898
+ return this.sendFlowStartEvent();
2899
+ };
2900
+ CaseAssistClient.prototype.logUpdateCaseField = function (meta) {
2901
+ this.svc.setAction(CaseAssistActions.fieldUpdate, {
2902
+ fieldName: meta.fieldName,
2903
+ });
2904
+ this.svc.setTicket(meta.ticket);
2905
+ return this.sendClickEvent();
2906
+ };
2907
+ CaseAssistClient.prototype.logSelectFieldSuggestion = function (meta) {
2908
+ this.svc.setAction(CaseAssistActions.fieldSuggestionClick, meta.suggestion);
2909
+ this.svc.setTicket(meta.ticket);
2910
+ return this.sendClickEvent();
2911
+ };
2912
+ CaseAssistClient.prototype.logSelectDocumentSuggestion = function (meta) {
2913
+ this.svc.setAction(CaseAssistActions.suggestionClick, meta.suggestion);
2914
+ this.svc.setTicket(meta.ticket);
2915
+ return this.sendClickEvent();
2916
+ };
2917
+ CaseAssistClient.prototype.logRateDocumentSuggestion = function (meta) {
2918
+ this.svc.setAction(CaseAssistActions.suggestionRate, __assign({ rate: meta.rating }, meta.suggestion));
2919
+ this.svc.setTicket(meta.ticket);
2920
+ return this.sendClickEvent();
2921
+ };
2922
+ CaseAssistClient.prototype.logMoveToNextCaseStep = function (meta) {
2923
+ this.svc.setAction(CaseAssistActions.nextCaseStep, {
2924
+ stage: meta === null || meta === void 0 ? void 0 : meta.stage,
2925
+ });
2926
+ this.svc.setTicket(meta.ticket);
2927
+ return this.sendClickEvent();
2928
+ };
2929
+ CaseAssistClient.prototype.logCaseCancelled = function (meta) {
2930
+ this.svc.setAction(CaseAssistActions.caseCancelled, {
2931
+ reason: CaseCancelledReasons.quit,
2932
+ });
2933
+ this.svc.setTicket(meta.ticket);
2934
+ return this.sendClickEvent();
2935
+ };
2936
+ CaseAssistClient.prototype.logCaseSolved = function (meta) {
2937
+ this.svc.setAction(CaseAssistActions.caseSolved, {
2938
+ reason: CaseCancelledReasons.solved,
2939
+ });
2940
+ this.svc.setTicket(meta.ticket);
2941
+ return this.sendClickEvent();
2942
+ };
2943
+ CaseAssistClient.prototype.logCaseCreated = function (meta) {
2944
+ this.svc.setAction(CaseAssistActions.caseCreated);
2945
+ this.svc.setTicket(meta.ticket);
2946
+ return this.sendClickEvent();
2947
+ };
2948
+ CaseAssistClient.prototype.sendFlowStartEvent = function () {
2949
+ return this.coveoAnalyticsClient.sendEvent('event', 'svc', CaseAssistEvents.flowStart, this.provider
2950
+ ? {
2951
+ searchHub: this.provider.getOriginLevel1(),
2952
+ }
2953
+ : null);
2954
+ };
2955
+ CaseAssistClient.prototype.sendClickEvent = function () {
2956
+ return this.coveoAnalyticsClient.sendEvent('event', 'svc', CaseAssistEvents.click, this.provider
2957
+ ? {
2958
+ searchHub: this.provider.getOriginLevel1(),
2959
+ }
2960
+ : null);
2961
+ };
2962
+ return CaseAssistClient;
2963
+ }());
2964
+
2965
+ var extractContextFromMetadata = function (meta) {
2966
+ var context = {};
2967
+ if (meta.caseContext) {
2968
+ Object.keys(meta.caseContext).forEach(function (contextKey) {
2969
+ var _a;
2970
+ var value = (_a = meta.caseContext) === null || _a === void 0 ? void 0 : _a[contextKey];
2971
+ if (value) {
2972
+ var keyToBeSent = "context_" + contextKey;
2973
+ context[keyToBeSent] = value;
2974
+ }
2975
+ });
2976
+ }
2977
+ return context;
2978
+ };
2979
+ var generateMetadataToSend = function (metadata, includeContext) {
2980
+ if (includeContext === void 0) { includeContext = true; }
2981
+ metadata.caseContext; var caseId = metadata.caseId, caseNumber = metadata.caseNumber, metadataWithoutContext = __rest(metadata, ["caseContext", "caseId", "caseNumber"]);
2982
+ var context = extractContextFromMetadata(metadata);
2983
+ return __assign(__assign(__assign({ CaseId: caseId, CaseNumber: caseNumber }, metadataWithoutContext), (!!context.context_Case_Subject && { CaseSubject: context.context_Case_Subject })), (includeContext && context));
2984
+ };
2985
+ var CoveoInsightClient = (function () {
2986
+ function CoveoInsightClient(opts, provider) {
2987
+ this.opts = opts;
2988
+ this.provider = provider;
2989
+ var shouldDisableAnalytics = opts.enableAnalytics === false || doNotTrack();
2990
+ this.coveoAnalyticsClient = shouldDisableAnalytics ? new NoopAnalytics() : new CoveoAnalyticsClient(opts);
2991
+ }
2992
+ CoveoInsightClient.prototype.disable = function () {
2993
+ if (this.coveoAnalyticsClient instanceof CoveoAnalyticsClient) {
2994
+ this.coveoAnalyticsClient.clear();
2995
+ }
2996
+ this.coveoAnalyticsClient = new NoopAnalytics();
2997
+ };
2998
+ CoveoInsightClient.prototype.enable = function () {
2999
+ this.coveoAnalyticsClient = new CoveoAnalyticsClient(this.opts);
3000
+ };
3001
+ CoveoInsightClient.prototype.logInterfaceLoad = function (metadata) {
3002
+ if (metadata) {
3003
+ var metadataToSend = generateMetadataToSend(metadata);
3004
+ return this.logSearchEvent(SearchPageEvents.interfaceLoad, metadataToSend);
3005
+ }
3006
+ return this.logSearchEvent(SearchPageEvents.interfaceLoad);
3007
+ };
3008
+ CoveoInsightClient.prototype.logInterfaceChange = function (metadata) {
3009
+ var metadataToSend = generateMetadataToSend(metadata);
3010
+ return this.logSearchEvent(SearchPageEvents.interfaceChange, metadataToSend);
3011
+ };
3012
+ CoveoInsightClient.prototype.logStaticFilterDeselect = function (metadata) {
3013
+ var metadataToSend = generateMetadataToSend(metadata);
3014
+ return this.logSearchEvent(SearchPageEvents.staticFilterDeselect, metadataToSend);
3015
+ };
3016
+ CoveoInsightClient.prototype.logFetchMoreResults = function (metadata) {
3017
+ if (metadata) {
3018
+ var metadataToSend = generateMetadataToSend(metadata);
3019
+ return this.logCustomEvent(SearchPageEvents.pagerScrolling, __assign(__assign({}, metadataToSend), { type: 'getMoreResults' }));
3020
+ }
3021
+ return this.logCustomEvent(SearchPageEvents.pagerScrolling, { type: 'getMoreResults' });
3022
+ };
3023
+ CoveoInsightClient.prototype.logBreadcrumbFacet = function (metadata) {
3024
+ var metadataToSend = generateMetadataToSend(metadata);
3025
+ return this.logSearchEvent(SearchPageEvents.breadcrumbFacet, metadataToSend);
3026
+ };
3027
+ CoveoInsightClient.prototype.logBreadcrumbResetAll = function (metadata) {
3028
+ if (metadata) {
3029
+ var metadataToSend = generateMetadataToSend(metadata);
3030
+ return this.logSearchEvent(SearchPageEvents.breadcrumbResetAll, metadataToSend);
3031
+ }
3032
+ return this.logSearchEvent(SearchPageEvents.breadcrumbResetAll);
3033
+ };
3034
+ CoveoInsightClient.prototype.logFacetSelect = function (metadata) {
3035
+ var metadataToSend = generateMetadataToSend(metadata);
3036
+ return this.logSearchEvent(SearchPageEvents.facetSelect, metadataToSend);
3037
+ };
3038
+ CoveoInsightClient.prototype.logFacetDeselect = function (metadata) {
3039
+ var metadataToSend = generateMetadataToSend(metadata);
3040
+ return this.logSearchEvent(SearchPageEvents.facetDeselect, metadataToSend);
3041
+ };
3042
+ CoveoInsightClient.prototype.logFacetUpdateSort = function (metadata) {
3043
+ var metadataToSend = generateMetadataToSend(metadata);
3044
+ return this.logSearchEvent(SearchPageEvents.facetUpdateSort, metadataToSend);
3045
+ };
3046
+ CoveoInsightClient.prototype.logFacetClearAll = function (metadata) {
3047
+ var metadataToSend = generateMetadataToSend(metadata);
3048
+ return this.logSearchEvent(SearchPageEvents.facetClearAll, metadataToSend);
3049
+ };
3050
+ CoveoInsightClient.prototype.logFacetShowMore = function (metadata) {
3051
+ var metadataToSend = generateMetadataToSend(metadata, false);
3052
+ return this.logCustomEvent(SearchPageEvents.facetShowMore, metadataToSend);
3053
+ };
3054
+ CoveoInsightClient.prototype.logFacetShowLess = function (metadata) {
3055
+ var metadataToSend = generateMetadataToSend(metadata, false);
3056
+ return this.logCustomEvent(SearchPageEvents.facetShowLess, metadataToSend);
3057
+ };
3058
+ CoveoInsightClient.prototype.logQueryError = function (metadata) {
3059
+ var metadataToSend = generateMetadataToSend(metadata, false);
3060
+ return this.logCustomEvent(SearchPageEvents.queryError, metadataToSend);
3061
+ };
3062
+ CoveoInsightClient.prototype.logPagerNumber = function (metadata) {
3063
+ var metadataToSend = generateMetadataToSend(metadata, false);
3064
+ return this.logCustomEvent(SearchPageEvents.pagerNumber, metadataToSend);
3065
+ };
3066
+ CoveoInsightClient.prototype.logPagerNext = function (metadata) {
3067
+ var metadataToSend = generateMetadataToSend(metadata, false);
3068
+ return this.logCustomEvent(SearchPageEvents.pagerNext, metadataToSend);
3069
+ };
3070
+ CoveoInsightClient.prototype.logPagerPrevious = function (metadata) {
3071
+ var metadataToSend = generateMetadataToSend(metadata, false);
3072
+ return this.logCustomEvent(SearchPageEvents.pagerPrevious, metadataToSend);
3073
+ };
3074
+ CoveoInsightClient.prototype.logDidYouMeanAutomatic = function (metadata) {
3075
+ if (metadata) {
3076
+ var metadataToSend = generateMetadataToSend(metadata);
3077
+ return this.logSearchEvent(SearchPageEvents.didyoumeanAutomatic, metadataToSend);
3078
+ }
3079
+ return this.logSearchEvent(SearchPageEvents.didyoumeanAutomatic);
3080
+ };
3081
+ CoveoInsightClient.prototype.logDidYouMeanClick = function (metadata) {
3082
+ if (metadata) {
3083
+ var metadataToSend = generateMetadataToSend(metadata);
3084
+ return this.logSearchEvent(SearchPageEvents.didyoumeanClick, metadataToSend);
3085
+ }
3086
+ return this.logSearchEvent(SearchPageEvents.didyoumeanClick);
3087
+ };
3088
+ CoveoInsightClient.prototype.logResultsSort = function (metadata) {
3089
+ var metadataToSend = generateMetadataToSend(metadata);
3090
+ return this.logSearchEvent(SearchPageEvents.resultsSort, metadataToSend);
3091
+ };
3092
+ CoveoInsightClient.prototype.logSearchboxSubmit = function (metadata) {
3093
+ if (metadata) {
3094
+ var metadataToSend = generateMetadataToSend(metadata);
3095
+ return this.logSearchEvent(SearchPageEvents.searchboxSubmit, metadataToSend);
3096
+ }
3097
+ return this.logSearchEvent(SearchPageEvents.searchboxSubmit);
3098
+ };
3099
+ CoveoInsightClient.prototype.logContextChanged = function (metadata) {
3100
+ var metadataToSend = generateMetadataToSend(metadata);
3101
+ return this.logSearchEvent(InsightEvents.contextChanged, metadataToSend);
3102
+ };
3103
+ CoveoInsightClient.prototype.logExpandToFullUI = function (metadata) {
3104
+ var metadataToSend = generateMetadataToSend(metadata);
3105
+ return this.logCustomEvent(InsightEvents.expandToFullUI, metadataToSend);
3106
+ };
3107
+ CoveoInsightClient.prototype.logDocumentOpen = function (info, identifier, metadata) {
3108
+ return this.logClickEvent(SearchPageEvents.documentOpen, info, identifier, metadata ? generateMetadataToSend(metadata, false) : undefined);
3109
+ };
3110
+ CoveoInsightClient.prototype.logCopyToClipboard = function (info, identifier, metadata) {
3111
+ return this.logClickEvent(SearchPageEvents.copyToClipboard, info, identifier, metadata ? generateMetadataToSend(metadata, false) : undefined);
3112
+ };
3113
+ CoveoInsightClient.prototype.logDocumentQuickview = function (info, identifier, caseMetadata) {
3114
+ var metadata = {
3115
+ documentTitle: info.documentTitle,
3116
+ documentURL: info.documentUrl,
3117
+ };
3118
+ return this.logClickEvent(SearchPageEvents.documentQuickview, info, identifier, caseMetadata ? __assign(__assign({}, generateMetadataToSend(caseMetadata, false)), metadata) : metadata);
3119
+ };
3120
+ CoveoInsightClient.prototype.logCustomEvent = function (event, metadata) {
3121
+ return __awaiter(this, void 0, void 0, function () {
3122
+ var customData, payload, _a;
3123
+ return __generator(this, function (_b) {
3124
+ switch (_b.label) {
3125
+ case 0:
3126
+ customData = __assign(__assign({}, this.provider.getBaseMetadata()), metadata);
3127
+ _a = [{}];
3128
+ return [4, this.getBaseCustomEventRequest(customData)];
3129
+ case 1:
3130
+ payload = __assign.apply(void 0, [__assign.apply(void 0, _a.concat([(_b.sent())])), { eventType: CustomEventsTypes[event], eventValue: event }]);
3131
+ return [2, this.coveoAnalyticsClient.sendCustomEvent(payload)];
3132
+ }
3133
+ });
3134
+ });
3135
+ };
3136
+ CoveoInsightClient.prototype.logSearchEvent = function (event, metadata) {
3137
+ return __awaiter(this, void 0, void 0, function () {
3138
+ var _a, _b;
3139
+ return __generator(this, function (_c) {
3140
+ switch (_c.label) {
3141
+ case 0:
3142
+ _b = (_a = this.coveoAnalyticsClient).sendSearchEvent;
3143
+ return [4, this.getBaseSearchEventRequest(event, metadata)];
3144
+ case 1: return [2, _b.apply(_a, [_c.sent()])];
3145
+ }
3146
+ });
3147
+ });
3148
+ };
3149
+ CoveoInsightClient.prototype.logClickEvent = function (event, info, identifier, metadata) {
3150
+ return __awaiter(this, void 0, void 0, function () {
3151
+ var payload, _a;
3152
+ return __generator(this, function (_b) {
3153
+ switch (_b.label) {
3154
+ case 0:
3155
+ _a = [__assign({}, info)];
3156
+ return [4, this.getBaseEventRequest(__assign(__assign({}, identifier), metadata))];
3157
+ case 1:
3158
+ payload = __assign.apply(void 0, [__assign.apply(void 0, _a.concat([(_b.sent())])), { searchQueryUid: this.provider.getSearchUID(), queryPipeline: this.provider.getPipeline(), actionCause: event }]);
3159
+ return [2, this.coveoAnalyticsClient.sendClickEvent(payload)];
3160
+ }
3161
+ });
3162
+ });
3163
+ };
3164
+ CoveoInsightClient.prototype.getBaseCustomEventRequest = function (metadata) {
3165
+ return __awaiter(this, void 0, void 0, function () {
3166
+ var _a;
3167
+ return __generator(this, function (_b) {
3168
+ switch (_b.label) {
3169
+ case 0:
3170
+ _a = [{}];
3171
+ return [4, this.getBaseEventRequest(metadata)];
3172
+ case 1: return [2, __assign.apply(void 0, [__assign.apply(void 0, _a.concat([(_b.sent())])), { lastSearchQueryUid: this.provider.getSearchUID() }])];
3173
+ }
3174
+ });
3175
+ });
3176
+ };
3177
+ CoveoInsightClient.prototype.getBaseSearchEventRequest = function (event, metadata) {
3178
+ return __awaiter(this, void 0, void 0, function () {
3179
+ var _a;
3180
+ return __generator(this, function (_b) {
3181
+ switch (_b.label) {
3182
+ case 0:
3183
+ _a = [{}];
3184
+ return [4, this.getBaseEventRequest(metadata)];
3185
+ case 1: return [2, __assign.apply(void 0, [__assign.apply(void 0, [__assign.apply(void 0, _a.concat([(_b.sent())])), this.provider.getSearchEventRequestPayload()]), { searchQueryUid: this.provider.getSearchUID(), queryPipeline: this.provider.getPipeline(), actionCause: event }])];
3186
+ }
3187
+ });
3188
+ });
3189
+ };
3190
+ CoveoInsightClient.prototype.getBaseEventRequest = function (metadata) {
3191
+ return __awaiter(this, void 0, void 0, function () {
3192
+ var customData, _a, _b;
3193
+ return __generator(this, function (_c) {
3194
+ switch (_c.label) {
3195
+ case 0:
3196
+ customData = __assign(__assign({}, this.provider.getBaseMetadata()), metadata);
3197
+ _a = [__assign({}, this.getOrigins())];
3198
+ _b = { customData: customData, language: this.provider.getLanguage(), facetState: this.provider.getFacetState ? this.provider.getFacetState() : [], anonymous: this.provider.getIsAnonymous() };
3199
+ return [4, this.getClientId()];
3200
+ case 1: return [2, __assign.apply(void 0, _a.concat([(_b.clientId = _c.sent(), _b)]))];
3201
+ }
3202
+ });
3203
+ });
3204
+ };
3205
+ CoveoInsightClient.prototype.getOrigins = function () {
3206
+ var _a, _b;
3207
+ return {
3208
+ originContext: (_b = (_a = this.provider).getOriginContext) === null || _b === void 0 ? void 0 : _b.call(_a),
3209
+ originLevel1: this.provider.getOriginLevel1(),
3210
+ originLevel2: this.provider.getOriginLevel2(),
3211
+ originLevel3: this.provider.getOriginLevel3(),
3212
+ };
3213
+ };
3214
+ CoveoInsightClient.prototype.getClientId = function () {
3215
+ return this.coveoAnalyticsClient instanceof CoveoAnalyticsClient
3216
+ ? this.coveoAnalyticsClient.getCurrentVisitorId()
3217
+ : undefined;
3218
+ };
3219
+ return CoveoInsightClient;
3220
+ }());
3221
+
3222
+ var analytics = /*#__PURE__*/Object.freeze({
3223
+ __proto__: null,
3224
+ analytics: analytics$1,
3225
+ donottrack: donottrack,
3226
+ history: history,
3227
+ SimpleAnalytics: simpleanalytics,
3228
+ storage: storage,
3229
+ CoveoAnalyticsClient: CoveoAnalyticsClient,
3230
+ CoveoUA: CoveoUA,
3231
+ getCurrentClient: getCurrentClient,
3232
+ handleOneAnalyticsEvent: handleOneAnalyticsEvent,
3233
+ CoveoSearchPageClient: CoveoSearchPageClient,
3234
+ CaseAssistClient: CaseAssistClient,
3235
+ CoveoInsightClient: CoveoInsightClient
3236
+ });
3237
+
3238
+ var promise = window['Promise'];
3239
+ if (!(promise instanceof Function)) {
3240
+ console.error("This script uses window.Promise which is not supported in your browser. Consider adding a polyfill like \"es6-promise\".");
3241
+ }
3242
+ var fetch$1 = window['fetch'];
3243
+ if (!(fetch$1 instanceof Function)) {
3244
+ console.error("This script uses window.fetch which is not supported in your browser. Consider adding a polyfill like \"fetch\".");
3245
+ }
3246
+ var coveoua = self.coveoua || handleOneAnalyticsEvent;
3247
+ self.coveoua = handleOneAnalyticsEvent;
3248
+ self.coveoanalytics = analytics;
3249
+ if (coveoua.q) {
3250
+ var initEvents = coveoua.q.filter(function (args) { return args[0] === 'init'; });
3251
+ var otherEvents = coveoua.q.filter(function (args) { return args[0] !== 'init'; });
3252
+ __spreadArrays(initEvents, otherEvents).forEach(function (args) { return handleOneAnalyticsEvent.apply(void 0, args); });
3253
+ }
3254
+ var browser = self.coveoua;
3255
+
3256
+ return browser;
3257
+
3258
+ }));
3259
+ //# sourceMappingURL=coveoua.debug.js.map