swetrix 2.4.0 → 3.0.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/.prettierrc.js +13 -0
- package/dist/esnext/Lib.d.ts +32 -14
- package/dist/esnext/Lib.js +38 -78
- package/dist/esnext/Lib.js.map +1 -1
- package/dist/esnext/index.js +1 -1
- package/dist/esnext/index.js.map +1 -1
- package/dist/esnext/utils.js.map +1 -1
- package/dist/swetrix.cjs.js +40 -83
- package/dist/swetrix.es5.js +40 -83
- package/dist/swetrix.js +1 -1
- package/dist/swetrix.orig.js +40 -83
- package/package.json +5 -5
- package/src/Lib.ts +88 -99
- package/src/index.ts +2 -4
package/dist/swetrix.es5.js
CHANGED
|
@@ -110,7 +110,7 @@ var Lib = /** @class */ (function () {
|
|
|
110
110
|
if (!this.canTrack()) {
|
|
111
111
|
return;
|
|
112
112
|
}
|
|
113
|
-
var data = __assign({ pid: this.projectID, pg: this.activePage, lc: getLocale(), tz: getTimezone(), ref: getReferrer(), so: getUTMSource(), me: getUTMMedium(), ca: getUTMCampaign() }
|
|
113
|
+
var data = __assign(__assign({}, event), { pid: this.projectID, pg: this.activePage, lc: getLocale(), tz: getTimezone(), ref: getReferrer(), so: getUTMSource(), me: getUTMMedium(), ca: getUTMCampaign() });
|
|
114
114
|
this.sendRequest('custom', data);
|
|
115
115
|
};
|
|
116
116
|
Lib.prototype.trackPageViews = function (options) {
|
|
@@ -121,14 +121,12 @@ var Lib = /** @class */ (function () {
|
|
|
121
121
|
return this.pageData.actions;
|
|
122
122
|
}
|
|
123
123
|
this.pageViewsOptions = options;
|
|
124
|
-
var
|
|
124
|
+
var interval;
|
|
125
125
|
if (!(options === null || options === void 0 ? void 0 : options.unique)) {
|
|
126
126
|
interval = setInterval(this.trackPathChange, 2000);
|
|
127
127
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
hbInterval = setInterval(this.heartbeat, 28000);
|
|
131
|
-
}
|
|
128
|
+
setTimeout(this.heartbeat, 3000);
|
|
129
|
+
var hbInterval = setInterval(this.heartbeat, 28000);
|
|
132
130
|
var path = getPath({
|
|
133
131
|
hash: options === null || options === void 0 ? void 0 : options.hash,
|
|
134
132
|
search: options === null || options === void 0 ? void 0 : options.search,
|
|
@@ -157,23 +155,17 @@ var Lib = /** @class */ (function () {
|
|
|
157
155
|
this.perfStatsCollected = true;
|
|
158
156
|
return {
|
|
159
157
|
// Network
|
|
160
|
-
//
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
// @ts-ignore
|
|
167
|
-
response: perf.responseEnd - perf.responseStart,
|
|
158
|
+
dns: perf.domainLookupEnd - perf.domainLookupStart, // DNS Resolution
|
|
159
|
+
tls: perf.secureConnectionStart ? perf.requestStart - perf.secureConnectionStart : 0, // TLS Setup; checking if secureConnectionStart is not 0 (it's 0 for non-https websites)
|
|
160
|
+
conn: perf.secureConnectionStart
|
|
161
|
+
? perf.secureConnectionStart - perf.connectStart
|
|
162
|
+
: perf.connectEnd - perf.connectStart, // Connection time
|
|
163
|
+
response: perf.responseEnd - perf.responseStart, // Response Time (Download)
|
|
168
164
|
// Frontend
|
|
169
|
-
//
|
|
170
|
-
|
|
171
|
-
//
|
|
172
|
-
dom_load: perf.domContentLoadedEventEnd - perf.responseEnd,
|
|
173
|
-
// @ts-ignore
|
|
174
|
-
page_load: perf.loadEventStart,
|
|
165
|
+
render: perf.domComplete - perf.domContentLoadedEventEnd, // Browser rendering the HTML time
|
|
166
|
+
dom_load: perf.domContentLoadedEventEnd - perf.responseEnd, // DOM loading timing
|
|
167
|
+
page_load: perf.loadEventStart, // Page load time
|
|
175
168
|
// Backend
|
|
176
|
-
// @ts-ignore
|
|
177
169
|
ttfb: perf.responseStart - perf.requestStart,
|
|
178
170
|
};
|
|
179
171
|
};
|
|
@@ -187,20 +179,6 @@ var Lib = /** @class */ (function () {
|
|
|
187
179
|
};
|
|
188
180
|
this.sendRequest('hb', data);
|
|
189
181
|
};
|
|
190
|
-
Lib.prototype.checkIgnore = function (path) {
|
|
191
|
-
var _a;
|
|
192
|
-
var ignore = (_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.ignore;
|
|
193
|
-
if (Array.isArray(ignore)) {
|
|
194
|
-
for (var i = 0; i < ignore.length; ++i) {
|
|
195
|
-
if (ignore[i] === path)
|
|
196
|
-
return true;
|
|
197
|
-
// @ts-ignore
|
|
198
|
-
if (ignore[i] instanceof RegExp && ignore[i].test(path))
|
|
199
|
-
return true;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
return false;
|
|
203
|
-
};
|
|
204
182
|
// Tracking path changes. If path changes -> calling this.trackPage method
|
|
205
183
|
Lib.prototype.trackPathChange = function () {
|
|
206
184
|
var _a, _b;
|
|
@@ -216,15 +194,10 @@ var Lib = /** @class */ (function () {
|
|
|
216
194
|
}
|
|
217
195
|
};
|
|
218
196
|
Lib.prototype.getPreviousPage = function () {
|
|
219
|
-
var _a, _b;
|
|
220
197
|
// Assuming that this function is called in trackPage and this.activePage is not overwritten by new value yet
|
|
221
198
|
// That method of getting previous page works for SPA websites
|
|
222
199
|
if (this.activePage) {
|
|
223
|
-
|
|
224
|
-
if (shouldIgnore && ((_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.doNotAnonymise)) {
|
|
225
|
-
return null;
|
|
226
|
-
}
|
|
227
|
-
return shouldIgnore ? null : this.activePage;
|
|
200
|
+
return this.activePage;
|
|
228
201
|
}
|
|
229
202
|
// Checking if URL is supported by the browser (for example, IE11 does not support it)
|
|
230
203
|
if (typeof URL === 'function') {
|
|
@@ -240,76 +213,60 @@ var Lib = /** @class */ (function () {
|
|
|
240
213
|
if (host !== refHost) {
|
|
241
214
|
return null;
|
|
242
215
|
}
|
|
243
|
-
|
|
244
|
-
if (shouldIgnore && ((_b = this.pageViewsOptions) === null || _b === void 0 ? void 0 : _b.doNotAnonymise)) {
|
|
245
|
-
return null;
|
|
246
|
-
}
|
|
247
|
-
return shouldIgnore ? null : pathname;
|
|
216
|
+
return pathname;
|
|
248
217
|
}
|
|
249
|
-
catch (
|
|
218
|
+
catch (_a) {
|
|
250
219
|
return null;
|
|
251
220
|
}
|
|
252
221
|
}
|
|
253
222
|
return null;
|
|
254
223
|
};
|
|
255
224
|
Lib.prototype.trackPage = function (pg, unique) {
|
|
256
|
-
var _a, _b;
|
|
257
225
|
if (unique === void 0) { unique = false; }
|
|
258
226
|
if (!this.pageData)
|
|
259
227
|
return;
|
|
260
228
|
this.pageData.path = pg;
|
|
261
|
-
var shouldIgnore = this.checkIgnore(pg);
|
|
262
|
-
if (shouldIgnore && ((_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.doNotAnonymise))
|
|
263
|
-
return;
|
|
264
229
|
var perf = this.getPerformanceStats();
|
|
265
|
-
var prev;
|
|
266
|
-
if (!((_b = this.pageViewsOptions) === null || _b === void 0 ? void 0 : _b.noUserFlow)) {
|
|
267
|
-
prev = this.getPreviousPage();
|
|
268
|
-
}
|
|
230
|
+
var prev = this.getPreviousPage();
|
|
269
231
|
this.activePage = pg;
|
|
270
|
-
this.submitPageView(
|
|
232
|
+
this.submitPageView(pg, prev, unique, perf, true);
|
|
271
233
|
};
|
|
272
|
-
Lib.prototype.submitPageView = function (pg, prev, unique, perf) {
|
|
273
|
-
var
|
|
234
|
+
Lib.prototype.submitPageView = function (pg, prev, unique, perf, evokeCallback) {
|
|
235
|
+
var _a;
|
|
236
|
+
var privateData = {
|
|
274
237
|
pid: this.projectID,
|
|
238
|
+
perf: perf,
|
|
239
|
+
unique: unique,
|
|
240
|
+
};
|
|
241
|
+
var pvPayload = {
|
|
275
242
|
lc: getLocale(),
|
|
276
243
|
tz: getTimezone(),
|
|
277
244
|
ref: getReferrer(),
|
|
278
245
|
so: getUTMSource(),
|
|
279
246
|
me: getUTMMedium(),
|
|
280
247
|
ca: getUTMCampaign(),
|
|
281
|
-
unique: unique,
|
|
282
248
|
pg: pg,
|
|
283
|
-
perf: perf,
|
|
284
249
|
prev: prev,
|
|
285
250
|
};
|
|
286
|
-
this.
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
251
|
+
if (evokeCallback && ((_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.callback)) {
|
|
252
|
+
var callbackResult = this.pageViewsOptions.callback(pvPayload);
|
|
253
|
+
if (callbackResult === false) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (callbackResult && typeof callbackResult === 'object') {
|
|
257
|
+
Object.assign(pvPayload, callbackResult);
|
|
258
|
+
}
|
|
292
259
|
}
|
|
260
|
+
Object.assign(pvPayload, privateData);
|
|
261
|
+
this.sendRequest('', pvPayload);
|
|
293
262
|
};
|
|
294
263
|
Lib.prototype.canTrack = function () {
|
|
295
264
|
var _a, _b, _c, _d;
|
|
296
|
-
if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.disabled)
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
this.debug('Tracking disabled: script does not run in browser environment.');
|
|
302
|
-
return false;
|
|
303
|
-
}
|
|
304
|
-
if (((_b = this.options) === null || _b === void 0 ? void 0 : _b.respectDNT) && ((_c = window.navigator) === null || _c === void 0 ? void 0 : _c.doNotTrack) === '1') {
|
|
305
|
-
this.debug('Tracking disabled: respecting user\'s \'Do Not Track\' preference.');
|
|
306
|
-
return false;
|
|
307
|
-
}
|
|
308
|
-
if (!((_d = this.options) === null || _d === void 0 ? void 0 : _d.debug) && isLocalhost()) {
|
|
309
|
-
return false;
|
|
310
|
-
}
|
|
311
|
-
if (isAutomated()) {
|
|
312
|
-
this.debug('Tracking disabled: navigation is automated by WebDriver.');
|
|
265
|
+
if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.disabled) ||
|
|
266
|
+
!isInBrowser() ||
|
|
267
|
+
(((_b = this.options) === null || _b === void 0 ? void 0 : _b.respectDNT) && ((_c = window.navigator) === null || _c === void 0 ? void 0 : _c.doNotTrack) === '1') ||
|
|
268
|
+
(!((_d = this.options) === null || _d === void 0 ? void 0 : _d.devMode) && isLocalhost()) ||
|
|
269
|
+
isAutomated()) {
|
|
313
270
|
return false;
|
|
314
271
|
}
|
|
315
272
|
return true;
|
package/dist/swetrix.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).swetrix={})}(this,function(
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).swetrix={})}(this,function(a){"use strict";function t(t){return(t=location.search.match(t))&&t[2]||void 0}function i(){return void 0!==navigator.languages?navigator.languages[0]:navigator.language}function r(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch(t){}}function s(){return document.referrer||void 0}function c(){return t(n)}function u(){return t(p)}function l(){return t(h)}function o(t){var e,n=location.pathname||"";return t.hash&&(n+=-1<(e=location.hash.indexOf("?"))?location.hash.substring(0,e):location.hash),t.search&&(e=location.hash.indexOf("?"),n+=location.search||(-1<e?location.hash.substring(e):"")),n}var e=function(){return(e=Object.assign||function(t){for(var e,n=1,a=arguments.length;n<a;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},n=/[?&](ref|source|utm_source)=([^?&]+)/,h=/[?&](utm_campaign)=([^?&]+)/,p=/[?&](utm_medium)=([^?&]+)/,d={stop:function(){}},f=(g.prototype.track=function(t){this.canTrack()&&(t=e(e({},t),{pid:this.projectID,pg:this.activePage,lc:i(),tz:r(),ref:s(),so:c(),me:u(),ca:l()}),this.sendRequest("custom",t))},g.prototype.trackPageViews=function(t){var e,n,a;return this.canTrack()?(this.pageData||(null!=(this.pageViewsOptions=t)&&t.unique||(e=setInterval(this.trackPathChange,2e3)),setTimeout(this.heartbeat,3e3),n=setInterval(this.heartbeat,28e3),a=o({hash:null==t?void 0:t.hash,search:null==t?void 0:t.search}),this.pageData={path:a,actions:{stop:function(){clearInterval(e),clearInterval(n)}}},this.trackPage(a,null==t?void 0:t.unique)),this.pageData.actions):d},g.prototype.getPerformanceStats=function(){var t;return this.canTrack()&&!this.perfStatsCollected&&null!=(t=window.performance)&&t.getEntriesByType&&(t=window.performance.getEntriesByType("navigation")[0])?(this.perfStatsCollected=!0,{dns:t.domainLookupEnd-t.domainLookupStart,tls:t.secureConnectionStart?t.requestStart-t.secureConnectionStart:0,conn:t.secureConnectionStart?t.secureConnectionStart-t.connectStart:t.connectEnd-t.connectStart,response:t.responseEnd-t.responseStart,render:t.domComplete-t.domContentLoadedEventEnd,dom_load:t.domContentLoadedEventEnd-t.responseEnd,page_load:t.loadEventStart,ttfb:t.responseStart-t.requestStart}):{}},g.prototype.heartbeat=function(){var t;(null!=(t=this.pageViewsOptions)&&t.heartbeatOnBackground||"hidden"!==document.visibilityState)&&(t={pid:this.projectID},this.sendRequest("hb",t))},g.prototype.trackPathChange=function(){var t;this.pageData&&(t=o({hash:null==(t=this.pageViewsOptions)?void 0:t.hash,search:null==(t=this.pageViewsOptions)?void 0:t.search}),this.pageData.path!==t)&&this.trackPage(t,!1)},g.prototype.getPreviousPage=function(){if(this.activePage)return this.activePage;if("function"==typeof URL){var t=s();if(!t)return null;var e=location.host;try{var n=new URL(t),a=n.host,o=n.pathname;return e!==a?null:o}catch(t){}}return null},g.prototype.trackPage=function(t,e){var n,a;void 0===e&&(e=!1),this.pageData&&(this.pageData.path=t,n=this.getPerformanceStats(),a=this.getPreviousPage(),this.activePage=t,this.submitPageView(t,a,e,n,!0))},g.prototype.submitPageView=function(t,e,n,a,o){a={pid:this.projectID,perf:a,unique:n},n={lc:i(),tz:r(),ref:s(),so:c(),me:u(),ca:l(),pg:t,prev:e};if(o&&null!=(t=this.pageViewsOptions)&&t.callback){e=this.pageViewsOptions.callback(n);if(!1===e)return;e&&"object"==typeof e&&Object.assign(n,e)}Object.assign(n,a),this.sendRequest("",n)},g.prototype.canTrack=function(){var t;return!(null!=(t=this.options)&&t.disabled||"undefined"==typeof window||null!=(t=this.options)&&t.respectDNT&&"1"===(null==(t=window.navigator)?void 0:t.doNotTrack)||(null==(t=this.options)||!t.devMode)&&("localhost"===(null===location||void 0===location?void 0:location.hostname)||"127.0.0.1"===(null===location||void 0===location?void 0:location.hostname)||""===(null===location||void 0===location?void 0:location.hostname))||null!==navigator&&void 0!==navigator&&navigator.webdriver)},g.prototype.sendRequest=function(t,e){var n=(null==(n=this.options)?void 0:n.apiURL)||"https://api.swetrix.com/log",a=new XMLHttpRequest;a.open("POST","".concat(n,"/").concat(t),!0),a.setRequestHeader("Content-Type","application/json"),a.send(JSON.stringify(e))},g);function g(t,e){this.projectID=t,this.options=e,this.pageData=null,this.pageViewsOptions=null,this.perfStatsCollected=!1,this.activePage=null,this.trackPathChange=this.trackPathChange.bind(this),this.heartbeat=this.heartbeat.bind(this)}a.LIB_INSTANCE=null,a.init=function(t,e){return a.LIB_INSTANCE||(a.LIB_INSTANCE=new f(t,e)),a.LIB_INSTANCE},a.track=function(t){a.LIB_INSTANCE&&a.LIB_INSTANCE.track(t)},a.trackPageview=function(t,e,n){a.LIB_INSTANCE&&a.LIB_INSTANCE.submitPageView(t,e||null,Boolean(n),{})},a.trackViews=function(e){return new Promise(function(t){a.LIB_INSTANCE?"undefined"==typeof document||"complete"===document.readyState?t(a.LIB_INSTANCE.trackPageViews(e)):window.addEventListener("load",function(){t(a.LIB_INSTANCE.trackPageViews(e))}):t(d)})},Object.defineProperty(a,"__esModule",{value:!0})});
|
package/dist/swetrix.orig.js
CHANGED
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
if (!this.canTrack()) {
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
119
|
-
var data = __assign({ pid: this.projectID, pg: this.activePage, lc: getLocale(), tz: getTimezone(), ref: getReferrer(), so: getUTMSource(), me: getUTMMedium(), ca: getUTMCampaign() }
|
|
119
|
+
var data = __assign(__assign({}, event), { pid: this.projectID, pg: this.activePage, lc: getLocale(), tz: getTimezone(), ref: getReferrer(), so: getUTMSource(), me: getUTMMedium(), ca: getUTMCampaign() });
|
|
120
120
|
this.sendRequest('custom', data);
|
|
121
121
|
};
|
|
122
122
|
Lib.prototype.trackPageViews = function (options) {
|
|
@@ -127,14 +127,12 @@
|
|
|
127
127
|
return this.pageData.actions;
|
|
128
128
|
}
|
|
129
129
|
this.pageViewsOptions = options;
|
|
130
|
-
var
|
|
130
|
+
var interval;
|
|
131
131
|
if (!(options === null || options === void 0 ? void 0 : options.unique)) {
|
|
132
132
|
interval = setInterval(this.trackPathChange, 2000);
|
|
133
133
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
hbInterval = setInterval(this.heartbeat, 28000);
|
|
137
|
-
}
|
|
134
|
+
setTimeout(this.heartbeat, 3000);
|
|
135
|
+
var hbInterval = setInterval(this.heartbeat, 28000);
|
|
138
136
|
var path = getPath({
|
|
139
137
|
hash: options === null || options === void 0 ? void 0 : options.hash,
|
|
140
138
|
search: options === null || options === void 0 ? void 0 : options.search,
|
|
@@ -163,23 +161,17 @@
|
|
|
163
161
|
this.perfStatsCollected = true;
|
|
164
162
|
return {
|
|
165
163
|
// Network
|
|
166
|
-
//
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
// @ts-ignore
|
|
173
|
-
response: perf.responseEnd - perf.responseStart,
|
|
164
|
+
dns: perf.domainLookupEnd - perf.domainLookupStart, // DNS Resolution
|
|
165
|
+
tls: perf.secureConnectionStart ? perf.requestStart - perf.secureConnectionStart : 0, // TLS Setup; checking if secureConnectionStart is not 0 (it's 0 for non-https websites)
|
|
166
|
+
conn: perf.secureConnectionStart
|
|
167
|
+
? perf.secureConnectionStart - perf.connectStart
|
|
168
|
+
: perf.connectEnd - perf.connectStart, // Connection time
|
|
169
|
+
response: perf.responseEnd - perf.responseStart, // Response Time (Download)
|
|
174
170
|
// Frontend
|
|
175
|
-
//
|
|
176
|
-
|
|
177
|
-
//
|
|
178
|
-
dom_load: perf.domContentLoadedEventEnd - perf.responseEnd,
|
|
179
|
-
// @ts-ignore
|
|
180
|
-
page_load: perf.loadEventStart,
|
|
171
|
+
render: perf.domComplete - perf.domContentLoadedEventEnd, // Browser rendering the HTML time
|
|
172
|
+
dom_load: perf.domContentLoadedEventEnd - perf.responseEnd, // DOM loading timing
|
|
173
|
+
page_load: perf.loadEventStart, // Page load time
|
|
181
174
|
// Backend
|
|
182
|
-
// @ts-ignore
|
|
183
175
|
ttfb: perf.responseStart - perf.requestStart,
|
|
184
176
|
};
|
|
185
177
|
};
|
|
@@ -193,20 +185,6 @@
|
|
|
193
185
|
};
|
|
194
186
|
this.sendRequest('hb', data);
|
|
195
187
|
};
|
|
196
|
-
Lib.prototype.checkIgnore = function (path) {
|
|
197
|
-
var _a;
|
|
198
|
-
var ignore = (_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.ignore;
|
|
199
|
-
if (Array.isArray(ignore)) {
|
|
200
|
-
for (var i = 0; i < ignore.length; ++i) {
|
|
201
|
-
if (ignore[i] === path)
|
|
202
|
-
return true;
|
|
203
|
-
// @ts-ignore
|
|
204
|
-
if (ignore[i] instanceof RegExp && ignore[i].test(path))
|
|
205
|
-
return true;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
return false;
|
|
209
|
-
};
|
|
210
188
|
// Tracking path changes. If path changes -> calling this.trackPage method
|
|
211
189
|
Lib.prototype.trackPathChange = function () {
|
|
212
190
|
var _a, _b;
|
|
@@ -222,15 +200,10 @@
|
|
|
222
200
|
}
|
|
223
201
|
};
|
|
224
202
|
Lib.prototype.getPreviousPage = function () {
|
|
225
|
-
var _a, _b;
|
|
226
203
|
// Assuming that this function is called in trackPage and this.activePage is not overwritten by new value yet
|
|
227
204
|
// That method of getting previous page works for SPA websites
|
|
228
205
|
if (this.activePage) {
|
|
229
|
-
|
|
230
|
-
if (shouldIgnore && ((_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.doNotAnonymise)) {
|
|
231
|
-
return null;
|
|
232
|
-
}
|
|
233
|
-
return shouldIgnore ? null : this.activePage;
|
|
206
|
+
return this.activePage;
|
|
234
207
|
}
|
|
235
208
|
// Checking if URL is supported by the browser (for example, IE11 does not support it)
|
|
236
209
|
if (typeof URL === 'function') {
|
|
@@ -246,76 +219,60 @@
|
|
|
246
219
|
if (host !== refHost) {
|
|
247
220
|
return null;
|
|
248
221
|
}
|
|
249
|
-
|
|
250
|
-
if (shouldIgnore && ((_b = this.pageViewsOptions) === null || _b === void 0 ? void 0 : _b.doNotAnonymise)) {
|
|
251
|
-
return null;
|
|
252
|
-
}
|
|
253
|
-
return shouldIgnore ? null : pathname;
|
|
222
|
+
return pathname;
|
|
254
223
|
}
|
|
255
|
-
catch (
|
|
224
|
+
catch (_a) {
|
|
256
225
|
return null;
|
|
257
226
|
}
|
|
258
227
|
}
|
|
259
228
|
return null;
|
|
260
229
|
};
|
|
261
230
|
Lib.prototype.trackPage = function (pg, unique) {
|
|
262
|
-
var _a, _b;
|
|
263
231
|
if (unique === void 0) { unique = false; }
|
|
264
232
|
if (!this.pageData)
|
|
265
233
|
return;
|
|
266
234
|
this.pageData.path = pg;
|
|
267
|
-
var shouldIgnore = this.checkIgnore(pg);
|
|
268
|
-
if (shouldIgnore && ((_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.doNotAnonymise))
|
|
269
|
-
return;
|
|
270
235
|
var perf = this.getPerformanceStats();
|
|
271
|
-
var prev;
|
|
272
|
-
if (!((_b = this.pageViewsOptions) === null || _b === void 0 ? void 0 : _b.noUserFlow)) {
|
|
273
|
-
prev = this.getPreviousPage();
|
|
274
|
-
}
|
|
236
|
+
var prev = this.getPreviousPage();
|
|
275
237
|
this.activePage = pg;
|
|
276
|
-
this.submitPageView(
|
|
238
|
+
this.submitPageView(pg, prev, unique, perf, true);
|
|
277
239
|
};
|
|
278
|
-
Lib.prototype.submitPageView = function (pg, prev, unique, perf) {
|
|
279
|
-
var
|
|
240
|
+
Lib.prototype.submitPageView = function (pg, prev, unique, perf, evokeCallback) {
|
|
241
|
+
var _a;
|
|
242
|
+
var privateData = {
|
|
280
243
|
pid: this.projectID,
|
|
244
|
+
perf: perf,
|
|
245
|
+
unique: unique,
|
|
246
|
+
};
|
|
247
|
+
var pvPayload = {
|
|
281
248
|
lc: getLocale(),
|
|
282
249
|
tz: getTimezone(),
|
|
283
250
|
ref: getReferrer(),
|
|
284
251
|
so: getUTMSource(),
|
|
285
252
|
me: getUTMMedium(),
|
|
286
253
|
ca: getUTMCampaign(),
|
|
287
|
-
unique: unique,
|
|
288
254
|
pg: pg,
|
|
289
|
-
perf: perf,
|
|
290
255
|
prev: prev,
|
|
291
256
|
};
|
|
292
|
-
this.
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
257
|
+
if (evokeCallback && ((_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.callback)) {
|
|
258
|
+
var callbackResult = this.pageViewsOptions.callback(pvPayload);
|
|
259
|
+
if (callbackResult === false) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
if (callbackResult && typeof callbackResult === 'object') {
|
|
263
|
+
Object.assign(pvPayload, callbackResult);
|
|
264
|
+
}
|
|
298
265
|
}
|
|
266
|
+
Object.assign(pvPayload, privateData);
|
|
267
|
+
this.sendRequest('', pvPayload);
|
|
299
268
|
};
|
|
300
269
|
Lib.prototype.canTrack = function () {
|
|
301
270
|
var _a, _b, _c, _d;
|
|
302
|
-
if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.disabled)
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
this.debug('Tracking disabled: script does not run in browser environment.');
|
|
308
|
-
return false;
|
|
309
|
-
}
|
|
310
|
-
if (((_b = this.options) === null || _b === void 0 ? void 0 : _b.respectDNT) && ((_c = window.navigator) === null || _c === void 0 ? void 0 : _c.doNotTrack) === '1') {
|
|
311
|
-
this.debug('Tracking disabled: respecting user\'s \'Do Not Track\' preference.');
|
|
312
|
-
return false;
|
|
313
|
-
}
|
|
314
|
-
if (!((_d = this.options) === null || _d === void 0 ? void 0 : _d.debug) && isLocalhost()) {
|
|
315
|
-
return false;
|
|
316
|
-
}
|
|
317
|
-
if (isAutomated()) {
|
|
318
|
-
this.debug('Tracking disabled: navigation is automated by WebDriver.');
|
|
271
|
+
if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.disabled) ||
|
|
272
|
+
!isInBrowser() ||
|
|
273
|
+
(((_b = this.options) === null || _b === void 0 ? void 0 : _b.respectDNT) && ((_c = window.navigator) === null || _c === void 0 ? void 0 : _c.doNotTrack) === '1') ||
|
|
274
|
+
(!((_d = this.options) === null || _d === void 0 ? void 0 : _d.devMode) && isLocalhost()) ||
|
|
275
|
+
isAutomated()) {
|
|
319
276
|
return false;
|
|
320
277
|
}
|
|
321
278
|
return true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swetrix",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "The JavaScript analytics client for Swetrix Analytics",
|
|
5
5
|
"main": "dist/swetrix.cjs.js",
|
|
6
6
|
"module": "dist/swetrix.es5.js",
|
|
@@ -32,13 +32,13 @@
|
|
|
32
32
|
"bugs": {
|
|
33
33
|
"url": "https://github.com/Swetrix/swetrix-js/issues"
|
|
34
34
|
},
|
|
35
|
-
"homepage": "https://swetrix.com
|
|
35
|
+
"homepage": "https://docs.swetrix.com",
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@types/node": "^20.8
|
|
37
|
+
"@types/node": "^20.11.8",
|
|
38
38
|
"tslib": "^2.6.2"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@rollup/plugin-commonjs": "^25.0.
|
|
41
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
42
42
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
43
43
|
"rimraf": "^4.4.1",
|
|
44
44
|
"rollup": "^2.79.1",
|
|
@@ -46,6 +46,6 @@
|
|
|
46
46
|
"rollup-plugin-sourcemaps": "^0.6.3",
|
|
47
47
|
"rollup-plugin-typescript2": "^0.36.0",
|
|
48
48
|
"rollup-plugin-uglify": "^6.0.4",
|
|
49
|
-
"typescript": "^5.
|
|
49
|
+
"typescript": "^5.3.3"
|
|
50
50
|
}
|
|
51
51
|
}
|