@constructor-io/constructorio-client-javascript 2.37.0 → 2.37.1
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/lib/constructorio.js +36 -60
- package/lib/modules/autocomplete.js +40 -55
- package/lib/modules/browse.js +86 -130
- package/lib/modules/quizzes.js +39 -60
- package/lib/modules/recommendations.js +38 -52
- package/lib/modules/search.js +66 -91
- package/lib/modules/tracker.js +430 -656
- package/lib/utils/botlist.js +1 -1
- package/lib/utils/event-dispatcher.js +14 -20
- package/lib/utils/events.js +29 -95
- package/lib/utils/helpers.js +7 -29
- package/lib/utils/humanity-check.js +10 -19
- package/lib/utils/request-queue.js +28 -48
- package/lib/utils/store.js +2 -3
- package/lib/utils/store.overflow.js +6 -27
- package/package.json +1 -1
package/lib/utils/helpers.js
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
6
|
-
|
|
7
5
|
/* eslint-disable no-param-reassign */
|
|
8
6
|
var CRC32 = require('crc-32');
|
|
9
|
-
|
|
10
7
|
var store = require('./store');
|
|
11
|
-
|
|
12
8
|
var purchaseEventStorageKey = '_constructorio_purchase_order_ids';
|
|
13
9
|
var PII_REGEX = {
|
|
14
10
|
email: /^[\w\-+\\.]+@([\w-]+\.)+[\w-]{2,4}$/,
|
|
15
11
|
phoneNumber: /^(?:\+\d{11,12}|\+\d{1,3}\s\d{3}\s\d{3}\s\d{3,4}|\(\d{3}\)\d{7}|\(\d{3}\)\s\d{3}\s\d{4}|\(\d{3}\)\d{3}-\d{4}|\(\d{3}\)\s\d{3}-\d{4})$/,
|
|
16
12
|
creditCard: /^(?:4[0-9]{12}(?:[0-9]{3})?|(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|6(?:011|5[0-9]{2})[0-9]{12}|(?:2131|1800|35\d{3})\d{11})$/ // Visa, Mastercard, Amex, Discover, JCB and Diners Club, regex source: https://www.regular-expressions.info/creditcard.html
|
|
17
13
|
// Add more PII REGEX
|
|
18
|
-
|
|
19
14
|
};
|
|
15
|
+
|
|
20
16
|
var utils = {
|
|
21
17
|
trimNonBreakingSpaces: function trimNonBreakingSpaces(string) {
|
|
22
18
|
return string.replace(/\s/g, ' ').trim();
|
|
@@ -31,7 +27,6 @@ var utils = {
|
|
|
31
27
|
var cleanedParams = {};
|
|
32
28
|
Object.keys(paramsObj).forEach(function (paramKey) {
|
|
33
29
|
var paramValue = paramsObj[paramKey];
|
|
34
|
-
|
|
35
30
|
if (typeof paramValue === 'string') {
|
|
36
31
|
// Replace non-breaking spaces (or any other type of spaces caught by the regex)
|
|
37
32
|
// - with a regular white space
|
|
@@ -69,7 +64,6 @@ var utils = {
|
|
|
69
64
|
if (utils.canUseDOM()) {
|
|
70
65
|
return window.navigator;
|
|
71
66
|
}
|
|
72
|
-
|
|
73
67
|
return {
|
|
74
68
|
userAgent: '',
|
|
75
69
|
webdriver: false
|
|
@@ -82,7 +76,6 @@ var utils = {
|
|
|
82
76
|
if (utils.canUseDOM()) {
|
|
83
77
|
return window.location;
|
|
84
78
|
}
|
|
85
|
-
|
|
86
79
|
return {};
|
|
87
80
|
},
|
|
88
81
|
dispatchEvent: function dispatchEvent(event) {
|
|
@@ -102,48 +95,40 @@ var utils = {
|
|
|
102
95
|
return evt;
|
|
103
96
|
}
|
|
104
97
|
}
|
|
105
|
-
|
|
106
98
|
return null;
|
|
107
99
|
},
|
|
108
100
|
hasOrderIdRecord: function hasOrderIdRecord(orderId) {
|
|
109
101
|
var orderIdHash = CRC32.str(orderId.toString());
|
|
110
102
|
var purchaseEventStorage = store.local.get(purchaseEventStorageKey);
|
|
111
|
-
|
|
112
103
|
if (typeof purchaseEventStorage === 'string') {
|
|
113
104
|
purchaseEventStorage = JSON.parse(purchaseEventStorage);
|
|
114
105
|
}
|
|
115
|
-
|
|
116
106
|
if (purchaseEventStorage && purchaseEventStorage.includes(orderIdHash)) {
|
|
117
107
|
return true;
|
|
118
108
|
}
|
|
119
|
-
|
|
120
109
|
return null;
|
|
121
110
|
},
|
|
122
111
|
addOrderIdRecord: function addOrderIdRecord(orderId) {
|
|
123
112
|
var orderIdHash = CRC32.str(orderId.toString());
|
|
124
113
|
var purchaseEventStorage = store.local.get(purchaseEventStorageKey);
|
|
125
|
-
|
|
126
114
|
if (typeof purchaseEventStorage === 'string') {
|
|
127
115
|
purchaseEventStorage = JSON.parse(purchaseEventStorage);
|
|
128
116
|
}
|
|
129
|
-
|
|
130
117
|
if (purchaseEventStorage) {
|
|
131
118
|
// If the order already exists, do nothing
|
|
132
119
|
if (purchaseEventStorage.includes(orderIdHash)) {
|
|
133
120
|
return;
|
|
134
121
|
}
|
|
135
|
-
|
|
136
122
|
if (purchaseEventStorage.length >= 10) {
|
|
137
123
|
purchaseEventStorage = purchaseEventStorage.slice(-9);
|
|
138
124
|
}
|
|
139
|
-
|
|
140
125
|
purchaseEventStorage.push(orderIdHash);
|
|
141
126
|
} else {
|
|
142
127
|
// Create a new object map for the order ids
|
|
143
128
|
purchaseEventStorage = [orderIdHash];
|
|
144
|
-
}
|
|
145
|
-
|
|
129
|
+
}
|
|
146
130
|
|
|
131
|
+
// Push the order id map into local storage
|
|
147
132
|
store.local.set(purchaseEventStorageKey, purchaseEventStorage);
|
|
148
133
|
},
|
|
149
134
|
// Abort network request based on supplied timeout interval (in milliseconds)
|
|
@@ -155,7 +140,6 @@ var utils = {
|
|
|
155
140
|
var optionsTimeout = options && options.networkParameters && options.networkParameters.timeout;
|
|
156
141
|
var networkParametersTimeout = networkParameters && networkParameters.timeout;
|
|
157
142
|
var timeout = networkParametersTimeout || optionsTimeout;
|
|
158
|
-
|
|
159
143
|
if (typeof timeout === 'number' && controller) {
|
|
160
144
|
setTimeout(function () {
|
|
161
145
|
return controller.abort();
|
|
@@ -166,16 +150,15 @@ var utils = {
|
|
|
166
150
|
if (!object) {
|
|
167
151
|
return '';
|
|
168
152
|
}
|
|
169
|
-
|
|
170
153
|
var allValues = [];
|
|
171
154
|
Object.keys(object).forEach(function (key) {
|
|
172
155
|
var value = object[key];
|
|
173
156
|
var encodedKey = utils.encodeURIComponentRFC3986(key);
|
|
174
|
-
var stringifiedValue;
|
|
157
|
+
var stringifiedValue;
|
|
175
158
|
|
|
159
|
+
// Check for both null and undefined
|
|
176
160
|
if (value != null) {
|
|
177
161
|
var nextPrefix = prefix ? "".concat(prefix, "%5B").concat(encodedKey, "%5D") : encodedKey;
|
|
178
|
-
|
|
179
162
|
if (Array.isArray(value)) {
|
|
180
163
|
stringifiedValue = utils.stringify(value, nextPrefix, 'array');
|
|
181
164
|
} else if ((0, _typeof2["default"])(value) === 'object') {
|
|
@@ -185,7 +168,6 @@ var utils = {
|
|
|
185
168
|
} else {
|
|
186
169
|
stringifiedValue = "".concat(prefix || encodedKey, "=").concat(utils.encodeURIComponentRFC3986(value));
|
|
187
170
|
}
|
|
188
|
-
|
|
189
171
|
allValues.push(stringifiedValue);
|
|
190
172
|
}
|
|
191
173
|
});
|
|
@@ -215,29 +197,25 @@ var utils = {
|
|
|
215
197
|
requestContainsPii: function requestContainsPii(urlString) {
|
|
216
198
|
try {
|
|
217
199
|
var _decodeURI, _decodeURIComponent;
|
|
218
|
-
|
|
219
200
|
var url = new URL(urlString);
|
|
220
201
|
var paths = (_decodeURI = decodeURI(url === null || url === void 0 ? void 0 : url.pathname)) === null || _decodeURI === void 0 ? void 0 : _decodeURI.split('/');
|
|
221
202
|
var paramValues = (_decodeURIComponent = decodeURIComponent(url === null || url === void 0 ? void 0 : url.search)) === null || _decodeURIComponent === void 0 ? void 0 : _decodeURIComponent.split('&').map(function (param) {
|
|
222
203
|
var _param$split;
|
|
223
|
-
|
|
224
204
|
return param === null || param === void 0 ? void 0 : (_param$split = param.split('=')) === null || _param$split === void 0 ? void 0 : _param$split[1];
|
|
225
205
|
});
|
|
226
|
-
|
|
227
206
|
if (paths.some(function (path) {
|
|
228
207
|
return utils.containsPii(path);
|
|
229
208
|
})) {
|
|
230
209
|
return true;
|
|
231
210
|
}
|
|
232
|
-
|
|
233
211
|
if (paramValues.some(function (value) {
|
|
234
212
|
return utils.containsPii(value);
|
|
235
213
|
})) {
|
|
236
214
|
return true;
|
|
237
215
|
}
|
|
238
|
-
} catch (e) {
|
|
216
|
+
} catch (e) {
|
|
217
|
+
// do nothing
|
|
239
218
|
}
|
|
240
|
-
|
|
241
219
|
return false;
|
|
242
220
|
}
|
|
243
221
|
};
|
|
@@ -1,72 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
6
|
-
|
|
7
5
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
8
|
-
|
|
9
6
|
/* eslint-disable class-methods-use-this */
|
|
10
7
|
var store = require('./store');
|
|
11
|
-
|
|
12
8
|
var botList = require('./botlist');
|
|
13
|
-
|
|
14
9
|
var helpers = require('./helpers');
|
|
15
|
-
|
|
16
10
|
var storageKey = '_constructorio_is_human';
|
|
17
11
|
var humanEvents = ['scroll', 'resize', 'touchmove', 'mouseover', 'mousemove', 'keydown', 'keypress', 'keyup', 'focus'];
|
|
18
|
-
|
|
19
12
|
var HumanityCheck = /*#__PURE__*/function () {
|
|
20
13
|
function HumanityCheck() {
|
|
21
14
|
var _this = this;
|
|
22
|
-
|
|
23
15
|
(0, _classCallCheck2["default"])(this, HumanityCheck);
|
|
24
|
-
this.isHumanBoolean = this.getIsHumanFromSessionStorage();
|
|
16
|
+
this.isHumanBoolean = this.getIsHumanFromSessionStorage();
|
|
25
17
|
|
|
18
|
+
// Humanity proved, remove handlers to prove humanity
|
|
26
19
|
var remove = function remove() {
|
|
27
20
|
_this.isHumanBoolean = true;
|
|
28
21
|
store.session.set(storageKey, true);
|
|
29
22
|
humanEvents.forEach(function (eventType) {
|
|
30
23
|
helpers.removeEventListener(eventType, remove, true);
|
|
31
24
|
});
|
|
32
|
-
};
|
|
33
|
-
|
|
25
|
+
};
|
|
34
26
|
|
|
27
|
+
// Add handlers to prove humanity
|
|
35
28
|
if (!this.isHumanBoolean) {
|
|
36
29
|
humanEvents.forEach(function (eventType) {
|
|
37
30
|
helpers.addEventListener(eventType, remove, true);
|
|
38
31
|
});
|
|
39
32
|
}
|
|
40
33
|
}
|
|
41
|
-
|
|
42
34
|
(0, _createClass2["default"])(HumanityCheck, [{
|
|
43
35
|
key: "getIsHumanFromSessionStorage",
|
|
44
36
|
value: function getIsHumanFromSessionStorage() {
|
|
45
37
|
return !!store.session.get(storageKey) || false;
|
|
46
|
-
}
|
|
38
|
+
}
|
|
47
39
|
|
|
40
|
+
// Return boolean indicating if is human
|
|
48
41
|
}, {
|
|
49
42
|
key: "isHuman",
|
|
50
43
|
value: function isHuman() {
|
|
51
44
|
return this.isHumanBoolean || !!store.session.get(storageKey);
|
|
52
|
-
}
|
|
45
|
+
}
|
|
53
46
|
|
|
47
|
+
// Return boolean indicating if useragent matches botlist
|
|
54
48
|
}, {
|
|
55
49
|
key: "isBot",
|
|
56
50
|
value: function isBot() {
|
|
57
51
|
if (this.getIsHumanFromSessionStorage()) {
|
|
58
52
|
return false;
|
|
59
53
|
}
|
|
60
|
-
|
|
61
54
|
var _helpers$getNavigator = helpers.getNavigator(),
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
userAgent = _helpers$getNavigator.userAgent,
|
|
56
|
+
webdriver = _helpers$getNavigator.webdriver;
|
|
65
57
|
var botRegex = new RegExp("(".concat(botList.join('|'), ")"));
|
|
66
58
|
return Boolean(userAgent.match(botRegex)) || Boolean(webdriver);
|
|
67
59
|
}
|
|
68
60
|
}]);
|
|
69
61
|
return HumanityCheck;
|
|
70
62
|
}();
|
|
71
|
-
|
|
72
63
|
module.exports = HumanityCheck;
|
|
@@ -1,28 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
6
|
-
|
|
7
5
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
8
|
-
|
|
9
6
|
/* eslint-disable brace-style, no-unneeded-ternary */
|
|
10
7
|
var store = require('./store');
|
|
11
|
-
|
|
12
8
|
var HumanityCheck = require('./humanity-check');
|
|
13
|
-
|
|
14
9
|
var helpers = require('./helpers');
|
|
15
|
-
|
|
16
10
|
var _require = require('./helpers'),
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
requestContainsPii = _require.requestContainsPii;
|
|
19
12
|
var storageKey = '_constructorio_requests';
|
|
20
13
|
var requestTTL = 180000; // 3 minutes in milliseconds
|
|
21
|
-
|
|
22
14
|
var RequestQueue = /*#__PURE__*/function () {
|
|
23
15
|
function RequestQueue(options, eventemitter) {
|
|
24
16
|
var _this = this;
|
|
25
|
-
|
|
26
17
|
(0, _classCallCheck2["default"])(this, RequestQueue);
|
|
27
18
|
this.options = options;
|
|
28
19
|
this.eventemitter = eventemitter;
|
|
@@ -30,30 +21,27 @@ var RequestQueue = /*#__PURE__*/function () {
|
|
|
30
21
|
this.requestPending = false;
|
|
31
22
|
this.pageUnloading = false;
|
|
32
23
|
this.sendTrackingEvents = options && options.sendTrackingEvents === true ? true : false; // Defaults to 'false'
|
|
33
|
-
// Mark if page environment is unloading
|
|
34
24
|
|
|
25
|
+
// Mark if page environment is unloading
|
|
35
26
|
helpers.addEventListener('beforeunload', function () {
|
|
36
27
|
_this.pageUnloading = true;
|
|
37
28
|
});
|
|
38
|
-
|
|
39
29
|
if (this.sendTrackingEvents) {
|
|
40
30
|
this.send();
|
|
41
31
|
}
|
|
42
|
-
}
|
|
43
|
-
|
|
32
|
+
}
|
|
44
33
|
|
|
34
|
+
// Add request to queue to be dispatched
|
|
45
35
|
(0, _createClass2["default"])(RequestQueue, [{
|
|
46
36
|
key: "queue",
|
|
47
37
|
value: function queue(url) {
|
|
48
38
|
var method = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'GET';
|
|
49
39
|
var body = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
50
40
|
var networkParameters = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
51
|
-
|
|
52
41
|
if (this.sendTrackingEvents && !this.humanity.isBot()) {
|
|
53
42
|
if (requestContainsPii(url, body)) {
|
|
54
43
|
return;
|
|
55
44
|
}
|
|
56
|
-
|
|
57
45
|
var queue = RequestQueue.get();
|
|
58
46
|
queue.push({
|
|
59
47
|
url: url,
|
|
@@ -63,63 +51,59 @@ var RequestQueue = /*#__PURE__*/function () {
|
|
|
63
51
|
});
|
|
64
52
|
RequestQueue.set(queue);
|
|
65
53
|
}
|
|
66
|
-
}
|
|
54
|
+
}
|
|
67
55
|
|
|
56
|
+
// Read from queue and send events to server
|
|
68
57
|
}, {
|
|
69
58
|
key: "sendEvents",
|
|
70
59
|
value: function sendEvents() {
|
|
71
60
|
var _this2 = this;
|
|
72
|
-
|
|
73
61
|
var fetch = this.options.fetch;
|
|
74
62
|
var queue = RequestQueue.get();
|
|
75
|
-
|
|
76
|
-
|
|
63
|
+
if (
|
|
64
|
+
// Consider user "human" if no DOM context is available
|
|
77
65
|
(!helpers.canUseDOM() || this.humanity.isHuman()) && !this.requestPending && !this.pageUnloading && queue.length) {
|
|
78
66
|
var request;
|
|
79
67
|
var nextInQueue = queue.shift();
|
|
80
68
|
var _nextInQueue = nextInQueue,
|
|
81
|
-
|
|
69
|
+
networkParameters = _nextInQueue.networkParameters;
|
|
82
70
|
var signal;
|
|
83
71
|
var instance = this;
|
|
84
72
|
RequestQueue.set(queue);
|
|
85
|
-
|
|
86
73
|
if (networkParameters && typeof AbortController === 'function') {
|
|
87
74
|
var controller = new AbortController();
|
|
88
75
|
signal = controller.signal;
|
|
89
76
|
helpers.applyNetworkTimeout(this.options, networkParameters, controller);
|
|
90
|
-
}
|
|
91
|
-
// - Request queue entries used to be strings with 'GET' method assumed
|
|
92
|
-
|
|
77
|
+
}
|
|
93
78
|
|
|
79
|
+
// Backwards compatibility with versions <= 2.0.0, can be removed in future
|
|
80
|
+
// - Request queue entries used to be strings with 'GET' method assumed
|
|
94
81
|
if (typeof nextInQueue === 'string') {
|
|
95
82
|
nextInQueue = {
|
|
96
83
|
url: nextInQueue,
|
|
97
84
|
method: 'GET'
|
|
98
85
|
};
|
|
99
|
-
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// If events older than `requestTTL` exist in queue, clear request queue
|
|
100
89
|
// - Prevents issue where stale items are sent in perpetuity
|
|
101
90
|
// - No request should go unsent for longer than `requestTTL`
|
|
102
|
-
|
|
103
|
-
|
|
104
91
|
if (nextInQueue.url) {
|
|
105
92
|
// Pull `dt` parameter from URL, indicating origin time of request
|
|
106
93
|
var dtMatch = nextInQueue.url.match(/\?.*_dt=([^&]+)/);
|
|
107
94
|
var requestOriginTime = parseInt(dtMatch && dtMatch[1], 10);
|
|
108
95
|
var now = +new Date();
|
|
109
|
-
|
|
110
96
|
if (requestOriginTime && Number.isInteger(requestOriginTime) && now - requestOriginTime > requestTTL) {
|
|
111
97
|
this.sendTrackingEvents = false;
|
|
112
98
|
RequestQueue.remove();
|
|
113
99
|
return;
|
|
114
100
|
}
|
|
115
101
|
}
|
|
116
|
-
|
|
117
102
|
if (nextInQueue.method === 'GET') {
|
|
118
103
|
request = fetch(nextInQueue.url, {
|
|
119
104
|
signal: signal
|
|
120
105
|
});
|
|
121
106
|
}
|
|
122
|
-
|
|
123
107
|
if (nextInQueue.method === 'POST') {
|
|
124
108
|
request = fetch(nextInQueue.url, {
|
|
125
109
|
method: nextInQueue.method,
|
|
@@ -131,7 +115,6 @@ var RequestQueue = /*#__PURE__*/function () {
|
|
|
131
115
|
signal: signal
|
|
132
116
|
});
|
|
133
117
|
}
|
|
134
|
-
|
|
135
118
|
if (request) {
|
|
136
119
|
this.requestPending = true;
|
|
137
120
|
request.then(function (response) {
|
|
@@ -144,11 +127,11 @@ var RequestQueue = /*#__PURE__*/function () {
|
|
|
144
127
|
message: 'ok'
|
|
145
128
|
});
|
|
146
129
|
}
|
|
147
|
-
|
|
148
130
|
_this2.requestPending = false;
|
|
149
|
-
|
|
150
131
|
_this2.send();
|
|
151
|
-
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Request was successful, but returned a non-2XX status code
|
|
152
135
|
else {
|
|
153
136
|
response.json().then(function (json) {
|
|
154
137
|
if (instance.eventemitter) {
|
|
@@ -158,9 +141,7 @@ var RequestQueue = /*#__PURE__*/function () {
|
|
|
158
141
|
message: json && json.message
|
|
159
142
|
});
|
|
160
143
|
}
|
|
161
|
-
|
|
162
144
|
_this2.requestPending = false;
|
|
163
|
-
|
|
164
145
|
_this2.send();
|
|
165
146
|
})["catch"](function (error) {
|
|
166
147
|
if (instance.eventemitter) {
|
|
@@ -170,9 +151,7 @@ var RequestQueue = /*#__PURE__*/function () {
|
|
|
170
151
|
message: error.type
|
|
171
152
|
});
|
|
172
153
|
}
|
|
173
|
-
|
|
174
154
|
_this2.requestPending = false;
|
|
175
|
-
|
|
176
155
|
_this2.send();
|
|
177
156
|
});
|
|
178
157
|
}
|
|
@@ -184,15 +163,14 @@ var RequestQueue = /*#__PURE__*/function () {
|
|
|
184
163
|
message: error && error.toString && error.toString()
|
|
185
164
|
});
|
|
186
165
|
}
|
|
187
|
-
|
|
188
166
|
_this2.requestPending = false;
|
|
189
|
-
|
|
190
167
|
_this2.send();
|
|
191
168
|
});
|
|
192
169
|
}
|
|
193
170
|
}
|
|
194
|
-
}
|
|
171
|
+
}
|
|
195
172
|
|
|
173
|
+
// Read from queue and send requests to server
|
|
196
174
|
}, {
|
|
197
175
|
key: "send",
|
|
198
176
|
value: function send() {
|
|
@@ -204,14 +182,16 @@ var RequestQueue = /*#__PURE__*/function () {
|
|
|
204
182
|
setTimeout(this.sendEvents.bind(this), this.options && this.options.trackingSendDelay || 250);
|
|
205
183
|
}
|
|
206
184
|
}
|
|
207
|
-
}
|
|
185
|
+
}
|
|
208
186
|
|
|
187
|
+
// Return current request queue
|
|
209
188
|
}], [{
|
|
210
189
|
key: "get",
|
|
211
190
|
value: function get() {
|
|
212
191
|
return store.local.get(storageKey) || [];
|
|
213
|
-
}
|
|
192
|
+
}
|
|
214
193
|
|
|
194
|
+
// Update current request queue
|
|
215
195
|
}, {
|
|
216
196
|
key: "set",
|
|
217
197
|
value: function set(queue) {
|
|
@@ -221,17 +201,18 @@ var RequestQueue = /*#__PURE__*/function () {
|
|
|
221
201
|
} else {
|
|
222
202
|
store.local.set(storageKey, queue);
|
|
223
203
|
}
|
|
204
|
+
var localStorageQueue = RequestQueue.get();
|
|
224
205
|
|
|
225
|
-
|
|
206
|
+
// Ensure storage queue was set correctly in storage by checking length
|
|
226
207
|
// - Otherwise remove all pending requests as preventative measure
|
|
227
208
|
// - Firefox seeing identical events being transmitted multiple times
|
|
228
|
-
|
|
229
209
|
if (Array.isArray(localStorageQueue) && localStorageQueue.length !== queue.length) {
|
|
230
210
|
this.sendTrackingEvents = false;
|
|
231
211
|
RequestQueue.remove();
|
|
232
212
|
}
|
|
233
|
-
}
|
|
213
|
+
}
|
|
234
214
|
|
|
215
|
+
// Remove current request queue key
|
|
235
216
|
}, {
|
|
236
217
|
key: "remove",
|
|
237
218
|
value: function remove() {
|
|
@@ -240,5 +221,4 @@ var RequestQueue = /*#__PURE__*/function () {
|
|
|
240
221
|
}]);
|
|
241
222
|
return RequestQueue;
|
|
242
223
|
}();
|
|
243
|
-
|
|
244
224
|
module.exports = RequestQueue;
|
package/lib/utils/store.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var store = require('store2');
|
|
4
|
+
var overflow = require('./store.overflow');
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
// Inject overflow into store
|
|
6
7
|
// https://raw.githubusercontent.com/nbubna/store/master/src/store.overflow.js
|
|
7
|
-
|
|
8
|
-
|
|
9
8
|
overflow(store, store._);
|
|
10
9
|
module.exports = store;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
/* eslint-disable */
|
|
4
|
-
|
|
5
4
|
/**
|
|
6
5
|
* Copyright (c) 2013 ESHA Research
|
|
7
6
|
* Dual licensed under the MIT and GPL licenses:
|
|
@@ -19,29 +18,24 @@
|
|
|
19
18
|
*/
|
|
20
19
|
module.exports = function (store, _) {
|
|
21
20
|
var _set = _.set,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
_get = _.get,
|
|
22
|
+
_remove = _.remove,
|
|
23
|
+
_key = _.key,
|
|
24
|
+
_length = _.length,
|
|
25
|
+
_clear = _.clear;
|
|
28
26
|
_.overflow = function (area, create) {
|
|
29
27
|
var name = area === _.areas.local ? '+local+' : area === _.areas.session ? '+session+' : false;
|
|
30
|
-
|
|
31
28
|
if (name) {
|
|
32
29
|
var overflow = _.areas[name];
|
|
33
|
-
|
|
34
30
|
if (create && !overflow) {
|
|
35
31
|
overflow = store.area(name)._area; // area() copies to _.areas
|
|
36
32
|
} else if (create === false) {
|
|
37
33
|
delete _.areas[name];
|
|
38
34
|
delete store[name];
|
|
39
35
|
}
|
|
40
|
-
|
|
41
36
|
return overflow;
|
|
42
37
|
}
|
|
43
38
|
};
|
|
44
|
-
|
|
45
39
|
_.set = function (area, key, string) {
|
|
46
40
|
try {
|
|
47
41
|
_set.apply(this, arguments);
|
|
@@ -50,36 +44,26 @@ module.exports = function (store, _) {
|
|
|
50
44
|
// the e.toString is needed for IE9 / IE10, cos name is empty there
|
|
51
45
|
return _.set(_.overflow(area, true), key, string);
|
|
52
46
|
}
|
|
53
|
-
|
|
54
47
|
throw e;
|
|
55
48
|
}
|
|
56
49
|
};
|
|
57
|
-
|
|
58
50
|
_.get = function (area, key) {
|
|
59
51
|
var overflow = _.overflow(area);
|
|
60
|
-
|
|
61
52
|
return overflow && _get.call(this, overflow, key) || _get.apply(this, arguments);
|
|
62
53
|
};
|
|
63
|
-
|
|
64
54
|
_.remove = function (area, key) {
|
|
65
55
|
var overflow = _.overflow(area);
|
|
66
|
-
|
|
67
56
|
if (overflow) {
|
|
68
57
|
_remove.call(this, overflow, key);
|
|
69
58
|
}
|
|
70
|
-
|
|
71
59
|
_remove.apply(this, arguments);
|
|
72
60
|
};
|
|
73
|
-
|
|
74
61
|
_.key = function (area, i) {
|
|
75
62
|
var overflow = _.overflow(area);
|
|
76
|
-
|
|
77
63
|
if (overflow) {
|
|
78
64
|
var l = _length.call(this, area);
|
|
79
|
-
|
|
80
65
|
if (i >= l) {
|
|
81
66
|
i = i - l; // make i overflow-relative
|
|
82
|
-
|
|
83
67
|
for (var j = 0, m = _length.call(this, overflow); j < m; j++) {
|
|
84
68
|
if (j === i) {
|
|
85
69
|
// j is overflow index
|
|
@@ -88,20 +72,15 @@ module.exports = function (store, _) {
|
|
|
88
72
|
}
|
|
89
73
|
}
|
|
90
74
|
}
|
|
91
|
-
|
|
92
75
|
return _key.apply(this, arguments);
|
|
93
76
|
};
|
|
94
|
-
|
|
95
77
|
_.length = function (area) {
|
|
96
78
|
var length = _length(area),
|
|
97
|
-
|
|
98
|
-
|
|
79
|
+
overflow = _.overflow(area);
|
|
99
80
|
return overflow ? length + _length(overflow) : length;
|
|
100
81
|
};
|
|
101
|
-
|
|
102
82
|
_.clear = function (area) {
|
|
103
83
|
_.overflow(area, false);
|
|
104
|
-
|
|
105
84
|
_clear.apply(this, arguments);
|
|
106
85
|
};
|
|
107
86
|
};
|