@subiz/widget-v4 4.1.203 → 4.1.204
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/api.md +646 -706
- package/compiled_src/lib.js +12 -13
- package/compiled_src/store/store.js +20 -4
- package/compiled_src/util/event.test.js +38 -0
- package/dist/19e1c4525c1.app.js +1 -0
- package/dist/{19df158c2ea.chat.html → 19e1c4525c1.chat.html} +1 -1
- package/dist/19e1c4525c1.chat.js +1 -0
- package/dist/{19df158c2ea.form.html → 19e1c4525c1.form.html} +1 -1
- package/dist/19e1c4525c1.form.js +1 -0
- package/dist/{19df158c2ea.index.html → 19e1c4525c1.index.html} +1 -1
- package/dist/{19df158c2ea.library.html → 19e1c4525c1.library.html} +1 -1
- package/dist/19e1c4525c1.library.js +1 -0
- package/dist/{19df158c2ea.preview.html → 19e1c4525c1.preview.html} +1 -1
- package/dist/19e1c4525c1.preview.js +1 -0
- package/dist/19e1c4525c1.webview.js +1 -0
- package/dist/HASH +1 -1
- package/dist/screenshoot.js +50 -3
- package/package.json +3 -3
- package/src/lib.js +12 -13
- package/src/store/store.js +28 -19
- package/src/util/event.test.js +31 -0
- package/dist/19df158c2ea.app.js +0 -1
- package/dist/19df158c2ea.chat.js +0 -1
- package/dist/19df158c2ea.form.js +0 -1
- package/dist/19df158c2ea.library.js +0 -1
- package/dist/19df158c2ea.preview.js +0 -1
- package/dist/19df158c2ea.webview.js +0 -1
- /package/dist/{19df158c2ea.127.js → 19e1c4525c1.127.js} +0 -0
- /package/dist/{19df158c2ea.132.js → 19e1c4525c1.132.js} +0 -0
- /package/dist/{19df158c2ea.185.js → 19e1c4525c1.185.js} +0 -0
- /package/dist/{19df158c2ea.27.js → 19e1c4525c1.27.js} +0 -0
- /package/dist/{19df158c2ea.278.js → 19e1c4525c1.278.js} +0 -0
- /package/dist/{19df158c2ea.339.js → 19e1c4525c1.339.js} +0 -0
- /package/dist/{19df158c2ea.459.js → 19e1c4525c1.459.js} +0 -0
- /package/dist/{19df158c2ea.490.js → 19e1c4525c1.490.js} +0 -0
- /package/dist/{19df158c2ea.74.js → 19e1c4525c1.74.js} +0 -0
- /package/dist/{19df158c2ea.997.js → 19e1c4525c1.997.js} +0 -0
package/compiled_src/lib.js
CHANGED
|
@@ -21,21 +21,11 @@ class Widget {
|
|
|
21
21
|
_defineProperty(this, "setViewingProduct", p => this.store.linkProduct(p));
|
|
22
22
|
_defineProperty(this, "getViewingProduct", () => this.store.getLinkedProduct());
|
|
23
23
|
_defineProperty(this, "track", v => this.store.track(v));
|
|
24
|
-
_defineProperty(this, "event", async
|
|
24
|
+
_defineProperty(this, "event", async (type, payload, options) => {
|
|
25
25
|
await this.store.readyGate.entry();
|
|
26
|
-
return this.store.api.sendEvent(
|
|
27
|
-
});
|
|
28
|
-
_defineProperty(this, "pageview", v => {
|
|
29
|
-
v = v || {};
|
|
30
|
-
return this.event({
|
|
31
|
-
type: 'content_viewed',
|
|
32
|
-
payload: {
|
|
33
|
-
url: v.url || location.href,
|
|
34
|
-
title: v.title || document.title,
|
|
35
|
-
referrer: v.referrer || document.referrer
|
|
36
|
-
}
|
|
37
|
-
});
|
|
26
|
+
return this.store.api.sendEvent(normalizeCdpEvent(type, payload, options));
|
|
38
27
|
});
|
|
28
|
+
_defineProperty(this, "pageview", v => this.store.sendPageview(v));
|
|
39
29
|
this.impressionTokens = {};
|
|
40
30
|
this.domGate = new _index.default.Gate();
|
|
41
31
|
this.store = new _store.default(ApiURL, FileURL, RealtimeURL, inmem, fake);
|
|
@@ -379,5 +369,14 @@ class Widget {
|
|
|
379
369
|
this.store.doNotStartBot();
|
|
380
370
|
}
|
|
381
371
|
}
|
|
372
|
+
function normalizeCdpEvent(type, payload, options) {
|
|
373
|
+
if (type && typeof type === 'object') return type;
|
|
374
|
+
let data = {
|
|
375
|
+
type: type
|
|
376
|
+
};
|
|
377
|
+
if (payload !== undefined) data.payload = payload;
|
|
378
|
+
if (options && typeof options === 'object') data = Object.assign({}, options, data);
|
|
379
|
+
return data;
|
|
380
|
+
}
|
|
382
381
|
window.__sbz_WIDGET = Widget;
|
|
383
382
|
var _default = exports.default = Widget;
|
|
@@ -176,14 +176,14 @@ class Store {
|
|
|
176
176
|
_defineProperty(this, "checkFormToken", (accid, token) => this.api.checkFormToken(accid, token));
|
|
177
177
|
_defineProperty(this, "submitForm2", (accid, token, data) => this.api.submitForm2(accid, token, data));
|
|
178
178
|
_defineProperty(this, "sendPresence", _index.default.throttle(async () => {
|
|
179
|
+
if (!this._track_page_view) return;
|
|
179
180
|
if (this._die) return dieErr;
|
|
180
181
|
await this.readyGate.entry();
|
|
181
182
|
if (!_index.default.get(this.cache.match('user'), 'id')) return;
|
|
182
183
|
if (_index.default.isUserBanned(this.cache.match('user'))) return;
|
|
183
|
-
if (!this._track_page_view) return;
|
|
184
184
|
let hasfocus = this.browserVisibility === 'visible' && document.hasFocus();
|
|
185
185
|
if (!hasfocus) return this.api.sendLostFocus();
|
|
186
|
-
this.
|
|
186
|
+
this.sendPageview();
|
|
187
187
|
}, 1000, {
|
|
188
188
|
leading: false
|
|
189
189
|
}));
|
|
@@ -277,6 +277,13 @@ class Store {
|
|
|
277
277
|
this.sendPresence();
|
|
278
278
|
});
|
|
279
279
|
window.addEventListener('beforeunload', () => this.api.sendLostFocus());
|
|
280
|
+
this._lastPresenceURL = window.location.href;
|
|
281
|
+
this._urlCheckInterval = _index.default.setInterval(() => {
|
|
282
|
+
if (this._die) return _index.default.clearInterval(this._urlCheckInterval);
|
|
283
|
+
if (this._lastPresenceURL === window.location.href) return;
|
|
284
|
+
this._lastPresenceURL = window.location.href;
|
|
285
|
+
this.sendPresence();
|
|
286
|
+
}, 2_000);
|
|
280
287
|
this.doNotStartBot = () => {
|
|
281
288
|
this._donotstartbot = true;
|
|
282
289
|
};
|
|
@@ -798,12 +805,20 @@ class Store {
|
|
|
798
805
|
this.cache.put('payment_methods', pms);
|
|
799
806
|
this.pubsub.publish('account');
|
|
800
807
|
}
|
|
808
|
+
async sendPageview(p) {
|
|
809
|
+
if (!p) p = {};
|
|
810
|
+
let device = Object.assign({}, this.device);
|
|
811
|
+
if (p.referrer) device.source_referrer = p.referrer;
|
|
812
|
+
device.page_url = p.url || location.href;
|
|
813
|
+
device.page_title = p.title || document.title;
|
|
814
|
+
return this.api.sendContentView(device, p.url || location.href, p.title || document.title, this._currentViewingProduct.id, this._currentViewingProduct.source_id, this._currentViewingProduct.sku);
|
|
815
|
+
}
|
|
801
816
|
async track(e) {
|
|
802
817
|
if (!e) {
|
|
803
|
-
let out = await this.
|
|
818
|
+
let out = await this.sendPageview();
|
|
804
819
|
let traffic_source = _index.default.get(out, 'body.by.device.source', '');
|
|
805
820
|
if (traffic_source) this.kv.put('traffic_source', traffic_source);
|
|
806
|
-
return;
|
|
821
|
+
return out;
|
|
807
822
|
}
|
|
808
823
|
if (typeof e === 'object') {
|
|
809
824
|
if (!e.data) e.data = {};
|
|
@@ -1306,6 +1321,7 @@ class Store {
|
|
|
1306
1321
|
this._die = true;
|
|
1307
1322
|
this.clearBrowserData();
|
|
1308
1323
|
_index.default.clearInterval(this._seenInterval);
|
|
1324
|
+
_index.default.clearInterval(this._urlCheckInterval);
|
|
1309
1325
|
if (this.realtime) this.realtime.stop();
|
|
1310
1326
|
this.readyGate.close();
|
|
1311
1327
|
window.removeEventListener('blur', this.sendPresence);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var test = require('tape');
|
|
4
|
+
var {
|
|
5
|
+
normalizeCdpEvent
|
|
6
|
+
} = require('./event.js');
|
|
7
|
+
test('normalize cdp event new signature', t => {
|
|
8
|
+
t.deepEqual(normalizeCdpEvent('content_viewed', {
|
|
9
|
+
url: 'https://example.com/products/pd2345',
|
|
10
|
+
title: 'Bàn phím cơ không dây'
|
|
11
|
+
}, {
|
|
12
|
+
event_source_id: 'evt_1234'
|
|
13
|
+
}), {
|
|
14
|
+
type: 'content_viewed',
|
|
15
|
+
payload: {
|
|
16
|
+
url: 'https://example.com/products/pd2345',
|
|
17
|
+
title: 'Bàn phím cơ không dây'
|
|
18
|
+
},
|
|
19
|
+
event_source_id: 'evt_1234'
|
|
20
|
+
});
|
|
21
|
+
t.end();
|
|
22
|
+
});
|
|
23
|
+
test('normalize cdp event without payload', t => {
|
|
24
|
+
t.deepEqual(normalizeCdpEvent('login'), {
|
|
25
|
+
type: 'login'
|
|
26
|
+
});
|
|
27
|
+
t.end();
|
|
28
|
+
});
|
|
29
|
+
test('normalize cdp event keeps old object signature', t => {
|
|
30
|
+
let event = {
|
|
31
|
+
type: 'product_viewed',
|
|
32
|
+
payload: {
|
|
33
|
+
id: 'pd2345'
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
t.equal(normalizeCdpEvent(event), event);
|
|
37
|
+
t.end();
|
|
38
|
+
});
|