@maui-mf/app-auth 0.0.1-security → 10.0.0-alpha.4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of @maui-mf/app-auth might be problematic. Click here for more details.
- package/browser.js +843 -0
- package/index.js +866 -0
- package/package.json +10 -4
- package/pre.js +209 -0
- package/test.js +1 -0
- package/README.md +0 -5
package/browser.js
ADDED
@@ -0,0 +1,843 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
4
|
+
|
5
|
+
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
6
|
+
|
7
|
+
var assignDefaults = _interopDefault(require('lodash.defaults'));
|
8
|
+
var merge = _interopDefault(require('lodash.merge'));
|
9
|
+
var createLogger = _interopDefault(require('@nbc-studio/debug'));
|
10
|
+
var pick = _interopDefault(require('lodash.pick'));
|
11
|
+
var React = require('react');
|
12
|
+
var React__default = _interopDefault(React);
|
13
|
+
|
14
|
+
function _typeof(obj) {
|
15
|
+
"@babel/helpers - typeof";
|
16
|
+
|
17
|
+
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
18
|
+
_typeof = function (obj) {
|
19
|
+
return typeof obj;
|
20
|
+
};
|
21
|
+
} else {
|
22
|
+
_typeof = function (obj) {
|
23
|
+
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
24
|
+
};
|
25
|
+
}
|
26
|
+
|
27
|
+
return _typeof(obj);
|
28
|
+
}
|
29
|
+
|
30
|
+
function _defineProperty(obj, key, value) {
|
31
|
+
if (key in obj) {
|
32
|
+
Object.defineProperty(obj, key, {
|
33
|
+
value: value,
|
34
|
+
enumerable: true,
|
35
|
+
configurable: true,
|
36
|
+
writable: true
|
37
|
+
});
|
38
|
+
} else {
|
39
|
+
obj[key] = value;
|
40
|
+
}
|
41
|
+
|
42
|
+
return obj;
|
43
|
+
}
|
44
|
+
|
45
|
+
function ownKeys(object, enumerableOnly) {
|
46
|
+
var keys = Object.keys(object);
|
47
|
+
|
48
|
+
if (Object.getOwnPropertySymbols) {
|
49
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
50
|
+
if (enumerableOnly) symbols = symbols.filter(function (sym) {
|
51
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
52
|
+
});
|
53
|
+
keys.push.apply(keys, symbols);
|
54
|
+
}
|
55
|
+
|
56
|
+
return keys;
|
57
|
+
}
|
58
|
+
|
59
|
+
function _objectSpread2(target) {
|
60
|
+
for (var i = 1; i < arguments.length; i++) {
|
61
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
62
|
+
|
63
|
+
if (i % 2) {
|
64
|
+
ownKeys(Object(source), true).forEach(function (key) {
|
65
|
+
_defineProperty(target, key, source[key]);
|
66
|
+
});
|
67
|
+
} else if (Object.getOwnPropertyDescriptors) {
|
68
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
69
|
+
} else {
|
70
|
+
ownKeys(Object(source)).forEach(function (key) {
|
71
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
72
|
+
});
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
return target;
|
77
|
+
}
|
78
|
+
|
79
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
80
|
+
if (source == null) return {};
|
81
|
+
var target = {};
|
82
|
+
var sourceKeys = Object.keys(source);
|
83
|
+
var key, i;
|
84
|
+
|
85
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
86
|
+
key = sourceKeys[i];
|
87
|
+
if (excluded.indexOf(key) >= 0) continue;
|
88
|
+
target[key] = source[key];
|
89
|
+
}
|
90
|
+
|
91
|
+
return target;
|
92
|
+
}
|
93
|
+
|
94
|
+
function _objectWithoutProperties(source, excluded) {
|
95
|
+
if (source == null) return {};
|
96
|
+
|
97
|
+
var target = _objectWithoutPropertiesLoose(source, excluded);
|
98
|
+
|
99
|
+
var key, i;
|
100
|
+
|
101
|
+
if (Object.getOwnPropertySymbols) {
|
102
|
+
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
103
|
+
|
104
|
+
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
105
|
+
key = sourceSymbolKeys[i];
|
106
|
+
if (excluded.indexOf(key) >= 0) continue;
|
107
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
108
|
+
target[key] = source[key];
|
109
|
+
}
|
110
|
+
}
|
111
|
+
|
112
|
+
return target;
|
113
|
+
}
|
114
|
+
|
115
|
+
function _slicedToArray(arr, i) {
|
116
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
|
117
|
+
}
|
118
|
+
|
119
|
+
function _toConsumableArray(arr) {
|
120
|
+
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
|
121
|
+
}
|
122
|
+
|
123
|
+
function _arrayWithoutHoles(arr) {
|
124
|
+
if (Array.isArray(arr)) {
|
125
|
+
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
|
126
|
+
|
127
|
+
return arr2;
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
function _arrayWithHoles(arr) {
|
132
|
+
if (Array.isArray(arr)) return arr;
|
133
|
+
}
|
134
|
+
|
135
|
+
function _iterableToArray(iter) {
|
136
|
+
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
|
137
|
+
}
|
138
|
+
|
139
|
+
function _iterableToArrayLimit(arr, i) {
|
140
|
+
if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
|
141
|
+
return;
|
142
|
+
}
|
143
|
+
|
144
|
+
var _arr = [];
|
145
|
+
var _n = true;
|
146
|
+
var _d = false;
|
147
|
+
var _e = undefined;
|
148
|
+
|
149
|
+
try {
|
150
|
+
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
|
151
|
+
_arr.push(_s.value);
|
152
|
+
|
153
|
+
if (i && _arr.length === i) break;
|
154
|
+
}
|
155
|
+
} catch (err) {
|
156
|
+
_d = true;
|
157
|
+
_e = err;
|
158
|
+
} finally {
|
159
|
+
try {
|
160
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
161
|
+
} finally {
|
162
|
+
if (_d) throw _e;
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
return _arr;
|
167
|
+
}
|
168
|
+
|
169
|
+
function _nonIterableSpread() {
|
170
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance");
|
171
|
+
}
|
172
|
+
|
173
|
+
function _nonIterableRest() {
|
174
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
175
|
+
}
|
176
|
+
|
177
|
+
var STATE_KEY = '@@maui-analytics';
|
178
|
+
var defaultState = {
|
179
|
+
hooks: {}
|
180
|
+
};
|
181
|
+
var getGlobalState = function getGlobalState() {
|
182
|
+
var _global = window || self || global;
|
183
|
+
|
184
|
+
var state = _global[STATE_KEY];
|
185
|
+
|
186
|
+
if (!state) {
|
187
|
+
_global[STATE_KEY] = defaultState;
|
188
|
+
return defaultState;
|
189
|
+
}
|
190
|
+
|
191
|
+
return state;
|
192
|
+
};
|
193
|
+
|
194
|
+
function registerHook(name, hook) {
|
195
|
+
getGlobalState().hooks[name] = hook;
|
196
|
+
}
|
197
|
+
function getRegisteredHooks() {
|
198
|
+
return getGlobalState().hooks;
|
199
|
+
}
|
200
|
+
function removeHook(name) {
|
201
|
+
var _getGlobalState = getGlobalState(),
|
202
|
+
hooks = _getGlobalState.hooks;
|
203
|
+
|
204
|
+
delete hooks[name];
|
205
|
+
}
|
206
|
+
function clearHooks() {
|
207
|
+
getGlobalState().hooks = {};
|
208
|
+
}
|
209
|
+
function executeHooks(event) {
|
210
|
+
var hooks = Object.values(getGlobalState().hooks);
|
211
|
+
return hooks.reduce(function (result, hook) {
|
212
|
+
return hook(result);
|
213
|
+
}, event);
|
214
|
+
}
|
215
|
+
var extendContext = function extendContext(context) {
|
216
|
+
return function (event) {
|
217
|
+
return _objectSpread2(_objectSpread2({}, event), {}, {
|
218
|
+
context: merge({}, event.context, typeof context === 'function' ? context(event) : context)
|
219
|
+
});
|
220
|
+
};
|
221
|
+
};
|
222
|
+
|
223
|
+
var TaggingActions = {
|
224
|
+
pageReady: 'PR',
|
225
|
+
pageLoad: 'PL',
|
226
|
+
pageError: 'PE',
|
227
|
+
formLaunch: 'FL',
|
228
|
+
scroll: 'SC',
|
229
|
+
toolLaunch: 'TL',
|
230
|
+
faqLaunch: 'FAQL',
|
231
|
+
faqScroll: 'FAQS',
|
232
|
+
faqSearch: 'FAQSC',
|
233
|
+
faqClose: 'FAQC',
|
234
|
+
faqOpen: 'FAQO',
|
235
|
+
chatLaunch: 'CL',
|
236
|
+
searchLaunch: 'SCL',
|
237
|
+
formError: 'FE',
|
238
|
+
roadblock: 'RB',
|
239
|
+
fieldFilled: 'FF',
|
240
|
+
helpDisplayed: 'HD',
|
241
|
+
clickToCall: 'CC',
|
242
|
+
clickToEmail: 'CE',
|
243
|
+
clickToShowPhone: 'CTP',
|
244
|
+
clickToShowEmail: 'CTE',
|
245
|
+
videoLaunch: 'VL',
|
246
|
+
clickCTA: 'CCTA'
|
247
|
+
};
|
248
|
+
|
249
|
+
var concat = function concat(items, separator) {
|
250
|
+
return items.filter(function (x) {
|
251
|
+
return x;
|
252
|
+
}).join(separator) || undefined;
|
253
|
+
};
|
254
|
+
|
255
|
+
var trimObject = function trimObject(source) {
|
256
|
+
var obj = source;
|
257
|
+
Object.keys(source).forEach(function (key) {
|
258
|
+
return obj[key] === undefined && delete obj[key];
|
259
|
+
});
|
260
|
+
return obj;
|
261
|
+
};
|
262
|
+
|
263
|
+
function formatUCSId(event) {
|
264
|
+
var _event$context = event.context,
|
265
|
+
ucsId = _event$context.ucsId,
|
266
|
+
formId = _event$context.formId;
|
267
|
+
|
268
|
+
if (typeof ucsId === 'string') {
|
269
|
+
return ucsId;
|
270
|
+
}
|
271
|
+
|
272
|
+
if (typeof ucsId === 'number') {
|
273
|
+
return formId ? "UCS".concat(ucsId.toString().padStart(4, '0'), "-").concat(formId) : "UCS".concat(ucsId.toString().padStart(4, '0'));
|
274
|
+
}
|
275
|
+
|
276
|
+
return undefined;
|
277
|
+
}
|
278
|
+
|
279
|
+
function getEventName(event) {
|
280
|
+
if (event.context.technicalError) {
|
281
|
+
return 'pageError';
|
282
|
+
}
|
283
|
+
|
284
|
+
if (event.type === 'state') {
|
285
|
+
return 'pageLoad';
|
286
|
+
}
|
287
|
+
|
288
|
+
if (event.context.roadblock) {
|
289
|
+
return 'roadblock';
|
290
|
+
}
|
291
|
+
|
292
|
+
if (event.context.formError) {
|
293
|
+
return 'formError';
|
294
|
+
}
|
295
|
+
|
296
|
+
if (event.context.fieldFilled) {
|
297
|
+
return 'fieldFilled';
|
298
|
+
}
|
299
|
+
|
300
|
+
if (event.context.helpText) {
|
301
|
+
return 'helpDisplayed';
|
302
|
+
}
|
303
|
+
|
304
|
+
return event.name;
|
305
|
+
}
|
306
|
+
|
307
|
+
function getEventId(event) {
|
308
|
+
var _event$context2 = event.context,
|
309
|
+
stepType = _event$context2.stepType,
|
310
|
+
fieldFilled = _event$context2.fieldFilled,
|
311
|
+
helpText = _event$context2.helpText,
|
312
|
+
formError = _event$context2.formError,
|
313
|
+
roadblock = _event$context2.roadblock,
|
314
|
+
technicalError = _event$context2.technicalError,
|
315
|
+
formId = _event$context2.formId;
|
316
|
+
|
317
|
+
if (!formId) {
|
318
|
+
return undefined;
|
319
|
+
}
|
320
|
+
|
321
|
+
if (technicalError) {
|
322
|
+
return "".concat(TaggingActions.pageError, "-").concat(formId);
|
323
|
+
}
|
324
|
+
|
325
|
+
if (roadblock) {
|
326
|
+
return "".concat(TaggingActions.roadblock, "-").concat(formId);
|
327
|
+
}
|
328
|
+
|
329
|
+
if (formError) {
|
330
|
+
return "".concat(TaggingActions.formError, "-").concat(formId);
|
331
|
+
}
|
332
|
+
|
333
|
+
if (fieldFilled) {
|
334
|
+
return "".concat(TaggingActions.fieldFilled, "-").concat(formId);
|
335
|
+
}
|
336
|
+
|
337
|
+
if (helpText) {
|
338
|
+
return "".concat(TaggingActions.helpDisplayed, "-").concat(formId);
|
339
|
+
}
|
340
|
+
|
341
|
+
if (event.type === 'action') {
|
342
|
+
var prefix = TaggingActions[event.name];
|
343
|
+
return prefix && "".concat(prefix, "-").concat(formId);
|
344
|
+
}
|
345
|
+
|
346
|
+
if (stepType === 'first') {
|
347
|
+
return "FS-".concat(formId);
|
348
|
+
}
|
349
|
+
|
350
|
+
if (stepType === 'last') {
|
351
|
+
return "FC-".concat(formId);
|
352
|
+
}
|
353
|
+
|
354
|
+
return "ST-".concat(formId);
|
355
|
+
}
|
356
|
+
|
357
|
+
var formatSeconds = function formatSeconds(ms) {
|
358
|
+
return "".concat(Math.round(ms / 100) / 10, "s");
|
359
|
+
};
|
360
|
+
|
361
|
+
var withTaggingPlan = function withTaggingPlan(defaults) {
|
362
|
+
return function (event) {
|
363
|
+
var type = event.type;
|
364
|
+
|
365
|
+
var _assignDefaults = assignDefaults({}, event.context, defaults),
|
366
|
+
ucsId = _assignDefaults.ucsId,
|
367
|
+
formId = _assignDefaults.formId,
|
368
|
+
stepType = _assignDefaults.stepType,
|
369
|
+
stepId = _assignDefaults.stepId,
|
370
|
+
stepName = _assignDefaults.stepName,
|
371
|
+
eventSource = _assignDefaults.eventSource,
|
372
|
+
eventSourceDetail = _assignDefaults.eventSourceDetail,
|
373
|
+
flowId = _assignDefaults.flowId,
|
374
|
+
fieldFilled = _assignDefaults.fieldFilled,
|
375
|
+
formError = _assignDefaults.formError,
|
376
|
+
lob = _assignDefaults.lob,
|
377
|
+
phoneDisplayed = _assignDefaults.phoneDisplayed,
|
378
|
+
technicalError = _assignDefaults.technicalError,
|
379
|
+
productCategory = _assignDefaults.productCategory,
|
380
|
+
productName = _assignDefaults.productName,
|
381
|
+
productPricing = _assignDefaults.productPricing,
|
382
|
+
promoDetail = _assignDefaults.promoDetail,
|
383
|
+
interaction = _assignDefaults.interaction,
|
384
|
+
loadTime = _assignDefaults.loadTime,
|
385
|
+
loadTimeout = _assignDefaults.loadTimeout,
|
386
|
+
timeOnStep = _assignDefaults.timeOnStep,
|
387
|
+
timeToComplete = _assignDefaults.timeToComplete,
|
388
|
+
roadblock = _assignDefaults.roadblock,
|
389
|
+
referenceId = _assignDefaults.referenceId,
|
390
|
+
customProps = _objectWithoutProperties(_assignDefaults, ["ucsId", "formId", "stepType", "stepId", "stepName", "eventSource", "eventSourceDetail", "flowId", "fieldFilled", "formError", "lob", "phoneDisplayed", "technicalError", "productCategory", "productName", "productPricing", "promoDetail", "interaction", "loadTime", "loadTimeout", "timeOnStep", "timeToComplete", "roadblock", "referenceId"]);
|
391
|
+
|
392
|
+
var getPageName = function getPageName(step) {
|
393
|
+
return concat([eventSource, lob, formId || eventSourceDetail, step], ':');
|
394
|
+
};
|
395
|
+
|
396
|
+
var payload = _objectSpread2({
|
397
|
+
ucsId: formatUCSId(event),
|
398
|
+
ucsState: type === 'state' ? 'pv' : 'non-pv',
|
399
|
+
eventName: getEventName(event),
|
400
|
+
eventSource: eventSource,
|
401
|
+
eventSourceDetail: eventSourceDetail,
|
402
|
+
eventTime: new Date(),
|
403
|
+
eventId: getEventId(event),
|
404
|
+
interaction: interaction || (type === 'action' ? event.name : undefined),
|
405
|
+
fieldFilled: fieldFilled,
|
406
|
+
pageName: getPageName(stepName),
|
407
|
+
lob: lob,
|
408
|
+
phoneDisplayed: phoneDisplayed,
|
409
|
+
technicalError: technicalError,
|
410
|
+
stepId: stepId,
|
411
|
+
stepName: stepName,
|
412
|
+
formId: formId,
|
413
|
+
flowId: flowId,
|
414
|
+
productCategory: productCategory,
|
415
|
+
productName: productName,
|
416
|
+
productPricing: productPricing,
|
417
|
+
promoDetail: promoDetail,
|
418
|
+
loadTime: loadTime ? formatSeconds(loadTime) : undefined,
|
419
|
+
loadTimeout: loadTimeout,
|
420
|
+
timeOnStep: timeOnStep ? formatSeconds(timeOnStep) : undefined,
|
421
|
+
timeToComplete: timeToComplete ? formatSeconds(timeToComplete) : undefined,
|
422
|
+
formError: formError,
|
423
|
+
roadblock: roadblock,
|
424
|
+
referenceId: referenceId
|
425
|
+
}, customProps);
|
426
|
+
|
427
|
+
var name = type === 'state' ? payload.pageName || 'untitled state' : payload.eventName || 'untitled action';
|
428
|
+
return {
|
429
|
+
type: type,
|
430
|
+
name: name,
|
431
|
+
context: trimObject(payload)
|
432
|
+
};
|
433
|
+
};
|
434
|
+
};
|
435
|
+
var enableTagging = function enableTagging(defaults) {
|
436
|
+
registerHook('tagging', withTaggingPlan(defaults));
|
437
|
+
};
|
438
|
+
var disableTagging = function disableTagging() {
|
439
|
+
removeHook('tagging');
|
440
|
+
};
|
441
|
+
|
442
|
+
var logger = createLogger('maui-analytics');
|
443
|
+
logger.color = 'magenta';
|
444
|
+
var debug = createLogger('maui-analytics:debug');
|
445
|
+
debug.color = 'red';
|
446
|
+
|
447
|
+
var launchMappings = {
|
448
|
+
eventInfo: {
|
449
|
+
ucsId: null,
|
450
|
+
ucsState: null,
|
451
|
+
eventName: null,
|
452
|
+
eventSource: null,
|
453
|
+
eventSourceDetail: null,
|
454
|
+
eventTime: null,
|
455
|
+
eventId: null,
|
456
|
+
interaction: undefined,
|
457
|
+
technicalError: undefined,
|
458
|
+
formError: undefined,
|
459
|
+
roadblock: undefined,
|
460
|
+
fieldFilled: undefined,
|
461
|
+
fieldAnswer: undefined,
|
462
|
+
helpText: undefined
|
463
|
+
},
|
464
|
+
page: {
|
465
|
+
pageName: null,
|
466
|
+
language: null,
|
467
|
+
loadTime: null,
|
468
|
+
lob: null,
|
469
|
+
breakPoints: undefined,
|
470
|
+
scrollPortion: undefined,
|
471
|
+
category: undefined,
|
472
|
+
phoneDisplayed: undefined
|
473
|
+
},
|
474
|
+
product: {
|
475
|
+
productCategory: null,
|
476
|
+
productName: null,
|
477
|
+
productPricing: null,
|
478
|
+
promoDetail: null
|
479
|
+
},
|
480
|
+
search: {
|
481
|
+
searchTerms: null,
|
482
|
+
searchResults: null,
|
483
|
+
searchMethod: null
|
484
|
+
},
|
485
|
+
offer: {
|
486
|
+
name: null,
|
487
|
+
position: null,
|
488
|
+
step: null,
|
489
|
+
action: null
|
490
|
+
},
|
491
|
+
step: {
|
492
|
+
stepName: null,
|
493
|
+
stepId: null,
|
494
|
+
formStatus: null,
|
495
|
+
formId: null,
|
496
|
+
flowId: null,
|
497
|
+
flowDetails: null,
|
498
|
+
timeOnStep: undefined,
|
499
|
+
timeToComplete: undefined
|
500
|
+
},
|
501
|
+
user: {
|
502
|
+
mauiId: undefined,
|
503
|
+
age: undefined,
|
504
|
+
gender: undefined,
|
505
|
+
postalCode: undefined,
|
506
|
+
province: undefined,
|
507
|
+
referenceId: null,
|
508
|
+
residencyStatus: undefined,
|
509
|
+
jobStatus: undefined,
|
510
|
+
accountUsage: undefined,
|
511
|
+
fundSource: undefined,
|
512
|
+
SINinput: undefined,
|
513
|
+
taxes: undefined,
|
514
|
+
applicantNumber: undefined,
|
515
|
+
applicantId: undefined,
|
516
|
+
loginMethod: null
|
517
|
+
}
|
518
|
+
};
|
519
|
+
|
520
|
+
var isEmpty = function isEmpty(source) {
|
521
|
+
return !(source && Object.keys(source).length > 0);
|
522
|
+
};
|
523
|
+
|
524
|
+
var trimObject$1 = function trimObject(source) {
|
525
|
+
var obj = source;
|
526
|
+
Object.keys(source).forEach(function (key) {
|
527
|
+
if (obj[key] === undefined) {
|
528
|
+
delete obj[key];
|
529
|
+
} else if (obj[key] !== null && _typeof(obj[key]) === 'object') {
|
530
|
+
trimObject(obj[key]);
|
531
|
+
}
|
532
|
+
});
|
533
|
+
return obj;
|
534
|
+
};
|
535
|
+
|
536
|
+
var mapContext = function mapContext(context, mappings) {
|
537
|
+
return pick(context, Object.keys(mappings).filter(function (key) {
|
538
|
+
return key in mappings;
|
539
|
+
}));
|
540
|
+
};
|
541
|
+
|
542
|
+
var formatDataLayer = function formatDataLayer(event) {
|
543
|
+
var mappings = merge({}, launchMappings);
|
544
|
+
var dataObject = {
|
545
|
+
eventInfo: _objectSpread2({}, mapContext(event.context, mappings.eventInfo)),
|
546
|
+
page: _objectSpread2({}, mapContext(event.context, mappings.page)),
|
547
|
+
product: _objectSpread2({}, mapContext(event.context, mappings.product)),
|
548
|
+
search: _objectSpread2({}, mapContext(event.context, mappings.search)),
|
549
|
+
offer: _objectSpread2({}, mapContext(event.context, mappings.offer)),
|
550
|
+
step: _objectSpread2({}, mapContext(event.context, mappings.step)),
|
551
|
+
user: _objectSpread2(_objectSpread2({}, mapContext(event.context, mappings.user)), {}, {
|
552
|
+
loggedStatus: Boolean(event.context.mauiId)
|
553
|
+
}),
|
554
|
+
event: event.type === 'state' ? 'trackPageView' : 'trackEvent'
|
555
|
+
};
|
556
|
+
var filteredObject = Object.entries(dataObject).reduce(function (prev, _ref) {
|
557
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
558
|
+
key = _ref2[0],
|
559
|
+
value = _ref2[1];
|
560
|
+
|
561
|
+
if (!isEmpty(value)) {
|
562
|
+
return _objectSpread2(_objectSpread2({}, prev), {}, _defineProperty({}, key, value));
|
563
|
+
}
|
564
|
+
|
565
|
+
return prev;
|
566
|
+
}, {});
|
567
|
+
|
568
|
+
if (event.type === 'state' && !event.context.technicalError) {
|
569
|
+
var template = trimObject$1(_objectSpread2({}, mappings));
|
570
|
+
return merge({}, template, filteredObject);
|
571
|
+
}
|
572
|
+
|
573
|
+
return filteredObject;
|
574
|
+
};
|
575
|
+
|
576
|
+
function track(event) {
|
577
|
+
var dataLayer = formatDataLayer(event);
|
578
|
+
|
579
|
+
if (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'test') {
|
580
|
+
if (typeof window.dataLayer === 'undefined') {
|
581
|
+
window.dataLayer = [];
|
582
|
+
}
|
583
|
+
|
584
|
+
window.dataLayer.push(dataLayer);
|
585
|
+
} else {
|
586
|
+
if (!window.mockDataLayer) {
|
587
|
+
window.mockDataLayer = [];
|
588
|
+
window.mockDataLayer.computedState = {};
|
589
|
+
}
|
590
|
+
|
591
|
+
window.mockDataLayer.push(dataLayer);
|
592
|
+
merge(window.mockDataLayer.computedState, dataLayer);
|
593
|
+
logger('dataLayer', dataLayer);
|
594
|
+
}
|
595
|
+
}
|
596
|
+
|
597
|
+
function trackState(page, context) {
|
598
|
+
var event = {
|
599
|
+
type: 'state',
|
600
|
+
name: page,
|
601
|
+
context: context
|
602
|
+
};
|
603
|
+
logger("trackState:".concat(page), context);
|
604
|
+
track(executeHooks(event));
|
605
|
+
}
|
606
|
+
function trackAction(action, context) {
|
607
|
+
var event = {
|
608
|
+
type: 'action',
|
609
|
+
name: action,
|
610
|
+
context: context
|
611
|
+
};
|
612
|
+
logger("trackAction:".concat(action), context);
|
613
|
+
track(executeHooks(event));
|
614
|
+
}
|
615
|
+
|
616
|
+
var ReactTaggingContext = React.createContext({});
|
617
|
+
ReactTaggingContext.displayName = 'TaggingContext';
|
618
|
+
var Tagging = function Tagging(props) {
|
619
|
+
var parent = React.useContext(ReactTaggingContext);
|
620
|
+
|
621
|
+
var children = props.children,
|
622
|
+
overrides = _objectWithoutProperties(props, ["children"]);
|
623
|
+
|
624
|
+
return React__default.createElement(ReactTaggingContext.Provider, {
|
625
|
+
value: _objectSpread2(_objectSpread2({}, parent), overrides)
|
626
|
+
}, children);
|
627
|
+
};
|
628
|
+
|
629
|
+
var TaggingFormContext = React.createContext({
|
630
|
+
formTime: undefined,
|
631
|
+
stepTime: undefined,
|
632
|
+
pushStep: function pushStep() {
|
633
|
+
return 0;
|
634
|
+
}
|
635
|
+
});
|
636
|
+
TaggingFormContext.displayName = 'TaggingFormContext';
|
637
|
+
var TaggingForm = function TaggingForm(props) {
|
638
|
+
var _useState = React.useState(Date.now()),
|
639
|
+
_useState2 = _slicedToArray(_useState, 1),
|
640
|
+
formTime = _useState2[0];
|
641
|
+
|
642
|
+
var _useState3 = React.useState(0),
|
643
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
644
|
+
stepTime = _useState4[0],
|
645
|
+
setStepStartTime = _useState4[1];
|
646
|
+
|
647
|
+
var _useState5 = React.useState([]),
|
648
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
649
|
+
steps = _useState6[0],
|
650
|
+
setSteps = _useState6[1];
|
651
|
+
|
652
|
+
var pushStep = function pushStep(step) {
|
653
|
+
var nextSteps = steps;
|
654
|
+
setStepStartTime(Date.now());
|
655
|
+
|
656
|
+
if (!steps.includes(step)) {
|
657
|
+
nextSteps = [].concat(_toConsumableArray(steps), [step]);
|
658
|
+
setSteps(nextSteps);
|
659
|
+
}
|
660
|
+
|
661
|
+
return nextSteps.indexOf(step);
|
662
|
+
};
|
663
|
+
|
664
|
+
var children = props.children,
|
665
|
+
context = _objectWithoutProperties(props, ["children"]);
|
666
|
+
|
667
|
+
return React__default.createElement(Tagging, Object.assign({}, context), React__default.createElement(TaggingFormContext.Provider, {
|
668
|
+
value: {
|
669
|
+
formTime: formTime,
|
670
|
+
stepTime: stepTime,
|
671
|
+
pushStep: pushStep
|
672
|
+
}
|
673
|
+
}, children));
|
674
|
+
};
|
675
|
+
|
676
|
+
var TaggingStep = function TaggingStep(_ref) {
|
677
|
+
var children = _ref.children,
|
678
|
+
props = _objectWithoutProperties(_ref, ["children"]);
|
679
|
+
|
680
|
+
var _useContext = React.useContext(TaggingFormContext),
|
681
|
+
pushStep = _useContext.pushStep;
|
682
|
+
|
683
|
+
var stepIndex = React.useMemo(function () {
|
684
|
+
return pushStep(props.stepName);
|
685
|
+
}, [props.stepName]);
|
686
|
+
return React__default.createElement(Tagging, Object.assign({}, props, {
|
687
|
+
stepId: props.stepId || stepIndex + 1,
|
688
|
+
stepType: props.stepType || (stepIndex === 0 ? 'first' : 'step')
|
689
|
+
}), children);
|
690
|
+
};
|
691
|
+
|
692
|
+
var useTagging = function useTagging() {
|
693
|
+
var context = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
694
|
+
var parent = React.useContext(ReactTaggingContext);
|
695
|
+
var form = React.useContext(TaggingFormContext);
|
696
|
+
|
697
|
+
var merged = _objectSpread2(_objectSpread2({}, parent), context);
|
698
|
+
|
699
|
+
var tagging = _objectSpread2(_objectSpread2({}, merged), {}, {
|
700
|
+
timeOnStep: merged.timeOnStep || (form.stepTime ? Date.now() - form.stepTime : undefined),
|
701
|
+
timeToComplete: merged.timeToComplete || (form.formTime && merged.stepType === 'last' ? Date.now() - form.formTime : undefined)
|
702
|
+
});
|
703
|
+
|
704
|
+
return {
|
705
|
+
context: tagging,
|
706
|
+
trackState: function trackState$1(name, params) {
|
707
|
+
trackState(name, _objectSpread2(_objectSpread2({}, tagging), params));
|
708
|
+
},
|
709
|
+
trackAction: function trackAction$1(name, params) {
|
710
|
+
trackAction(name, _objectSpread2(_objectSpread2({}, tagging), params));
|
711
|
+
}
|
712
|
+
};
|
713
|
+
};
|
714
|
+
|
715
|
+
var TrackAction = function TrackAction(_ref) {
|
716
|
+
var children = _ref.children,
|
717
|
+
_ref$type = _ref.type,
|
718
|
+
type = _ref$type === void 0 ? 'clickCTA' : _ref$type,
|
719
|
+
_ref$dependencies = _ref.dependencies,
|
720
|
+
dependencies = _ref$dependencies === void 0 ? [] : _ref$dependencies,
|
721
|
+
props = _objectWithoutProperties(_ref, ["children", "type", "dependencies"]);
|
722
|
+
|
723
|
+
var _useTagging = useTagging(props),
|
724
|
+
context = _useTagging.context,
|
725
|
+
trackAction = _useTagging.trackAction;
|
726
|
+
|
727
|
+
var name = type;
|
728
|
+
|
729
|
+
if (context.technicalError) {
|
730
|
+
name = 'pageError';
|
731
|
+
} else if (context.roadblock) {
|
732
|
+
name = 'roadblock';
|
733
|
+
} else if (context.formError) {
|
734
|
+
name = 'formError';
|
735
|
+
} else if (context.fieldFilled) {
|
736
|
+
name = 'fieldFilled';
|
737
|
+
} else if (context.helpText) {
|
738
|
+
name = 'helpDisplayed';
|
739
|
+
}
|
740
|
+
|
741
|
+
React.useEffect(function () {
|
742
|
+
return trackAction(name);
|
743
|
+
}, dependencies);
|
744
|
+
return React__default.createElement(React__default.Fragment, null, children);
|
745
|
+
};
|
746
|
+
|
747
|
+
var TrackingTimer = function TrackingTimer(_ref) {
|
748
|
+
var finished = _ref.finished,
|
749
|
+
timeout = _ref.timeout,
|
750
|
+
children = _ref.children;
|
751
|
+
var startTime = React.useMemo(Date.now, []);
|
752
|
+
|
753
|
+
var _useState = React.useState(0),
|
754
|
+
_useState2 = _slicedToArray(_useState, 2),
|
755
|
+
stopTime = _useState2[0],
|
756
|
+
setStop = _useState2[1];
|
757
|
+
|
758
|
+
var _useState3 = React.useState(false),
|
759
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
760
|
+
timedOut = _useState4[0],
|
761
|
+
setTimedOut = _useState4[1];
|
762
|
+
|
763
|
+
var stopTimer = function stopTimer() {
|
764
|
+
return setStop(Date.now());
|
765
|
+
};
|
766
|
+
|
767
|
+
React.useEffect(function () {
|
768
|
+
var timer;
|
769
|
+
|
770
|
+
if (!finished) {
|
771
|
+
timer = setTimeout(function () {
|
772
|
+
setTimedOut(true);
|
773
|
+
stopTimer();
|
774
|
+
}, timeout);
|
775
|
+
} else {
|
776
|
+
stopTimer();
|
777
|
+
}
|
778
|
+
|
779
|
+
return function () {
|
780
|
+
if (timer) {
|
781
|
+
clearTimeout(timer);
|
782
|
+
stopTimer();
|
783
|
+
}
|
784
|
+
};
|
785
|
+
}, [finished]);
|
786
|
+
|
787
|
+
if (!stopTime) {
|
788
|
+
return null;
|
789
|
+
}
|
790
|
+
|
791
|
+
return React__default.createElement(Tagging, {
|
792
|
+
loadTime: stopTime - startTime,
|
793
|
+
loadTimeout: timedOut ? true : undefined
|
794
|
+
}, children);
|
795
|
+
};
|
796
|
+
|
797
|
+
function getStateName(_ref) {
|
798
|
+
var formId = _ref.formId,
|
799
|
+
stepId = _ref.stepId,
|
800
|
+
stepName = _ref.stepName;
|
801
|
+
|
802
|
+
if (formId && stepName) {
|
803
|
+
return "".concat(formId, ".").concat(stepName);
|
804
|
+
}
|
805
|
+
|
806
|
+
return stepName || stepId ? "step".concat(stepId) : 'untitled state';
|
807
|
+
}
|
808
|
+
var TrackState = function TrackState(_ref2) {
|
809
|
+
var children = _ref2.children,
|
810
|
+
_ref2$dependencies = _ref2.dependencies,
|
811
|
+
dependencies = _ref2$dependencies === void 0 ? [] : _ref2$dependencies,
|
812
|
+
props = _objectWithoutProperties(_ref2, ["children", "dependencies"]);
|
813
|
+
|
814
|
+
var _useTagging = useTagging(props),
|
815
|
+
trackState = _useTagging.trackState,
|
816
|
+
context = _useTagging.context;
|
817
|
+
|
818
|
+
React.useEffect(function () {
|
819
|
+
return trackState(getStateName(context));
|
820
|
+
}, dependencies);
|
821
|
+
return React__default.createElement(React__default.Fragment, null, children);
|
822
|
+
};
|
823
|
+
|
824
|
+
enableTagging();
|
825
|
+
|
826
|
+
exports.Tagging = Tagging;
|
827
|
+
exports.TaggingActions = TaggingActions;
|
828
|
+
exports.TaggingForm = TaggingForm;
|
829
|
+
exports.TaggingStep = TaggingStep;
|
830
|
+
exports.TrackAction = TrackAction;
|
831
|
+
exports.TrackState = TrackState;
|
832
|
+
exports.TrackingTimer = TrackingTimer;
|
833
|
+
exports.clearHooks = clearHooks;
|
834
|
+
exports.disableTagging = disableTagging;
|
835
|
+
exports.enableTagging = enableTagging;
|
836
|
+
exports.executeHooks = executeHooks;
|
837
|
+
exports.extendContext = extendContext;
|
838
|
+
exports.getRegisteredHooks = getRegisteredHooks;
|
839
|
+
exports.registerHook = registerHook;
|
840
|
+
exports.removeHook = removeHook;
|
841
|
+
exports.trackAction = trackAction;
|
842
|
+
exports.trackState = trackState;
|
843
|
+
exports.useTagging = useTagging;
|