@subiz/widget-v4 4.0.83 → 4.0.87
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/.prettierrc.js +1 -1
- package/compiled_src/chatbox/AgentsAvatar.js +20 -3
- package/compiled_src/chatbox/ChatButton.js +11 -8
- package/compiled_src/chatbox/Event.js +12 -0
- package/compiled_src/chatbox/Events.js +1 -0
- package/compiled_src/chatbox/MessageInput.js +6 -0
- package/compiled_src/chatbox/Typing.js +1 -1
- package/compiled_src/chatbox/Widget.js +50 -38
- package/compiled_src/chatbox/main.js +10 -0
- package/compiled_src/popup/popup.js +21 -2
- package/compiled_src/store/store.js +24 -40
- package/compiled_src/util/common.js +10 -10
- package/dist/132.js +162 -44
- package/dist/178.js +174 -341
- package/dist/182ed9b853b.132.js +1 -0
- package/dist/182ed9b853b.178.js +1 -0
- package/dist/{17f00e48d38.213.js → 182ed9b853b.213.js} +1 -1
- package/dist/{17f00e48d38.335.js → 182ed9b853b.335.js} +1 -1
- package/dist/182ed9b853b.362.js +1 -0
- package/dist/182ed9b853b.441.js +1 -0
- package/dist/{17f00e48d38.605.js → 182ed9b853b.605.js} +0 -0
- package/dist/182ed9b853b.678.js +1 -0
- package/dist/182ed9b853b.782.js +1 -0
- package/dist/182ed9b853b.app.js +1 -0
- package/dist/{17f00e48d38.index.html → 182ed9b853b.index.html} +7 -3
- package/dist/{17f00e48d38.library.html → 182ed9b853b.library.html} +7 -3
- package/dist/182ed9b853b.library.js +1 -0
- package/dist/{17f00e48d38.preview.html → 182ed9b853b.preview.html} +1 -1
- package/dist/182ed9b853b.preview.js +1 -0
- package/dist/182ed9b853b.screenshoot.js +1 -0
- package/dist/213.js +28 -1
- package/dist/335.js +2 -2
- package/dist/362.js +21 -71
- package/dist/441.js +152 -57
- package/dist/678.js +20 -70
- package/dist/782.js +21 -118
- package/dist/HASH +1 -1
- package/dist/screenshoot.html +1 -1
- package/dist/screenshoot.js +208 -174
- package/index.html +1 -1
- package/package.json +16 -16
- package/src/chatbox/AgentsAvatar.js +32 -10
- package/src/chatbox/ChatButton.js +11 -4
- package/src/chatbox/Event.js +23 -4
- package/src/chatbox/Events.js +3 -1
- package/src/chatbox/MessageInput.js +14 -5
- package/src/chatbox/Typing.js +10 -11
- package/src/chatbox/Widget.js +17 -11
- package/src/chatbox/main.js +8 -1
- package/src/popup/popup.js +37 -12
- package/src/store/store.js +24 -36
- package/src/util/common.js +16 -19
- package/dist/0b82fa7e5c3b07b40a44.png +0 -1
- package/dist/0f4af006e38ee8b93633.png +0 -1
- package/dist/17f00e48d38.132.js +0 -1
- package/dist/17f00e48d38.178.js +0 -1
- package/dist/17f00e48d38.362.js +0 -1
- package/dist/17f00e48d38.441.js +0 -1
- package/dist/17f00e48d38.678.js +0 -1
- package/dist/17f00e48d38.782.js +0 -1
- package/dist/17f00e48d38.app.js +0 -1
- package/dist/17f00e48d38.library.js +0 -1
- package/dist/17f00e48d38.preview.js +0 -1
- package/dist/17f00e48d38.screenshoot.js +0 -1
- package/dist/1ea1c6cd21d25176810c.png +0 -1
- package/dist/292d42404e1b03398f61.png +0 -1
- package/dist/312d376370831b7bea83.png +0 -1
- package/dist/313d1bfc1cf776d1aefe.png +0 -1
- package/dist/4aa58bb7a66bb44975aa.png +0 -1
- package/dist/56ce063bc6c81adb7322.png +0 -1
- package/dist/6a411166ef5cc79e0714.png +0 -1
- package/dist/6faf403782fefacc1649.png +0 -1
- package/dist/79dca33c68fab79c067f.png +0 -1
- package/dist/82da1578fa84f9debaeb.png +0 -1
- package/dist/8b8e0f0824743974b282.png +0 -1
- package/dist/8d551390d81e39130a3c.png +0 -1
- package/dist/9fc61b9479877ebdb6c7.png +0 -1
- package/dist/a165d31dcb3dc90f1057.png +0 -1
- package/dist/a98d4a5698812c4426b3.png +0 -1
- package/dist/c41606bf9d1b604e46d5.png +0 -1
- package/dist/ce1f7450ce6c1aacd330.png +0 -1
- package/dist/cf8c01e88f4770a6e3e5.png +0 -1
- package/dist/dfbcfeab1d5622a737e2.png +0 -1
- package/dist/e4893ed8c2f7b8329919.png +0 -1
- package/dist/ec2ab4eb4ef73d186186.png +0 -1
package/.prettierrc.js
CHANGED
|
@@ -20,6 +20,26 @@ class AgentsAvatar extends _common.Com {
|
|
|
20
20
|
|
|
21
21
|
render() {
|
|
22
22
|
let accountSetting = this.props.plugin.chatbox;
|
|
23
|
+
let acc = this.props.store.matchAccount();
|
|
24
|
+
var tooltippos = this.props.tooltipPos || 'bottom';
|
|
25
|
+
var mode = this.props.mode || 'primary';
|
|
26
|
+
|
|
27
|
+
if (accountSetting && accountSetting.hide_agent_profile) {
|
|
28
|
+
return (0, _preact.h)("div", {
|
|
29
|
+
class: `group-avatar group-avatar--${mode}`
|
|
30
|
+
}, (0, _preact.h)("div", {
|
|
31
|
+
class: "d-inline-block pos-relative",
|
|
32
|
+
"data-tooltip": acc.name,
|
|
33
|
+
"data-tooltip-position": tooltippos
|
|
34
|
+
}, (0, _preact.h)("img", {
|
|
35
|
+
width: 35,
|
|
36
|
+
height: 35,
|
|
37
|
+
alt: "agent avatar left",
|
|
38
|
+
class: "avatar group-avatar--agent-left",
|
|
39
|
+
src: this.props.store.replaceFileUrl(acc.logo_url) || require('../../assets/img/image_default.png')
|
|
40
|
+
})));
|
|
41
|
+
}
|
|
42
|
+
|
|
23
43
|
let agentM = this.props.store.matchAgent('*');
|
|
24
44
|
|
|
25
45
|
var agents = _index.default.map(this.props.agent_ids, id => agentM[id]);
|
|
@@ -37,9 +57,6 @@ class AgentsAvatar extends _common.Com {
|
|
|
37
57
|
}
|
|
38
58
|
|
|
39
59
|
agents = _index.default.filter(agents, ag => !!ag);
|
|
40
|
-
let acc = this.props.store.matchAccount();
|
|
41
|
-
var tooltippos = this.props.tooltipPos || 'bottom';
|
|
42
|
-
var mode = this.props.mode || 'primary';
|
|
43
60
|
|
|
44
61
|
if (agents.length === 0) {
|
|
45
62
|
return (0, _preact.h)("div", {
|
|
@@ -214,6 +214,13 @@ class ChatButton extends _common.Com {
|
|
|
214
214
|
position = _index.default.get(accountSetting, 'mobile_button.position') || position;
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
+
if (accountSetting && accountSetting.hide_agent_profile) {
|
|
218
|
+
agent = Object.assign({}, account, {
|
|
219
|
+
avatar_url: account.logo_url || require('../../assets/img/image_default.png'),
|
|
220
|
+
fullname: account.name || this.props.t('agent')
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
217
224
|
let cls = 'widget-preview widget-preview--' + position;
|
|
218
225
|
if (!this.state.displayPreview) cls += ' widget-preview--hidden';
|
|
219
226
|
var tags = this.renderMessagePreview(this.state.previewEvent, this.props.t('sent_you_a_message'));
|
|
@@ -247,21 +254,17 @@ class ChatButton extends _common.Com {
|
|
|
247
254
|
}
|
|
248
255
|
|
|
249
256
|
onProfileReady() {
|
|
250
|
-
if (this.
|
|
257
|
+
if (this._buttonLoaded) this.setState({
|
|
251
258
|
opacity: 1
|
|
252
259
|
});
|
|
253
|
-
this.
|
|
254
|
-
profileLoaded: true
|
|
255
|
-
});
|
|
260
|
+
this._profileLoaded = true;
|
|
256
261
|
}
|
|
257
262
|
|
|
258
263
|
onButtonReady() {
|
|
259
|
-
if (this.
|
|
264
|
+
if (this._profileLoaded) this.setState({
|
|
260
265
|
opacity: 1
|
|
261
266
|
});
|
|
262
|
-
this.
|
|
263
|
-
buttonLoaded: true
|
|
264
|
-
});
|
|
267
|
+
this._buttonLoaded = true;
|
|
265
268
|
}
|
|
266
269
|
|
|
267
270
|
renderButton() {
|
|
@@ -128,6 +128,18 @@ class Event extends _common.Com {
|
|
|
128
128
|
|
|
129
129
|
var uri = acc.logo_url || require('../../assets/img/image_default.png');
|
|
130
130
|
|
|
131
|
+
if (true || _index.default.get(this.props, 'chatbox.hide_agent_profile')) {
|
|
132
|
+
return (0, _preact.h)("div", {
|
|
133
|
+
class: "message-sender"
|
|
134
|
+
}, (0, _preact.h)("img", {
|
|
135
|
+
alt: "sender",
|
|
136
|
+
class: "message-sender-avatar",
|
|
137
|
+
src: this.props.store.replaceFileUrl(uri)
|
|
138
|
+
}), (0, _preact.h)("p", {
|
|
139
|
+
class: "message-sender-name"
|
|
140
|
+
}, acc.name));
|
|
141
|
+
}
|
|
142
|
+
|
|
131
143
|
let agentM = this.props.store.matchAgent('*');
|
|
132
144
|
|
|
133
145
|
if (byid !== 'system' || bytype !== 'dummy') {
|
|
@@ -68,6 +68,7 @@ class Events extends _common.Com {
|
|
|
68
68
|
processEvents(convo, events);
|
|
69
69
|
|
|
70
70
|
let $events = _index.default.map(events, ev => (0, _preact.h)(_Event.default, {
|
|
71
|
+
chatbox: this.props.chatbox,
|
|
71
72
|
onLink: this.props.onLink,
|
|
72
73
|
store: this.props.store,
|
|
73
74
|
onFormSubmit: this.props.onFormSubmit,
|
|
@@ -46,6 +46,12 @@ class MessageInput extends _common.Com {
|
|
|
46
46
|
}, 5);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
blur() {
|
|
50
|
+
const $input = this.refMessageInput.current;
|
|
51
|
+
if (!$input) return;
|
|
52
|
+
$input.blur();
|
|
53
|
+
}
|
|
54
|
+
|
|
49
55
|
render() {
|
|
50
56
|
var buttons = (0, _preact.h)("div", {
|
|
51
57
|
class: "d-flex flex-row align-self-end"
|
|
@@ -41,7 +41,7 @@ class Typing extends _common.Com {
|
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
let ag = this.props.store.matchAgent(ev.by.id);
|
|
44
|
+
let ag = this.props.store.matchAgent(ev.by.id) || {};
|
|
45
45
|
if (ag.type == 'agent') return;
|
|
46
46
|
if (_index.default.get(ev, 'type') !== 'conversation_typing') return;
|
|
47
47
|
this.setState({
|
|
@@ -51,6 +51,40 @@ class Widget extends _common.Com {
|
|
|
51
51
|
constructor(props) {
|
|
52
52
|
super(props);
|
|
53
53
|
|
|
54
|
+
_defineProperty(this, "msgInput", (0, _preact.createRef)());
|
|
55
|
+
|
|
56
|
+
_defineProperty(this, "sendMessage", async message => {
|
|
57
|
+
let text = message.text;
|
|
58
|
+
|
|
59
|
+
if (!this.props.cid) {
|
|
60
|
+
this.creating = true;
|
|
61
|
+
const {
|
|
62
|
+
convo,
|
|
63
|
+
error
|
|
64
|
+
} = await this.props.store.startConvo({
|
|
65
|
+
locale: this.props.t.locale(),
|
|
66
|
+
message: text,
|
|
67
|
+
initial_by: this.props.store.matchUser().id
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
if (error) {}
|
|
71
|
+
|
|
72
|
+
this.creating = false;
|
|
73
|
+
this.props.store.sendConvoEvent(convo.id, 'message_sent', {
|
|
74
|
+
message
|
|
75
|
+
});
|
|
76
|
+
this.props.onGo({
|
|
77
|
+
view: 'chat',
|
|
78
|
+
cid: convo.id
|
|
79
|
+
});
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
this.props.store.sendConvoEvent(this.props.cid, 'message_sent', {
|
|
84
|
+
message
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
54
88
|
_defineProperty(this, "onLink", (e, url) => {
|
|
55
89
|
if (!url) return e.preventDefault();
|
|
56
90
|
let noschemeurl = url.replace(/(^\w+:|^)\/\//, '');
|
|
@@ -189,11 +223,14 @@ class Widget extends _common.Com {
|
|
|
189
223
|
|
|
190
224
|
let user = _index.default.cloneDeep(this.props.store.matchUser());
|
|
191
225
|
|
|
226
|
+
let is_lead = false;
|
|
227
|
+
|
|
192
228
|
_index.default.map(data, (field, key) => {
|
|
193
229
|
if (!key.startsWith('attr:')) return;
|
|
194
230
|
var attr = {
|
|
195
231
|
key: key.substr(5)
|
|
196
232
|
};
|
|
233
|
+
is_lead = is_lead || key == 'emails' || key == 'phones';
|
|
197
234
|
if (field.type === 'number') attr.number = parseInt(field.value);
|
|
198
235
|
if (field.type === 'datetime') attr.datetime = new _index.default.Date(field.value).toISOString();
|
|
199
236
|
if (field.type === 'list') attr.list = field.value;
|
|
@@ -202,6 +239,11 @@ class Widget extends _common.Com {
|
|
|
202
239
|
_index.default.setUserAttr(user, attr);
|
|
203
240
|
});
|
|
204
241
|
|
|
242
|
+
if (is_lead) _index.default.setUserAttr(user, {
|
|
243
|
+
key: 'lead_source',
|
|
244
|
+
text: 'widget'
|
|
245
|
+
});
|
|
246
|
+
|
|
205
247
|
let firstmsg = _index.default.get(data, 'question.value');
|
|
206
248
|
|
|
207
249
|
let groupid = _index.default.get(data, 'group.value', '');
|
|
@@ -241,11 +283,11 @@ class Widget extends _common.Com {
|
|
|
241
283
|
this.setState({
|
|
242
284
|
creatingError: null
|
|
243
285
|
});
|
|
286
|
+
await this.props.store.setUser(user);
|
|
244
287
|
const {
|
|
245
288
|
error,
|
|
246
289
|
convo
|
|
247
290
|
} = await this.props.store.startConvo(req);
|
|
248
|
-
this.props.store.setUser(user);
|
|
249
291
|
|
|
250
292
|
if (error) {
|
|
251
293
|
this.setState({
|
|
@@ -564,7 +606,7 @@ class Widget extends _common.Com {
|
|
|
564
606
|
|
|
565
607
|
blur() {
|
|
566
608
|
if (this.props.store.isPreview) return;
|
|
567
|
-
var $input = this.msgInput;
|
|
609
|
+
var $input = this.msgInput.current;
|
|
568
610
|
if (!$input) return;
|
|
569
611
|
setTimeout(() => $input && $input.blur());
|
|
570
612
|
setTimeout(() => $input && $input.blur(), 300);
|
|
@@ -590,7 +632,7 @@ class Widget extends _common.Com {
|
|
|
590
632
|
return;
|
|
591
633
|
}
|
|
592
634
|
|
|
593
|
-
var $input = this.msgInput;
|
|
635
|
+
var $input = this.msgInput.current;
|
|
594
636
|
if (!$input) return;
|
|
595
637
|
setTimeout(() => $input.focus());
|
|
596
638
|
setTimeout(() => $input.focus(), 300);
|
|
@@ -606,38 +648,6 @@ class Widget extends _common.Com {
|
|
|
606
648
|
this.focusInput();
|
|
607
649
|
}
|
|
608
650
|
|
|
609
|
-
async sendMessage(message) {
|
|
610
|
-
let text = message.text;
|
|
611
|
-
|
|
612
|
-
if (!this.props.cid) {
|
|
613
|
-
this.creating = true;
|
|
614
|
-
const {
|
|
615
|
-
convo,
|
|
616
|
-
error
|
|
617
|
-
} = await this.props.store.startConvo({
|
|
618
|
-
locale: this.props.t.locale(),
|
|
619
|
-
message: text,
|
|
620
|
-
initial_by: this.props.store.matchUser().id
|
|
621
|
-
});
|
|
622
|
-
|
|
623
|
-
if (error) {}
|
|
624
|
-
|
|
625
|
-
this.creating = false;
|
|
626
|
-
this.props.store.sendConvoEvent(convo.id, 'message_sent', {
|
|
627
|
-
message
|
|
628
|
-
});
|
|
629
|
-
this.props.onGo({
|
|
630
|
-
view: 'chat',
|
|
631
|
-
cid: convo.id
|
|
632
|
-
});
|
|
633
|
-
return;
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
this.props.store.sendConvoEvent(this.props.cid, 'message_sent', {
|
|
637
|
-
message
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
|
-
|
|
641
651
|
createPostback(postback) {
|
|
642
652
|
this.props.store.createPostback(this.props.cid, postback);
|
|
643
653
|
}
|
|
@@ -645,9 +655,9 @@ class Widget extends _common.Com {
|
|
|
645
655
|
renderChat() {
|
|
646
656
|
let $input = (0, _preact.h)(_MessageInput.default, {
|
|
647
657
|
store: this.props.store,
|
|
648
|
-
ref:
|
|
658
|
+
ref: this.msgInput,
|
|
649
659
|
cid: this.props.cid,
|
|
650
|
-
onSend:
|
|
660
|
+
onSend: this.sendMessage,
|
|
651
661
|
t: this.props.t
|
|
652
662
|
});
|
|
653
663
|
let convo = this.props.store.matchConvo(this.props.cid) || {};
|
|
@@ -670,6 +680,7 @@ class Widget extends _common.Com {
|
|
|
670
680
|
isShow: this.props.isShow,
|
|
671
681
|
onLink: this.onLink,
|
|
672
682
|
store: this.props.store,
|
|
683
|
+
chatbox: this.props.plugin.chatbox || {},
|
|
673
684
|
onFormSubmit: e => this.onEventFormSubmit(e),
|
|
674
685
|
ref: ref => this.events = ref,
|
|
675
686
|
cid: this.props.cid,
|
|
@@ -740,6 +751,7 @@ class Widget extends _common.Com {
|
|
|
740
751
|
}
|
|
741
752
|
|
|
742
753
|
renderConvoSummary(convo) {
|
|
754
|
+
let accountSetting = this.props.plugin.chatbox || {};
|
|
743
755
|
let agentM = this.props.store.matchAgent('*');
|
|
744
756
|
|
|
745
757
|
let ags = _index.default.filter(convo.members, m => {
|
|
@@ -757,7 +769,7 @@ class Widget extends _common.Com {
|
|
|
757
769
|
|
|
758
770
|
var name = _index.default.each(agents, ag => ag.fullname).join(', ');
|
|
759
771
|
|
|
760
|
-
if (!name) name = this.props.store.matchAccount().name;
|
|
772
|
+
if (accountSetting.hide_agent_profile || !name) name = this.props.store.matchAccount().name;
|
|
761
773
|
if (!name) name = this.props.t('agent');
|
|
762
774
|
var $you = null;
|
|
763
775
|
|
|
@@ -142,6 +142,16 @@ class Main extends _common.Com {
|
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
p = p || {};
|
|
145
|
+
|
|
146
|
+
if (!p.view && !p.cid) {
|
|
147
|
+
let convoM = this.props.store.matchConvo('*');
|
|
148
|
+
|
|
149
|
+
let redconvo = _index.default.find(convoM, convo => !_index.default.isConvoSeen(convo, this.props.store.matchUser().id));
|
|
150
|
+
|
|
151
|
+
p.cid = _index.default.get(redconvo, 'id', _index.default.get(convoM, '0.id'));
|
|
152
|
+
p.view = 'chat';
|
|
153
|
+
}
|
|
154
|
+
|
|
145
155
|
if (this.props.store.isMobile()) modifyViewport();
|
|
146
156
|
this.setState({
|
|
147
157
|
widgetConvoId: p.cid,
|
|
@@ -280,15 +280,29 @@ class Popup extends _common.Com {
|
|
|
280
280
|
|
|
281
281
|
let user = _index.default.cloneDeep(this.props.store.matchUser());
|
|
282
282
|
|
|
283
|
+
let is_lead = false;
|
|
284
|
+
let modifiedPairs = {};
|
|
285
|
+
|
|
283
286
|
for (var pair of formData.entries()) {
|
|
287
|
+
if (modifiedPairs[pair[0]]) {
|
|
288
|
+
let currentValue = _index.default.get(modifiedPairs, `${pair[0]}.1`, '');
|
|
289
|
+
|
|
290
|
+
currentValue += `,${pair[1]}`;
|
|
291
|
+
|
|
292
|
+
_index.default.set(modifiedPairs, `${pair[0]}.1`, currentValue);
|
|
293
|
+
} else {
|
|
294
|
+
modifiedPairs[pair[0]] = [pair[0], pair[1]];
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
for (const [_, pair] of Object.entries(modifiedPairs)) {
|
|
284
299
|
let page = _index.default.get(this.props.plugin.popup, `pages.${this.getPageIndex()}`);
|
|
285
300
|
|
|
286
301
|
let form = _index.default.find(page.components, com => com.type === 'form');
|
|
287
302
|
|
|
288
303
|
let fields = _index.default.get(form, 'form.fields', []);
|
|
289
304
|
|
|
290
|
-
let field = _index.default.find(fields, field => field.key === pair[0]);
|
|
291
|
-
|
|
305
|
+
let field = _index.default.find(fields, field => field.key === pair[0]) || {};
|
|
292
306
|
if (!field.type) return;
|
|
293
307
|
summitFields.push({
|
|
294
308
|
key: pair[0],
|
|
@@ -298,6 +312,7 @@ class Popup extends _common.Com {
|
|
|
298
312
|
let key = pair[0];
|
|
299
313
|
if (key === 'email') key = 'emails';
|
|
300
314
|
if (key === 'phone') key = 'phones';
|
|
315
|
+
is_lead = is_lead || key == 'emails' || key == 'phones';
|
|
301
316
|
|
|
302
317
|
_index.default.setUserAttr(user, {
|
|
303
318
|
key: key,
|
|
@@ -305,6 +320,10 @@ class Popup extends _common.Com {
|
|
|
305
320
|
});
|
|
306
321
|
}
|
|
307
322
|
|
|
323
|
+
if (is_lead) _index.default.setUserAttr(user, {
|
|
324
|
+
key: 'lead_source',
|
|
325
|
+
text: 'plugin.' + this.props.plugin.id
|
|
326
|
+
});
|
|
308
327
|
this.props.store.sendConversion(this.props.plugin.id, summitFields, this.impressionToken);
|
|
309
328
|
this.props.store.setUser(user);
|
|
310
329
|
}
|
|
@@ -50,8 +50,6 @@ class Store {
|
|
|
50
50
|
|
|
51
51
|
_defineProperty(this, "suggest_addresses", keyword => this.api.suggest_address(keyword));
|
|
52
52
|
|
|
53
|
-
_defineProperty(this, "matchSession", () => this.kv.match('session') || {});
|
|
54
|
-
|
|
55
53
|
_defineProperty(this, "matchAccount", () => this.cache.match('account'));
|
|
56
54
|
|
|
57
55
|
_defineProperty(this, "matchPaymentMethods", () => this.cache.match('payment_methods'));
|
|
@@ -145,6 +143,8 @@ class Store {
|
|
|
145
143
|
};
|
|
146
144
|
});
|
|
147
145
|
|
|
146
|
+
_defineProperty(this, "matchLocation", () => this.cache.match('location') || {});
|
|
147
|
+
|
|
148
148
|
_defineProperty(this, "matchBot", () => this.cache.match('bot') || {});
|
|
149
149
|
|
|
150
150
|
_defineProperty(this, "readyGate", new _index.default.Gate());
|
|
@@ -172,6 +172,8 @@ class Store {
|
|
|
172
172
|
|
|
173
173
|
_defineProperty(this, "seenQueue", []);
|
|
174
174
|
|
|
175
|
+
_defineProperty(this, "matchTrafficSource", () => this.kv.match('traffic_source'));
|
|
176
|
+
|
|
175
177
|
_defineProperty(this, "_typing", _index.default.throttle(convoid => this.api.sendTyping(convoid), 3000, {
|
|
176
178
|
trailing: false
|
|
177
179
|
}));
|
|
@@ -279,7 +281,7 @@ class Store {
|
|
|
279
281
|
}
|
|
280
282
|
|
|
281
283
|
isInsync(key) {
|
|
282
|
-
return _index.default.Date.now() - (this.g_sync[key] || 0) <
|
|
284
|
+
return _index.default.Date.now() - (this.g_sync[key] || 0) < 600000;
|
|
283
285
|
}
|
|
284
286
|
|
|
285
287
|
async fetchShippingAddresses() {
|
|
@@ -562,24 +564,6 @@ class Store {
|
|
|
562
564
|
|
|
563
565
|
if (setting.user) {
|
|
564
566
|
setting.user.account_id = setting.account.id;
|
|
565
|
-
let oldsession = this.matchSession();
|
|
566
|
-
let session = setting.user.session;
|
|
567
|
-
|
|
568
|
-
if (session) {
|
|
569
|
-
if (session.id === oldsession.id) {
|
|
570
|
-
session._urls = oldsession._urls;
|
|
571
|
-
} else {}
|
|
572
|
-
} else {
|
|
573
|
-
session = oldsession;
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
session._urls = session._urls || [];
|
|
577
|
-
|
|
578
|
-
session._urls.push(location.href);
|
|
579
|
-
|
|
580
|
-
while (session._urls.length > 1000) session._urls.shift();
|
|
581
|
-
|
|
582
|
-
this.kv.put('session', session);
|
|
583
567
|
delete setting.user.session;
|
|
584
568
|
|
|
585
569
|
this._setUser(setting.user);
|
|
@@ -592,6 +576,10 @@ class Store {
|
|
|
592
576
|
delete setting.account;
|
|
593
577
|
}
|
|
594
578
|
|
|
579
|
+
let location = _index.default.get(setting, 'location', []);
|
|
580
|
+
|
|
581
|
+
this.cache.put('location', location);
|
|
582
|
+
|
|
595
583
|
let bots = _index.default.get(setting, 'bots', []);
|
|
596
584
|
|
|
597
585
|
let botM = {};
|
|
@@ -637,7 +625,11 @@ class Store {
|
|
|
637
625
|
|
|
638
626
|
async track() {
|
|
639
627
|
let user = this.kv.match('user') || {};
|
|
640
|
-
await this.api.sendContentView(this.device, location.href, document.title, this._currentViewingProduct.id, this._currentViewingProduct.source_id, this._currentViewingProduct.sku);
|
|
628
|
+
let out = await this.api.sendContentView(this.device, location.href, document.title, this._currentViewingProduct.id, this._currentViewingProduct.source_id, this._currentViewingProduct.sku);
|
|
629
|
+
|
|
630
|
+
let traffic_source = _index.default.get(out, 'body.by.device.source', '');
|
|
631
|
+
|
|
632
|
+
if (traffic_source) this.kv.put('traffic_source', traffic_source);
|
|
641
633
|
this.sendPresence();
|
|
642
634
|
}
|
|
643
635
|
|
|
@@ -983,12 +975,10 @@ class Store {
|
|
|
983
975
|
}
|
|
984
976
|
|
|
985
977
|
logBotRun(botid) {
|
|
986
|
-
let session = this.matchSession();
|
|
987
978
|
let log = this.kv.match('bot_run_logs') || {};
|
|
988
979
|
log[botid] = {
|
|
989
980
|
bot_id: botid,
|
|
990
|
-
created: this.now()
|
|
991
|
-
session_id: session.id
|
|
981
|
+
created: this.now()
|
|
992
982
|
};
|
|
993
983
|
this.kv.put('bot_run_logs', log);
|
|
994
984
|
}
|
|
@@ -996,11 +986,9 @@ class Store {
|
|
|
996
986
|
sendImpression(id) {
|
|
997
987
|
let user = this.kv.match('user') || {};
|
|
998
988
|
let log = this.kv.match('plugin_run_logs') || {};
|
|
999
|
-
let session = this.matchSession();
|
|
1000
989
|
log[id] = {
|
|
1001
990
|
web_plugin_id: id,
|
|
1002
|
-
created: this.now()
|
|
1003
|
-
session_id: session.id
|
|
991
|
+
created: this.now()
|
|
1004
992
|
};
|
|
1005
993
|
this.kv.put('plugin_run_logs', log);
|
|
1006
994
|
return this.api.sendImpression({
|
|
@@ -1009,8 +997,7 @@ class Store {
|
|
|
1009
997
|
web_plugin_id: id,
|
|
1010
998
|
user_id: user.id,
|
|
1011
999
|
url: window.location.href,
|
|
1012
|
-
device: this.device
|
|
1013
|
-
session_id: session.id
|
|
1000
|
+
device: this.device
|
|
1014
1001
|
});
|
|
1015
1002
|
}
|
|
1016
1003
|
|
|
@@ -1032,8 +1019,7 @@ class Store {
|
|
|
1032
1019
|
url: window.location.href,
|
|
1033
1020
|
device: this.device,
|
|
1034
1021
|
submission,
|
|
1035
|
-
impression_token: impressionToken
|
|
1036
|
-
session_id: this.matchSession().id
|
|
1022
|
+
impression_token: impressionToken
|
|
1037
1023
|
});
|
|
1038
1024
|
}
|
|
1039
1025
|
|
|
@@ -1079,7 +1065,7 @@ class Store {
|
|
|
1079
1065
|
async loopTime() {
|
|
1080
1066
|
let startms = _index.default.Date.now();
|
|
1081
1067
|
|
|
1082
|
-
if (!_index.default.get(this.kv.match('user'), 'id')) return setTimeout(() => this.loopTime(),
|
|
1068
|
+
if (!_index.default.get(this.kv.match('user'), 'id')) return setTimeout(() => this.loopTime(), 240000);
|
|
1083
1069
|
let {
|
|
1084
1070
|
body: t,
|
|
1085
1071
|
error
|
|
@@ -1091,7 +1077,7 @@ class Store {
|
|
|
1091
1077
|
var localMs = _index.default.Date.now();
|
|
1092
1078
|
|
|
1093
1079
|
this.timeDiff = Math.floor(serverMs - localMs);
|
|
1094
|
-
setTimeout(() => this.loopTime(),
|
|
1080
|
+
setTimeout(() => this.loopTime(), 240000);
|
|
1095
1081
|
}
|
|
1096
1082
|
|
|
1097
1083
|
replaceFileUrl(src) {
|
|
@@ -1232,7 +1218,10 @@ function sendToFBPixel(category, action, label) {
|
|
|
1232
1218
|
}
|
|
1233
1219
|
|
|
1234
1220
|
function sendToGA(category, action, label) {
|
|
1235
|
-
|
|
1221
|
+
if (window.gtag) window.gtag('event', category, {
|
|
1222
|
+
Action: action,
|
|
1223
|
+
Label: label
|
|
1224
|
+
});
|
|
1236
1225
|
|
|
1237
1226
|
if (window.ga && window.ga.getAll) {
|
|
1238
1227
|
const allTrackers = window.ga.getAll() || [];
|
|
@@ -1240,11 +1229,6 @@ function sendToGA(category, action, label) {
|
|
|
1240
1229
|
const name = tracker.get('name');
|
|
1241
1230
|
window.ga(name + '.send', 'event', category, action, label);
|
|
1242
1231
|
});
|
|
1243
|
-
} else {
|
|
1244
|
-
if (window.gtag) window.gtag('event', category, {
|
|
1245
|
-
Action: action,
|
|
1246
|
-
Label: label
|
|
1247
|
-
});
|
|
1248
1232
|
}
|
|
1249
1233
|
}
|
|
1250
1234
|
|
|
@@ -750,10 +750,9 @@ function osName() {
|
|
|
750
750
|
function check_frequently(freq, lastrun, store) {
|
|
751
751
|
if (!lastrun) return true;
|
|
752
752
|
if (op.get(freq, 'once_per_user')) return false;
|
|
753
|
-
var session = store.matchSession() || {};
|
|
754
753
|
|
|
755
754
|
if (op.get(freq, 'once_per_session')) {
|
|
756
|
-
if (lastrun.
|
|
755
|
+
if (sameDay(lastrun.created, Date.now())) return false;
|
|
757
756
|
}
|
|
758
757
|
|
|
759
758
|
if (op.get(freq, 'interval_sec')) {
|
|
@@ -766,7 +765,7 @@ function check_frequently(freq, lastrun, store) {
|
|
|
766
765
|
|
|
767
766
|
function checkRunConditions(freq, conds, lastrun, store) {
|
|
768
767
|
var acc = store.matchAccount() || {};
|
|
769
|
-
var
|
|
768
|
+
var location = store.matchLocation() || {};
|
|
770
769
|
if (!check_frequently(freq, lastrun, store)) return false;
|
|
771
770
|
|
|
772
771
|
for (var i = 0; i < size(conds); i++) {
|
|
@@ -806,15 +805,15 @@ function checkRunConditions(freq, conds, lastrun, store) {
|
|
|
806
805
|
if (size(cond.exclude_locations) > 0) {
|
|
807
806
|
let found = find(cond.exclude_locations, loc => {
|
|
808
807
|
if (loc.city_name && loc.country_code) {
|
|
809
|
-
if (loc.city_name ===
|
|
808
|
+
if (loc.city_name === location.city_name && loc.country_code === location.country_code) return true;
|
|
810
809
|
}
|
|
811
810
|
|
|
812
811
|
if (loc.city_name && !loc.country_code) {
|
|
813
|
-
if (loc.city_name ===
|
|
812
|
+
if (loc.city_name === location.city_name) return true;
|
|
814
813
|
}
|
|
815
814
|
|
|
816
815
|
if (!loc.city_name && loc.country_code) {
|
|
817
|
-
if (loc.country_code ===
|
|
816
|
+
if (loc.country_code === location.country_code) return true;
|
|
818
817
|
}
|
|
819
818
|
});
|
|
820
819
|
if (found) return false;
|
|
@@ -823,15 +822,15 @@ function checkRunConditions(freq, conds, lastrun, store) {
|
|
|
823
822
|
if (size(cond.locations) > 0) {
|
|
824
823
|
let found = find(cond.locations, loc => {
|
|
825
824
|
if (loc.city_name && loc.country_code) {
|
|
826
|
-
if (loc.city_name ===
|
|
825
|
+
if (loc.city_name === location.city_name && loc.country_code === location.country_code) return true;
|
|
827
826
|
}
|
|
828
827
|
|
|
829
828
|
if (loc.city_name && !loc.country_code) {
|
|
830
|
-
if (loc.city_name ===
|
|
829
|
+
if (loc.city_name === location.city_name) return true;
|
|
831
830
|
}
|
|
832
831
|
|
|
833
832
|
if (!loc.city_name && loc.country_code) {
|
|
834
|
-
if (loc.country_code ===
|
|
833
|
+
if (loc.country_code === location.country_code) return true;
|
|
835
834
|
}
|
|
836
835
|
});
|
|
837
836
|
if (!found) return false;
|
|
@@ -895,7 +894,8 @@ function checkRunConditions(freq, conds, lastrun, store) {
|
|
|
895
894
|
|
|
896
895
|
case 'source':
|
|
897
896
|
if (size(cond.sources) > 0) {
|
|
898
|
-
|
|
897
|
+
let source = store.matchTrafficSource();
|
|
898
|
+
if (!find(cond.sources, src => norm(src) === norm(source))) return false;
|
|
899
899
|
}
|
|
900
900
|
|
|
901
901
|
break;
|