@hellotext/hellotext 2.1.3 → 2.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hellotext.js +1 -1
- package/lib/channels/application_channel.cjs +9 -6
- package/lib/channels/application_channel.js +9 -6
- package/lib/channels/webchat_channel.cjs +42 -17
- package/lib/channels/webchat_channel.js +42 -17
- package/lib/controllers/webchat_controller.cjs +145 -42
- package/lib/controllers/webchat_controller.js +146 -43
- package/lib/core/configuration.cjs +1 -0
- package/lib/core/configuration.js +1 -0
- package/lib/hellotext.cjs +3 -1
- package/lib/hellotext.js +4 -4
- package/lib/models/index.cjs +14 -0
- package/lib/models/index.js +2 -0
- package/lib/models/page.cjs +86 -0
- package/lib/models/page.js +81 -0
- package/lib/models/query.cjs +1 -2
- package/lib/models/query.js +1 -2
- package/lib/models/session.cjs +1 -1
- package/lib/models/session.js +1 -1
- package/lib/models/utm.cjs +41 -0
- package/lib/models/utm.js +38 -0
- package/package.json +1 -1
- package/src/channels/application_channel.js +12 -9
- package/src/channels/webchat_channel.js +33 -19
- package/src/controllers/webchat_controller.js +137 -34
- package/src/core/configuration.js +1 -0
- package/src/hellotext.js +5 -2
- package/src/models/cookies.js +2 -2
- package/src/models/index.js +2 -0
- package/src/models/page.js +65 -0
- package/src/models/query.js +1 -3
- package/src/models/session.js +1 -1
- package/src/models/utm.js +33 -0
|
@@ -40,9 +40,8 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
40
40
|
this.webChatChannel = new WebchatChannel(this.idValue, Hellotext.session, this.conversationIdValue);
|
|
41
41
|
this.files = [];
|
|
42
42
|
this.onMessageReceived = this.onMessageReceived.bind(this);
|
|
43
|
-
this.onConversationAssignment = this.onConversationAssignment.bind(this);
|
|
44
|
-
this.onAgentOnline = this.onAgentOnline.bind(this);
|
|
45
43
|
this.onMessageReaction = this.onMessageReaction.bind(this);
|
|
44
|
+
this.onTypingStart = this.onTypingStart.bind(this);
|
|
46
45
|
this.onScroll = this.onScroll.bind(this);
|
|
47
46
|
this.onOutboundMessageSent = this.onOutboundMessageSent.bind(this);
|
|
48
47
|
this.broadcastChannel = new BroadcastChannel("hellotext--webchat--".concat(this.idValue));
|
|
@@ -59,8 +58,7 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
59
58
|
popover: this.popoverTarget
|
|
60
59
|
});
|
|
61
60
|
this.webChatChannel.onMessage(this.onMessageReceived);
|
|
62
|
-
this.webChatChannel.
|
|
63
|
-
this.webChatChannel.onAgentOnline(this.onAgentOnline);
|
|
61
|
+
this.webChatChannel.onTypingStart(this.onTypingStart);
|
|
64
62
|
this.webChatChannel.onReaction(this.onMessageReaction);
|
|
65
63
|
this.messagesContainerTarget.addEventListener('scroll', this.onScroll);
|
|
66
64
|
if (!Hellotext.business.features.white_label) {
|
|
@@ -78,10 +76,85 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
78
76
|
value: function disconnect() {
|
|
79
77
|
this.broadcastChannel.removeEventListener('message', this.onOutboundMessageSent);
|
|
80
78
|
this.messagesContainerTarget.removeEventListener('scroll', this.onScroll);
|
|
79
|
+
|
|
80
|
+
// Clean up typing indicator timeouts
|
|
81
|
+
this.clearTypingIndicator();
|
|
81
82
|
this.broadcastChannel.close();
|
|
82
83
|
this.floatingUICleanup();
|
|
83
84
|
_get(_getPrototypeOf(_default.prototype), "disconnect", this).call(this);
|
|
84
85
|
}
|
|
86
|
+
}, {
|
|
87
|
+
key: "onTypingStart",
|
|
88
|
+
value: function onTypingStart() {
|
|
89
|
+
if (this.typingIndicatorVisible) {
|
|
90
|
+
return this.resetTypingIndicatorTimer();
|
|
91
|
+
}
|
|
92
|
+
this.showTypingIndicator();
|
|
93
|
+
}
|
|
94
|
+
}, {
|
|
95
|
+
key: "showOptimisticTypingIndicator",
|
|
96
|
+
value: function showOptimisticTypingIndicator() {
|
|
97
|
+
if (this.typingIndicatorVisible) return;
|
|
98
|
+
this.showTypingIndicator();
|
|
99
|
+
}
|
|
100
|
+
}, {
|
|
101
|
+
key: "showTypingIndicator",
|
|
102
|
+
value: function showTypingIndicator() {
|
|
103
|
+
this.clearTypingIndicator();
|
|
104
|
+
this.typingIndicatorVisible = true;
|
|
105
|
+
var indicator = this.typingIndicatorTemplateTarget.cloneNode(true);
|
|
106
|
+
indicator.setAttribute('data-hellotext--webchat-target', 'typingIndicator');
|
|
107
|
+
indicator.style.display = 'flex';
|
|
108
|
+
this.messagesContainerTarget.appendChild(indicator);
|
|
109
|
+
requestAnimationFrame(() => {
|
|
110
|
+
this.messagesContainerTarget.scroll({
|
|
111
|
+
top: this.messagesContainerTarget.scrollHeight,
|
|
112
|
+
behavior: 'instant'
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
var timeout = this.typingIndicatorKeepAliveValue;
|
|
116
|
+
this.incomingTypingIndicatorTimeout = setTimeout(() => {
|
|
117
|
+
this.clearTypingIndicator();
|
|
118
|
+
}, timeout);
|
|
119
|
+
}
|
|
120
|
+
}, {
|
|
121
|
+
key: "resetTypingIndicatorTimer",
|
|
122
|
+
value: function resetTypingIndicatorTimer() {
|
|
123
|
+
if (!this.typingIndicatorVisible) return;
|
|
124
|
+
|
|
125
|
+
// Clear existing timeout
|
|
126
|
+
clearTimeout(this.incomingTypingIndicatorTimeout);
|
|
127
|
+
clearTimeout(this.optimisticTypingTimeout);
|
|
128
|
+
|
|
129
|
+
// Use unified timeout for all typing indicators
|
|
130
|
+
var timeout = this.typingIndicatorKeepAliveValue;
|
|
131
|
+
this.incomingTypingIndicatorTimeout = setTimeout(() => {
|
|
132
|
+
this.clearTypingIndicator();
|
|
133
|
+
}, timeout);
|
|
134
|
+
}
|
|
135
|
+
}, {
|
|
136
|
+
key: "clearTypingIndicator",
|
|
137
|
+
value: function clearTypingIndicator() {
|
|
138
|
+
if (this.hasTypingIndicatorTarget) {
|
|
139
|
+
this.typingIndicatorTarget.remove();
|
|
140
|
+
}
|
|
141
|
+
this.typingIndicatorVisible = false;
|
|
142
|
+
clearTimeout(this.incomingTypingIndicatorTimeout);
|
|
143
|
+
clearTimeout(this.optimisticTypingTimeout);
|
|
144
|
+
}
|
|
145
|
+
}, {
|
|
146
|
+
key: "onMessageInputChange",
|
|
147
|
+
value: function onMessageInputChange() {
|
|
148
|
+
this.resizeInput();
|
|
149
|
+
clearTimeout(this.typingIndicatorTimeout);
|
|
150
|
+
if (!this.hasSentTypingIndicator) {
|
|
151
|
+
this.webChatChannel.startTypingIndicator();
|
|
152
|
+
this.hasSentTypingIndicator = true;
|
|
153
|
+
}
|
|
154
|
+
this.typingIndicatorTimeout = setTimeout(() => {
|
|
155
|
+
this.hasSentTypingIndicator = false;
|
|
156
|
+
}, 3000);
|
|
157
|
+
}
|
|
85
158
|
}, {
|
|
86
159
|
key: "onOutboundMessageSent",
|
|
87
160
|
value: function onOutboundMessageSent(event) {
|
|
@@ -91,7 +164,13 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
91
164
|
var callbacks = {
|
|
92
165
|
'message:sent': data => {
|
|
93
166
|
var element = new DOMParser().parseFromString(data.element, 'text/html').body.firstElementChild;
|
|
94
|
-
|
|
167
|
+
|
|
168
|
+
// Insert message before typing indicator if one exists
|
|
169
|
+
if (this.typingIndicatorVisible && this.hasTypingIndicatorTarget) {
|
|
170
|
+
this.messagesContainerTarget.insertBefore(element, this.typingIndicatorTarget);
|
|
171
|
+
} else {
|
|
172
|
+
this.messagesContainerTarget.appendChild(element);
|
|
173
|
+
}
|
|
95
174
|
element.scrollIntoView({
|
|
96
175
|
behavior: 'instant'
|
|
97
176
|
});
|
|
@@ -251,6 +330,7 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
251
330
|
element.querySelector('[data-attachment-container]').appendChild(image);
|
|
252
331
|
});
|
|
253
332
|
}
|
|
333
|
+
this.clearTypingIndicator();
|
|
254
334
|
this.messagesContainerTarget.appendChild(element);
|
|
255
335
|
Hellotext.eventEmitter.dispatch('webchat:message:received', _objectSpread(_objectSpread({}, message), {}, {
|
|
256
336
|
body: element.querySelector('[data-body]').innerText
|
|
@@ -258,7 +338,6 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
258
338
|
element.scrollIntoView({
|
|
259
339
|
behavior: 'smooth'
|
|
260
340
|
});
|
|
261
|
-
this.setOfflineTimeout();
|
|
262
341
|
if (this.openValue) {
|
|
263
342
|
this.messagesAPI.markAsSeen(id);
|
|
264
343
|
return;
|
|
@@ -268,34 +347,31 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
268
347
|
this.unreadCounterTarget.innerText = unreadCount > 99 ? '99+' : unreadCount;
|
|
269
348
|
}
|
|
270
349
|
}, {
|
|
271
|
-
key: "
|
|
272
|
-
value: function
|
|
273
|
-
var
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
this.
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
}
|
|
283
|
-
}, {
|
|
284
|
-
key: "onAgentOnline",
|
|
285
|
-
value: function onAgentOnline() {
|
|
286
|
-
this.onlineStatusTarget.style.display = 'flex';
|
|
287
|
-
this.setOfflineTimeout();
|
|
350
|
+
key: "resizeInput",
|
|
351
|
+
value: function resizeInput() {
|
|
352
|
+
var maxHeight = 96;
|
|
353
|
+
|
|
354
|
+
// Temporarily reset height to its natural content size
|
|
355
|
+
this.inputTarget.style.height = 'auto';
|
|
356
|
+
|
|
357
|
+
// Set the height to the scrollHeight, which is the minimum height
|
|
358
|
+
// the element needs to fit its content without a scrollbar.
|
|
359
|
+
var scrollHeight = this.inputTarget.scrollHeight;
|
|
360
|
+
this.inputTarget.style.height = "".concat(Math.min(scrollHeight, maxHeight), "px");
|
|
288
361
|
}
|
|
289
362
|
}, {
|
|
290
363
|
key: "sendMessage",
|
|
291
364
|
value: function () {
|
|
292
|
-
var _sendMessage = _asyncToGenerator(function* () {
|
|
365
|
+
var _sendMessage = _asyncToGenerator(function* (e) {
|
|
293
366
|
var formData = new FormData();
|
|
294
367
|
var message = {
|
|
295
368
|
body: this.inputTarget.value,
|
|
296
369
|
attachments: this.files
|
|
297
370
|
};
|
|
298
371
|
if (this.inputTarget.value.trim().length === 0 && this.files.length === 0) {
|
|
372
|
+
if (e && e.target) {
|
|
373
|
+
e.preventDefault();
|
|
374
|
+
}
|
|
299
375
|
return;
|
|
300
376
|
}
|
|
301
377
|
if (this.inputTarget.value.trim().length > 0) {
|
|
@@ -324,7 +400,13 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
324
400
|
element.querySelector('[data-attachment-container]').appendChild(attachment);
|
|
325
401
|
});
|
|
326
402
|
}
|
|
327
|
-
|
|
403
|
+
|
|
404
|
+
// Insert message before typing indicator if one exists
|
|
405
|
+
if (this.typingIndicatorVisible && this.hasTypingIndicatorTarget) {
|
|
406
|
+
this.messagesContainerTarget.insertBefore(element, this.typingIndicatorTarget);
|
|
407
|
+
} else {
|
|
408
|
+
this.messagesContainerTarget.appendChild(element);
|
|
409
|
+
}
|
|
328
410
|
element.scrollIntoView({
|
|
329
411
|
behavior: 'smooth'
|
|
330
412
|
});
|
|
@@ -333,14 +415,26 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
333
415
|
element: element.outerHTML
|
|
334
416
|
});
|
|
335
417
|
this.inputTarget.value = '';
|
|
418
|
+
this.resizeInput();
|
|
336
419
|
this.files = [];
|
|
337
420
|
this.attachmentInputTarget.value = '';
|
|
338
421
|
this.attachmentContainerTarget.innerHTML = '';
|
|
339
422
|
this.attachmentContainerTarget.style.display = 'none';
|
|
340
423
|
this.errorMessageContainerTarget.style.display = 'none';
|
|
341
424
|
this.inputTarget.focus();
|
|
425
|
+
|
|
426
|
+
// Set up optimistic typing indicator BEFORE making the API call
|
|
427
|
+
// This prevents race conditions with server responses
|
|
428
|
+
if (!this.typingIndicatorVisible) {
|
|
429
|
+
clearTimeout(this.optimisticTypingTimeout);
|
|
430
|
+
this.optimisticTypingTimeout = setTimeout(() => {
|
|
431
|
+
this.showOptimisticTypingIndicator();
|
|
432
|
+
}, this.optimisticTypingIndicatorWaitValue);
|
|
433
|
+
}
|
|
342
434
|
var response = yield this.messagesAPI.create(formData);
|
|
343
435
|
if (response.failed) {
|
|
436
|
+
// Clear the optimistic typing indicator on failure
|
|
437
|
+
clearTimeout(this.optimisticTypingTimeout);
|
|
344
438
|
this.broadcastChannel.postMessage({
|
|
345
439
|
type: 'message:failed',
|
|
346
440
|
id: element.id
|
|
@@ -355,9 +449,14 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
355
449
|
this.conversationIdValue = data.conversation;
|
|
356
450
|
this.webChatChannel.updateSubscriptionWith(this.conversationIdValue);
|
|
357
451
|
}
|
|
452
|
+
|
|
453
|
+
// If there's already a typing indicator visible, reset its timer
|
|
454
|
+
if (this.typingIndicatorVisible) {
|
|
455
|
+
this.resetTypingIndicatorTimer();
|
|
456
|
+
}
|
|
358
457
|
this.attachmentContainerTarget.style.display = '';
|
|
359
458
|
});
|
|
360
|
-
function sendMessage() {
|
|
459
|
+
function sendMessage(_x) {
|
|
361
460
|
return _sendMessage.apply(this, arguments);
|
|
362
461
|
}
|
|
363
462
|
return sendMessage;
|
|
@@ -458,29 +557,16 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
458
557
|
this.inputTarget.selectionStart = this.inputTarget.selectionEnd = start + emoji.length;
|
|
459
558
|
this.inputTarget.focus();
|
|
460
559
|
}
|
|
461
|
-
}, {
|
|
462
|
-
key: "setOfflineTimeout",
|
|
463
|
-
value: function setOfflineTimeout() {
|
|
464
|
-
clearTimeout(this.offlineTimeout);
|
|
465
|
-
this.offlineTimeout = setTimeout(() => {
|
|
466
|
-
this.onlineStatusTarget.style.display = 'none';
|
|
467
|
-
}, this.fiveMinutes);
|
|
468
|
-
}
|
|
469
560
|
}, {
|
|
470
561
|
key: "byteToMegabyte",
|
|
471
562
|
value: function byteToMegabyte(bytes) {
|
|
472
563
|
return Math.ceil(bytes / 1024 / 1024);
|
|
473
564
|
}
|
|
474
|
-
}, {
|
|
475
|
-
key: "fiveMinutes",
|
|
476
|
-
get: function get() {
|
|
477
|
-
return 300000;
|
|
478
|
-
}
|
|
479
565
|
}, {
|
|
480
566
|
key: "middlewares",
|
|
481
567
|
get: function get() {
|
|
482
|
-
return [offset(
|
|
483
|
-
padding:
|
|
568
|
+
return [offset(this.offsetValue), shift({
|
|
569
|
+
padding: this.paddingValue
|
|
484
570
|
}), flip()];
|
|
485
571
|
}
|
|
486
572
|
}, {
|
|
@@ -524,8 +610,25 @@ _default.values = {
|
|
|
524
610
|
fullScreenThreshold: {
|
|
525
611
|
type: Number,
|
|
526
612
|
default: 1024
|
|
527
|
-
}
|
|
613
|
+
},
|
|
614
|
+
typingIndicatorKeepAlive: {
|
|
615
|
+
type: Number,
|
|
616
|
+
default: 30000
|
|
617
|
+
},
|
|
618
|
+
// 30 seconds
|
|
619
|
+
offset: {
|
|
620
|
+
type: Number,
|
|
621
|
+
default: 24
|
|
622
|
+
},
|
|
623
|
+
padding: {
|
|
624
|
+
type: Number,
|
|
625
|
+
default: 24
|
|
626
|
+
},
|
|
627
|
+
optimisticTypingIndicatorWait: {
|
|
628
|
+
type: Number,
|
|
629
|
+
default: 1000
|
|
630
|
+
} // 1 second
|
|
528
631
|
};
|
|
529
632
|
_default.classes = ['fadeOut'];
|
|
530
|
-
_default.targets = ['trigger', 'popover', 'input', 'attachmentInput', 'attachmentButton', 'errorMessageContainer', 'attachmentTemplate', 'attachmentContainer', 'attachment', 'messageTemplate', 'messagesContainer', 'title', '
|
|
633
|
+
_default.targets = ['trigger', 'popover', 'input', 'attachmentInput', 'attachmentButton', 'errorMessageContainer', 'attachmentTemplate', 'attachmentContainer', 'attachment', 'messageTemplate', 'messagesContainer', 'title', 'attachmentImage', 'footer', 'toolbar', 'message', 'unreadCounter', 'typingIndicator', 'typingIndicatorTemplate'];
|
|
531
634
|
export { _default as default };
|
|
@@ -69,6 +69,7 @@ let Configuration = /*#__PURE__*/function () {
|
|
|
69
69
|
}();
|
|
70
70
|
exports.Configuration = Configuration;
|
|
71
71
|
Configuration.apiRoot = 'https://api.hellotext.com/v1';
|
|
72
|
+
Configuration.actionCableUrl = 'wss://www.hellotext.com/cable';
|
|
72
73
|
Configuration.autoGenerateSession = true;
|
|
73
74
|
Configuration.session = null;
|
|
74
75
|
Configuration.forms = _forms.Forms;
|
|
@@ -64,6 +64,7 @@ var Configuration = /*#__PURE__*/function () {
|
|
|
64
64
|
return Configuration;
|
|
65
65
|
}();
|
|
66
66
|
Configuration.apiRoot = 'https://api.hellotext.com/v1';
|
|
67
|
+
Configuration.actionCableUrl = 'wss://www.hellotext.com/cable';
|
|
67
68
|
Configuration.autoGenerateSession = true;
|
|
68
69
|
Configuration.session = null;
|
|
69
70
|
Configuration.forms = Forms;
|
package/lib/hellotext.cjs
CHANGED
|
@@ -35,6 +35,7 @@ let Hellotext = /*#__PURE__*/function () {
|
|
|
35
35
|
async function initialize(business, config) {
|
|
36
36
|
_core.Configuration.assign(config);
|
|
37
37
|
_models.Session.initialize();
|
|
38
|
+
this.page = new _models.Page();
|
|
38
39
|
this.business = new _models.Business(business);
|
|
39
40
|
this.forms = new _models.FormCollection();
|
|
40
41
|
_classPrivateFieldLooseBase(this, _query)[_query] = new _models.Query();
|
|
@@ -63,11 +64,12 @@ let Hellotext = /*#__PURE__*/function () {
|
|
|
63
64
|
...(params && params.headers || {}),
|
|
64
65
|
...this.headers
|
|
65
66
|
};
|
|
67
|
+
const pageInstance = params && params.url ? new _models.Page(params.url) : this.page;
|
|
66
68
|
const body = {
|
|
67
69
|
session: this.session,
|
|
68
70
|
action,
|
|
69
71
|
...params,
|
|
70
|
-
|
|
72
|
+
...pageInstance.trackingData
|
|
71
73
|
};
|
|
72
74
|
delete body.headers;
|
|
73
75
|
return await _api.default.events.create({
|
package/lib/hellotext.js
CHANGED
|
@@ -13,7 +13,7 @@ var id = 0;
|
|
|
13
13
|
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
|
|
14
14
|
import { Configuration, Event } from './core';
|
|
15
15
|
import API, { Response } from './api';
|
|
16
|
-
import { Business, FormCollection, Query, Session, Webchat } from './models';
|
|
16
|
+
import { Business, FormCollection, Page, Query, Session, Webchat } from './models';
|
|
17
17
|
import { NotInitializedError } from './errors';
|
|
18
18
|
var _session = /*#__PURE__*/_classPrivateFieldLooseKey("session");
|
|
19
19
|
var _query = /*#__PURE__*/_classPrivateFieldLooseKey("query");
|
|
@@ -33,6 +33,7 @@ var Hellotext = /*#__PURE__*/function () {
|
|
|
33
33
|
var _initialize = _asyncToGenerator(function* (business, config) {
|
|
34
34
|
Configuration.assign(config);
|
|
35
35
|
Session.initialize();
|
|
36
|
+
this.page = new Page();
|
|
36
37
|
this.business = new Business(business);
|
|
37
38
|
this.forms = new FormCollection();
|
|
38
39
|
_classPrivateFieldLooseBase(this, _query)[_query] = new Query();
|
|
@@ -64,12 +65,11 @@ var Hellotext = /*#__PURE__*/function () {
|
|
|
64
65
|
throw new NotInitializedError();
|
|
65
66
|
}
|
|
66
67
|
var headers = _objectSpread(_objectSpread({}, params && params.headers || {}), this.headers);
|
|
68
|
+
var pageInstance = params && params.url ? new Page(params.url) : this.page;
|
|
67
69
|
var body = _objectSpread(_objectSpread({
|
|
68
70
|
session: this.session,
|
|
69
71
|
action
|
|
70
|
-
}, params),
|
|
71
|
-
url: params && params.url || window.location.href
|
|
72
|
-
});
|
|
72
|
+
}, params), pageInstance.trackingData);
|
|
73
73
|
delete body.headers;
|
|
74
74
|
return yield API.events.create({
|
|
75
75
|
headers,
|
package/lib/models/index.cjs
CHANGED
|
@@ -27,6 +27,12 @@ Object.defineProperty(exports, "FormCollection", {
|
|
|
27
27
|
return _form_collection.FormCollection;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
+
Object.defineProperty(exports, "Page", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _page.Page;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
30
36
|
Object.defineProperty(exports, "Query", {
|
|
31
37
|
enumerable: true,
|
|
32
38
|
get: function () {
|
|
@@ -39,6 +45,12 @@ Object.defineProperty(exports, "Session", {
|
|
|
39
45
|
return _session.Session;
|
|
40
46
|
}
|
|
41
47
|
});
|
|
48
|
+
Object.defineProperty(exports, "UTM", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _utm.UTM;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
42
54
|
Object.defineProperty(exports, "Webchat", {
|
|
43
55
|
enumerable: true,
|
|
44
56
|
get: function () {
|
|
@@ -49,6 +61,8 @@ var _business = require("./business");
|
|
|
49
61
|
var _cookies = require("./cookies");
|
|
50
62
|
var _form = require("./form");
|
|
51
63
|
var _form_collection = require("./form_collection");
|
|
64
|
+
var _page = require("./page");
|
|
52
65
|
var _query = require("./query");
|
|
53
66
|
var _session = require("./session");
|
|
67
|
+
var _utm = require("./utm");
|
|
54
68
|
var _webchat = require("./webchat");
|
package/lib/models/index.js
CHANGED
|
@@ -2,6 +2,8 @@ export { Business } from './business';
|
|
|
2
2
|
export { Cookies } from './cookies';
|
|
3
3
|
export { Form } from './form';
|
|
4
4
|
export { FormCollection } from './form_collection';
|
|
5
|
+
export { Page } from './page';
|
|
5
6
|
export { Query } from './query';
|
|
6
7
|
export { Session } from './session';
|
|
8
|
+
export { UTM } from './utm';
|
|
7
9
|
export { Webchat } from './webchat';
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Page = void 0;
|
|
7
|
+
var _utm = require("./utm");
|
|
8
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
9
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
10
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
11
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
12
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
13
|
+
let Page = /*#__PURE__*/function () {
|
|
14
|
+
function Page(url = null) {
|
|
15
|
+
_classCallCheck(this, Page);
|
|
16
|
+
this.utm = new _utm.UTM();
|
|
17
|
+
this._url = url;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Get the current page URL
|
|
22
|
+
* @returns {string} The page URL
|
|
23
|
+
*/
|
|
24
|
+
_createClass(Page, [{
|
|
25
|
+
key: "url",
|
|
26
|
+
get: function () {
|
|
27
|
+
return this._url || window.location.href;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Get the current page title
|
|
32
|
+
* @returns {string} The page title
|
|
33
|
+
*/
|
|
34
|
+
}, {
|
|
35
|
+
key: "title",
|
|
36
|
+
get: function () {
|
|
37
|
+
return document.title;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Get the current page path
|
|
42
|
+
* @returns {string} The page path
|
|
43
|
+
*/
|
|
44
|
+
}, {
|
|
45
|
+
key: "path",
|
|
46
|
+
get: function () {
|
|
47
|
+
if (this._url) {
|
|
48
|
+
try {
|
|
49
|
+
return new URL(this._url).pathname;
|
|
50
|
+
} catch (e) {
|
|
51
|
+
return '/';
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return window.location.pathname;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Get current UTM parameters
|
|
59
|
+
* @returns {Object} The UTM parameters
|
|
60
|
+
*/
|
|
61
|
+
}, {
|
|
62
|
+
key: "utmParams",
|
|
63
|
+
get: function () {
|
|
64
|
+
return this.utm.current;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Get page data for tracking
|
|
69
|
+
* @returns {Object} Object containing page object and utm_params
|
|
70
|
+
*/
|
|
71
|
+
}, {
|
|
72
|
+
key: "trackingData",
|
|
73
|
+
get: function () {
|
|
74
|
+
return {
|
|
75
|
+
page: {
|
|
76
|
+
url: this.url,
|
|
77
|
+
title: this.title,
|
|
78
|
+
path: this.path
|
|
79
|
+
},
|
|
80
|
+
utm_params: this.utmParams
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}]);
|
|
84
|
+
return Page;
|
|
85
|
+
}();
|
|
86
|
+
exports.Page = Page;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
2
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
3
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
4
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
5
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
6
|
+
import { UTM } from './utm';
|
|
7
|
+
var Page = /*#__PURE__*/function () {
|
|
8
|
+
function Page() {
|
|
9
|
+
var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
10
|
+
_classCallCheck(this, Page);
|
|
11
|
+
this.utm = new UTM();
|
|
12
|
+
this._url = url;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Get the current page URL
|
|
17
|
+
* @returns {string} The page URL
|
|
18
|
+
*/
|
|
19
|
+
_createClass(Page, [{
|
|
20
|
+
key: "url",
|
|
21
|
+
get: function get() {
|
|
22
|
+
return this._url || window.location.href;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Get the current page title
|
|
27
|
+
* @returns {string} The page title
|
|
28
|
+
*/
|
|
29
|
+
}, {
|
|
30
|
+
key: "title",
|
|
31
|
+
get: function get() {
|
|
32
|
+
return document.title;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Get the current page path
|
|
37
|
+
* @returns {string} The page path
|
|
38
|
+
*/
|
|
39
|
+
}, {
|
|
40
|
+
key: "path",
|
|
41
|
+
get: function get() {
|
|
42
|
+
if (this._url) {
|
|
43
|
+
try {
|
|
44
|
+
return new URL(this._url).pathname;
|
|
45
|
+
} catch (e) {
|
|
46
|
+
return '/';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return window.location.pathname;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Get current UTM parameters
|
|
54
|
+
* @returns {Object} The UTM parameters
|
|
55
|
+
*/
|
|
56
|
+
}, {
|
|
57
|
+
key: "utmParams",
|
|
58
|
+
get: function get() {
|
|
59
|
+
return this.utm.current;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Get page data for tracking
|
|
64
|
+
* @returns {Object} Object containing page object and utm_params
|
|
65
|
+
*/
|
|
66
|
+
}, {
|
|
67
|
+
key: "trackingData",
|
|
68
|
+
get: function get() {
|
|
69
|
+
return {
|
|
70
|
+
page: {
|
|
71
|
+
url: this.url,
|
|
72
|
+
title: this.title,
|
|
73
|
+
path: this.path
|
|
74
|
+
},
|
|
75
|
+
utm_params: this.utmParams
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}]);
|
|
79
|
+
return Page;
|
|
80
|
+
}();
|
|
81
|
+
export { Page };
|
package/lib/models/query.cjs
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Query = void 0;
|
|
7
|
-
var _cookies = require("./cookies");
|
|
8
7
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
9
8
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
10
9
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
@@ -33,7 +32,7 @@ let Query = /*#__PURE__*/function () {
|
|
|
33
32
|
}, {
|
|
34
33
|
key: "session",
|
|
35
34
|
get: function () {
|
|
36
|
-
return this.get('session')
|
|
35
|
+
return this.get('session');
|
|
37
36
|
}
|
|
38
37
|
}, {
|
|
39
38
|
key: "toHellotextParam",
|
package/lib/models/query.js
CHANGED
|
@@ -3,7 +3,6 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
3
3
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
4
4
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
5
5
|
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
6
|
-
import { Cookies } from './cookies';
|
|
7
6
|
var Query = /*#__PURE__*/function () {
|
|
8
7
|
function Query() {
|
|
9
8
|
_classCallCheck(this, Query);
|
|
@@ -27,7 +26,7 @@ var Query = /*#__PURE__*/function () {
|
|
|
27
26
|
}, {
|
|
28
27
|
key: "session",
|
|
29
28
|
get: function get() {
|
|
30
|
-
return this.get('session')
|
|
29
|
+
return this.get('session');
|
|
31
30
|
}
|
|
32
31
|
}, {
|
|
33
32
|
key: "toHellotextParam",
|
package/lib/models/session.cjs
CHANGED
|
@@ -34,7 +34,7 @@ let Session = /*#__PURE__*/function () {
|
|
|
34
34
|
key: "initialize",
|
|
35
35
|
value: function initialize() {
|
|
36
36
|
_classPrivateFieldLooseBase(this, _query)[_query] = new _query2.Query();
|
|
37
|
-
this.session =
|
|
37
|
+
this.session = _classPrivateFieldLooseBase(this, _query)[_query].session || _core.Configuration.session || _cookies.Cookies.get('hello_session');
|
|
38
38
|
if (!this.session && _core.Configuration.autoGenerateSession) {
|
|
39
39
|
this.session = crypto.randomUUID();
|
|
40
40
|
}
|
package/lib/models/session.js
CHANGED
|
@@ -28,7 +28,7 @@ var Session = /*#__PURE__*/function () {
|
|
|
28
28
|
key: "initialize",
|
|
29
29
|
value: function initialize() {
|
|
30
30
|
_classPrivateFieldLooseBase(this, _query)[_query] = new Query();
|
|
31
|
-
this.session =
|
|
31
|
+
this.session = _classPrivateFieldLooseBase(this, _query)[_query].session || Configuration.session || Cookies.get('hello_session');
|
|
32
32
|
if (!this.session && Configuration.autoGenerateSession) {
|
|
33
33
|
this.session = crypto.randomUUID();
|
|
34
34
|
}
|