swetrix 3.4.0 → 3.5.0
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/esnext/Lib.d.ts +2 -2
- package/dist/esnext/Lib.js +0 -30
- package/dist/esnext/Lib.js.map +1 -1
- package/dist/esnext/index.d.ts +2 -2
- package/dist/esnext/index.js +3 -3
- package/dist/esnext/index.js.map +1 -1
- package/dist/swetrix.cjs.js +4 -33
- package/dist/swetrix.es5.js +4 -33
- package/dist/swetrix.js +1 -1
- package/dist/swetrix.orig.js +4 -33
- package/package.json +2 -2
- package/src/Lib.ts +2 -38
- package/src/index.ts +3 -3
package/dist/esnext/Lib.d.ts
CHANGED
|
@@ -32,8 +32,9 @@ export interface IPageViewPayload {
|
|
|
32
32
|
so: string | undefined;
|
|
33
33
|
me: string | undefined;
|
|
34
34
|
ca: string | undefined;
|
|
35
|
+
te: string | undefined;
|
|
36
|
+
co: string | undefined;
|
|
35
37
|
pg: string | null | undefined;
|
|
36
|
-
prev: string | null | undefined;
|
|
37
38
|
/** Pageview-related metadata object with string values. */
|
|
38
39
|
meta?: {
|
|
39
40
|
[key: string]: string;
|
|
@@ -145,7 +146,6 @@ export declare class Lib {
|
|
|
145
146
|
getPerformanceStats(): IPerfPayload | {};
|
|
146
147
|
private heartbeat;
|
|
147
148
|
private trackPathChange;
|
|
148
|
-
private getPreviousPage;
|
|
149
149
|
private trackPage;
|
|
150
150
|
submitPageView(payload: Partial<IPageViewPayload>, unique: boolean, perf: IPerfPayload | {}, evokeCallback?: boolean): void;
|
|
151
151
|
private canTrack;
|
package/dist/esnext/Lib.js
CHANGED
|
@@ -171,34 +171,6 @@ export class Lib {
|
|
|
171
171
|
this.trackPage(newPath, false);
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
|
-
getPreviousPage() {
|
|
175
|
-
// Assuming that this function is called in trackPage and this.activePage is not overwritten by new value yet
|
|
176
|
-
// That method of getting previous page works for SPA websites
|
|
177
|
-
if (this.activePage) {
|
|
178
|
-
return this.activePage;
|
|
179
|
-
}
|
|
180
|
-
// Checking if URL is supported by the browser (for example, IE11 does not support it)
|
|
181
|
-
if (typeof URL === 'function') {
|
|
182
|
-
// That method of getting previous page works for websites with page reloads
|
|
183
|
-
const referrer = getReferrer();
|
|
184
|
-
if (!referrer) {
|
|
185
|
-
return null;
|
|
186
|
-
}
|
|
187
|
-
const { host } = location;
|
|
188
|
-
try {
|
|
189
|
-
const url = new URL(referrer);
|
|
190
|
-
const { host: refHost, pathname } = url;
|
|
191
|
-
if (host !== refHost) {
|
|
192
|
-
return null;
|
|
193
|
-
}
|
|
194
|
-
return pathname;
|
|
195
|
-
}
|
|
196
|
-
catch {
|
|
197
|
-
return null;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
return null;
|
|
201
|
-
}
|
|
202
174
|
trackPage(pg, unique = false) {
|
|
203
175
|
if (!this.pageData)
|
|
204
176
|
return;
|
|
@@ -208,7 +180,6 @@ export class Lib {
|
|
|
208
180
|
this.submitPageView({ pg }, unique, perf, true);
|
|
209
181
|
}
|
|
210
182
|
submitPageView(payload, unique, perf, evokeCallback) {
|
|
211
|
-
const prev = this.getPreviousPage();
|
|
212
183
|
const privateData = {
|
|
213
184
|
pid: this.projectID,
|
|
214
185
|
perf,
|
|
@@ -223,7 +194,6 @@ export class Lib {
|
|
|
223
194
|
ca: getUTMCampaign(),
|
|
224
195
|
te: getUTMTerm(),
|
|
225
196
|
co: getUTMContent(),
|
|
226
|
-
prev,
|
|
227
197
|
...payload,
|
|
228
198
|
};
|
|
229
199
|
if (evokeCallback && this.pageViewsOptions?.callback) {
|
package/dist/esnext/Lib.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Lib.js","sourceRoot":"","sources":["../../src/Lib.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,WAAW,EACX,WAAW,EACX,SAAS,EACT,WAAW,EACX,WAAW,EACX,cAAc,EACd,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I,cAAc,KAAK,KAAK,EAAE,CAAC;gBAC7B,OAAM;YACR,CAAC;YAED,IAAI,cAAc,IAAI,OAAO,cAAc,KAAK,QAAQ,EAAE,CAAC;gBACzD,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,cAAc,CAAC,CAAA;YAC1C,CAAC;QACH,CAAC;QAED,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC,CAAA;QAErC,IAAI,CAAC,WAAW,CAAC,EAAE,EAAE,SAAS,CAAC,CAAA;IACjC,CAAC;IAEO,QAAQ;QACd,IACE,IAAI,CAAC,OAAO,EAAE,QAAQ;YACtB,CAAC,WAAW,EAAE;YACd,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,IAAI,MAAM,CAAC,SAAS,EAAE,UAAU,KAAK,GAAG,CAAC;YAClE,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,CAAC;YACzC,WAAW,EAAE,EACb,CAAC;YACD,OAAO,KAAK,CAAA;QACd,CAAC;QAED,OAAO,IAAI,CAAA;IACb,CAAC;IAEO,KAAK,CAAC,WAAW,CAAC,IAAY,EAAE,IAAY;QAClD,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,MAAM,IAAI,gBAAgB,CAAA;QACrD,MAAM,KAAK,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,EAAE;YAC7B,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC3B,CAAC,CAAA;IACJ,CAAC;CACF"}
|
package/dist/esnext/index.d.ts
CHANGED
|
@@ -44,11 +44,11 @@ export declare function trackError(payload: IErrorEventPayload): void;
|
|
|
44
44
|
*
|
|
45
45
|
* @deprecated This function is deprecated and will be removed soon, please use the `pageview` instead.
|
|
46
46
|
* @param pg Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
|
|
47
|
-
* @param
|
|
47
|
+
* @param _prev Path of the previous page (deprecated and ignored).
|
|
48
48
|
* @param unique If set to `true`, only 1 event with the same ID will be saved per user session.
|
|
49
49
|
* @returns void
|
|
50
50
|
*/
|
|
51
|
-
export declare function trackPageview(pg: string,
|
|
51
|
+
export declare function trackPageview(pg: string, _prev?: string, unique?: boolean): void;
|
|
52
52
|
export interface IPageviewOptions {
|
|
53
53
|
payload: Partial<IPageViewPayload>;
|
|
54
54
|
unique?: boolean;
|
package/dist/esnext/index.js
CHANGED
|
@@ -79,14 +79,14 @@ export function trackError(payload) {
|
|
|
79
79
|
*
|
|
80
80
|
* @deprecated This function is deprecated and will be removed soon, please use the `pageview` instead.
|
|
81
81
|
* @param pg Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
|
|
82
|
-
* @param
|
|
82
|
+
* @param _prev Path of the previous page (deprecated and ignored).
|
|
83
83
|
* @param unique If set to `true`, only 1 event with the same ID will be saved per user session.
|
|
84
84
|
* @returns void
|
|
85
85
|
*/
|
|
86
|
-
export function trackPageview(pg,
|
|
86
|
+
export function trackPageview(pg, _prev, unique) {
|
|
87
87
|
if (!LIB_INSTANCE)
|
|
88
88
|
return;
|
|
89
|
-
LIB_INSTANCE.submitPageView({ pg
|
|
89
|
+
LIB_INSTANCE.submitPageView({ pg }, Boolean(unique), {});
|
|
90
90
|
}
|
|
91
91
|
export function pageview(options) {
|
|
92
92
|
if (!LIB_INSTANCE)
|
package/dist/esnext/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EAOH,cAAc,GAGf,MAAM,OAAO,CAAA;AAEd,MAAM,CAAC,IAAI,YAAY,GAAe,IAAI,CAAA;AAE1C;;;;;;GAMG;AACH,MAAM,UAAU,IAAI,CAAC,GAAW,EAAE,OAAoB;IACpD,IAAI,CAAC,YAAY,EAAE,CAAC;QA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ED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,OAAsB;IAChD,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,cAAc,CAAA;IACvB,CAAC;IAED,OAAO,YAAY,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;AAC1C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,OAA2B;IACpD,IAAI,CAAC,YAAY;QAAE,OAAM;IAEzB,YAAY,CAAC,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;AAC1C,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa,CAAC,EAAU,EAAE,KAAc,EAAE,MAAgB;IACxE,IAAI,CAAC,YAAY;QAAE,OAAM;IAEzB,YAAY,CAAC,cAAc,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAA;AAC1D,CAAC;AAOD,MAAM,UAAU,QAAQ,CAAC,OAAyB;IAChD,IAAI,CAAC,YAAY;QAAE,OAAM;IAEzB,YAAY,CAAC,cAAc,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAA;AAC3E,CAAC"}
|
package/dist/swetrix.cjs.js
CHANGED
|
@@ -309,34 +309,6 @@ var Lib = /** @class */ (function () {
|
|
|
309
309
|
this.trackPage(newPath, false);
|
|
310
310
|
}
|
|
311
311
|
};
|
|
312
|
-
Lib.prototype.getPreviousPage = function () {
|
|
313
|
-
// Assuming that this function is called in trackPage and this.activePage is not overwritten by new value yet
|
|
314
|
-
// That method of getting previous page works for SPA websites
|
|
315
|
-
if (this.activePage) {
|
|
316
|
-
return this.activePage;
|
|
317
|
-
}
|
|
318
|
-
// Checking if URL is supported by the browser (for example, IE11 does not support it)
|
|
319
|
-
if (typeof URL === 'function') {
|
|
320
|
-
// That method of getting previous page works for websites with page reloads
|
|
321
|
-
var referrer = getReferrer();
|
|
322
|
-
if (!referrer) {
|
|
323
|
-
return null;
|
|
324
|
-
}
|
|
325
|
-
var host = location.host;
|
|
326
|
-
try {
|
|
327
|
-
var url = new URL(referrer);
|
|
328
|
-
var refHost = url.host, pathname = url.pathname;
|
|
329
|
-
if (host !== refHost) {
|
|
330
|
-
return null;
|
|
331
|
-
}
|
|
332
|
-
return pathname;
|
|
333
|
-
}
|
|
334
|
-
catch (_a) {
|
|
335
|
-
return null;
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
return null;
|
|
339
|
-
};
|
|
340
312
|
Lib.prototype.trackPage = function (pg, unique) {
|
|
341
313
|
if (unique === void 0) { unique = false; }
|
|
342
314
|
if (!this.pageData)
|
|
@@ -348,13 +320,12 @@ var Lib = /** @class */ (function () {
|
|
|
348
320
|
};
|
|
349
321
|
Lib.prototype.submitPageView = function (payload, unique, perf, evokeCallback) {
|
|
350
322
|
var _a;
|
|
351
|
-
var prev = this.getPreviousPage();
|
|
352
323
|
var privateData = {
|
|
353
324
|
pid: this.projectID,
|
|
354
325
|
perf: perf,
|
|
355
326
|
unique: unique,
|
|
356
327
|
};
|
|
357
|
-
var pvPayload = __assign({ lc: getLocale(), tz: getTimezone(), ref: getReferrer(), so: getUTMSource(), me: getUTMMedium(), ca: getUTMCampaign(), te: getUTMTerm(), co: getUTMContent()
|
|
328
|
+
var pvPayload = __assign({ lc: getLocale(), tz: getTimezone(), ref: getReferrer(), so: getUTMSource(), me: getUTMMedium(), ca: getUTMCampaign(), te: getUTMTerm(), co: getUTMContent() }, payload);
|
|
358
329
|
if (evokeCallback && ((_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.callback)) {
|
|
359
330
|
var callbackResult = this.pageViewsOptions.callback(pvPayload);
|
|
360
331
|
if (callbackResult === false) {
|
|
@@ -493,14 +464,14 @@ function trackError(payload) {
|
|
|
493
464
|
*
|
|
494
465
|
* @deprecated This function is deprecated and will be removed soon, please use the `pageview` instead.
|
|
495
466
|
* @param pg Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
|
|
496
|
-
* @param
|
|
467
|
+
* @param _prev Path of the previous page (deprecated and ignored).
|
|
497
468
|
* @param unique If set to `true`, only 1 event with the same ID will be saved per user session.
|
|
498
469
|
* @returns void
|
|
499
470
|
*/
|
|
500
|
-
function trackPageview(pg,
|
|
471
|
+
function trackPageview(pg, _prev, unique) {
|
|
501
472
|
if (!exports.LIB_INSTANCE)
|
|
502
473
|
return;
|
|
503
|
-
exports.LIB_INSTANCE.submitPageView({ pg: pg
|
|
474
|
+
exports.LIB_INSTANCE.submitPageView({ pg: pg }, Boolean(unique), {});
|
|
504
475
|
}
|
|
505
476
|
function pageview(options) {
|
|
506
477
|
if (!exports.LIB_INSTANCE)
|
package/dist/swetrix.es5.js
CHANGED
|
@@ -305,34 +305,6 @@ var Lib = /** @class */ (function () {
|
|
|
305
305
|
this.trackPage(newPath, false);
|
|
306
306
|
}
|
|
307
307
|
};
|
|
308
|
-
Lib.prototype.getPreviousPage = function () {
|
|
309
|
-
// Assuming that this function is called in trackPage and this.activePage is not overwritten by new value yet
|
|
310
|
-
// That method of getting previous page works for SPA websites
|
|
311
|
-
if (this.activePage) {
|
|
312
|
-
return this.activePage;
|
|
313
|
-
}
|
|
314
|
-
// Checking if URL is supported by the browser (for example, IE11 does not support it)
|
|
315
|
-
if (typeof URL === 'function') {
|
|
316
|
-
// That method of getting previous page works for websites with page reloads
|
|
317
|
-
var referrer = getReferrer();
|
|
318
|
-
if (!referrer) {
|
|
319
|
-
return null;
|
|
320
|
-
}
|
|
321
|
-
var host = location.host;
|
|
322
|
-
try {
|
|
323
|
-
var url = new URL(referrer);
|
|
324
|
-
var refHost = url.host, pathname = url.pathname;
|
|
325
|
-
if (host !== refHost) {
|
|
326
|
-
return null;
|
|
327
|
-
}
|
|
328
|
-
return pathname;
|
|
329
|
-
}
|
|
330
|
-
catch (_a) {
|
|
331
|
-
return null;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
return null;
|
|
335
|
-
};
|
|
336
308
|
Lib.prototype.trackPage = function (pg, unique) {
|
|
337
309
|
if (unique === void 0) { unique = false; }
|
|
338
310
|
if (!this.pageData)
|
|
@@ -344,13 +316,12 @@ var Lib = /** @class */ (function () {
|
|
|
344
316
|
};
|
|
345
317
|
Lib.prototype.submitPageView = function (payload, unique, perf, evokeCallback) {
|
|
346
318
|
var _a;
|
|
347
|
-
var prev = this.getPreviousPage();
|
|
348
319
|
var privateData = {
|
|
349
320
|
pid: this.projectID,
|
|
350
321
|
perf: perf,
|
|
351
322
|
unique: unique,
|
|
352
323
|
};
|
|
353
|
-
var pvPayload = __assign({ lc: getLocale(), tz: getTimezone(), ref: getReferrer(), so: getUTMSource(), me: getUTMMedium(), ca: getUTMCampaign(), te: getUTMTerm(), co: getUTMContent()
|
|
324
|
+
var pvPayload = __assign({ lc: getLocale(), tz: getTimezone(), ref: getReferrer(), so: getUTMSource(), me: getUTMMedium(), ca: getUTMCampaign(), te: getUTMTerm(), co: getUTMContent() }, payload);
|
|
354
325
|
if (evokeCallback && ((_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.callback)) {
|
|
355
326
|
var callbackResult = this.pageViewsOptions.callback(pvPayload);
|
|
356
327
|
if (callbackResult === false) {
|
|
@@ -489,14 +460,14 @@ function trackError(payload) {
|
|
|
489
460
|
*
|
|
490
461
|
* @deprecated This function is deprecated and will be removed soon, please use the `pageview` instead.
|
|
491
462
|
* @param pg Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
|
|
492
|
-
* @param
|
|
463
|
+
* @param _prev Path of the previous page (deprecated and ignored).
|
|
493
464
|
* @param unique If set to `true`, only 1 event with the same ID will be saved per user session.
|
|
494
465
|
* @returns void
|
|
495
466
|
*/
|
|
496
|
-
function trackPageview(pg,
|
|
467
|
+
function trackPageview(pg, _prev, unique) {
|
|
497
468
|
if (!LIB_INSTANCE)
|
|
498
469
|
return;
|
|
499
|
-
LIB_INSTANCE.submitPageView({ pg: pg
|
|
470
|
+
LIB_INSTANCE.submitPageView({ pg: pg }, Boolean(unique), {});
|
|
500
471
|
}
|
|
501
472
|
function pageview(options) {
|
|
502
473
|
if (!LIB_INSTANCE)
|
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(o){"use strict";var r=function(){return(r=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)};function t(t,a,s,c){return new(s=s||Promise)(function(n,e){function o(t){try{i(c.next(t))}catch(t){e(t)}}function r(t){try{i(c.throw(t))}catch(t){e(t)}}function i(t){var e;t.done?n(t.value):((e=t.value)instanceof s?e:new s(function(t){t(e)})).then(o,r)}i((c=c.apply(t,a||[])).next())})}function i(o,r){var i,a,s,c={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},u={next:t(0),throw:t(1),return:t(2)};return"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function t(n){return function(t){var e=[n,t];if(i)throw new TypeError("Generator is already executing.");for(;c=u&&e[u=0]?0:c;)try{if(i=1,a&&(s=2&e[0]?a.return:e[0]?a.throw||((s=a.return)&&s.call(a),0):a.next)&&!(s=s.call(a,e[1])).done)return s;switch(a=0,(e=s?[2&e[0],s.value]:e)[0]){case 0:case 1:s=e;break;case 4:return c.label++,{value:e[1],done:!1};case 5:c.label++,a=e[1],e=[0];continue;case 7:e=c.ops.pop(),c.trys.pop();continue;default:if(!(s=0<(s=c.trys).length&&s[s.length-1])&&(6===e[0]||2===e[0])){c=0;continue}if(3===e[0]&&(!s||e[1]>s[0]&&e[1]<s[3]))c.label=e[1];else if(6===e[0]&&c.label<s[1])c.label=s[1],s=e;else{if(!(s&&c.label<s[2])){s[2]&&c.ops.pop(),c.trys.pop();continue}c.label=s[2],c.ops.push(e)}}e=r.call(o,c)}catch(t){e=[6,t],a=0}finally{i=s=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}}}function e(t){return(t=location.search.match(t))&&t[2]||void 0}function a(){return void 0!==navigator.languages?navigator.languages[0]:navigator.language}function s(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch(t){}}function c(){return document.referrer||void 0}function u(){return e(n)}function l(){return e(g)}function h(){return e(v)}function p(){return e(m)}function d(){return e(b)}function f(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 n=/[?&](ref|source|utm_source)=([^?&]+)/,v=/[?&](utm_campaign)=([^?&]+)/,g=/[?&](utm_medium)=([^?&]+)/,m=/[?&](utm_term)=([^?&]+)/,b=/[?&](utm_content)=([^?&]+)/,w={stop:function(){}},y=(E.prototype.captureError=function(t){var e;"number"==typeof(null==(e=this.errorsOptions)?void 0:e.sampleRate)&&this.errorsOptions.sampleRate>Math.random()||this.submitError({filename:t.filename,lineno:t.lineno,colno:t.colno,name:(null==(e=t.error)?void 0:e.name)||"Error",message:(null==(e=t.error)?void 0:e.message)||t.message},!0)},E.prototype.trackErrors=function(t){var e=this;return this.errorListenerExists||!this.canTrack()?w:(this.errorsOptions=t,window.addEventListener("error",this.captureError),this.errorListenerExists=!0,{stop:function(){window.removeEventListener("error",e.captureError)}})},E.prototype.submitError=function(t,e){var n={pid:this.projectID},o=r({pg:this.activePage||f({hash:null==(o=this.pageViewsOptions)?void 0:o.hash,search:null==(o=this.pageViewsOptions)?void 0:o.search}),lc:a(),tz:s()},t);if(e&&null!=(t=this.errorsOptions)&&t.callback){e=this.errorsOptions.callback(o);if(!1===e)return;e&&"object"==typeof e&&Object.assign(o,e)}Object.assign(o,n),this.sendRequest("error",o)},E.prototype.track=function(n){return t(this,void 0,void 0,function(){var e;return i(this,function(t){switch(t.label){case 0:return this.canTrack()?(e=r(r({},n),{pid:this.projectID,pg:this.activePage,lc:a(),tz:s(),ref:c(),so:u(),me:l(),ca:h(),te:p(),co:d()}),[4,this.sendRequest("custom",e)]):[2];case 1:return t.sent(),[2]}})})},E.prototype.trackPageViews=function(t){var e,n,o;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),o=f({hash:null==t?void 0:t.hash,search:null==t?void 0:t.search}),this.pageData={path:o,actions:{stop:function(){clearInterval(e),clearInterval(n)}}},this.trackPage(o,null==t?void 0:t.unique)),this.pageData.actions):w},E.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}):{}},E.prototype.heartbeat=function(){var t;(null!=(t=this.pageViewsOptions)&&t.heartbeatOnBackground||"hidden"!==document.visibilityState)&&(t={pid:this.projectID},this.sendRequest("hb",t))},E.prototype.trackPathChange=function(){var t;this.pageData&&(t=f({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)},E.prototype.trackPage=function(t,e){var n;void 0===e&&(e=!1),this.pageData&&(this.pageData.path=t,n=this.getPerformanceStats(),this.activePage=t,this.submitPageView({pg:t},e,n,!0))},E.prototype.submitPageView=function(t,e,n,o){n={pid:this.projectID,perf:n,unique:e},e=r({lc:a(),tz:s(),ref:c(),so:u(),me:l(),ca:h(),te:p(),co:d()},t);if(o&&null!=(t=this.pageViewsOptions)&&t.callback){o=this.pageViewsOptions.callback(e);if(!1===o)return;o&&"object"==typeof o&&Object.assign(e,o)}Object.assign(e,n),this.sendRequest("",e)},E.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)},E.prototype.sendRequest=function(n,o){return t(this,void 0,void 0,function(){var e;return i(this,function(t){switch(t.label){case 0:return e=(null==(e=this.options)?void 0:e.apiURL)||"https://api.swetrix.com/log",[4,fetch("".concat(e,"/").concat(n),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)})];case 1:return t.sent(),[2]}})})},E);function E(t,e){this.projectID=t,this.options=e,this.pageData=null,this.pageViewsOptions=null,this.errorsOptions=null,this.perfStatsCollected=!1,this.activePage=null,this.errorListenerExists=!1,this.trackPathChange=this.trackPathChange.bind(this),this.heartbeat=this.heartbeat.bind(this),this.captureError=this.captureError.bind(this)}o.LIB_INSTANCE=null,o.init=function(t,e){return o.LIB_INSTANCE||(o.LIB_INSTANCE=new y(t,e)),o.LIB_INSTANCE},o.pageview=function(t){o.LIB_INSTANCE&&o.LIB_INSTANCE.submitPageView(t.payload,Boolean(t.unique),{})},o.track=function(e){return t(this,void 0,void 0,function(){return i(this,function(t){switch(t.label){case 0:return o.LIB_INSTANCE?[4,o.LIB_INSTANCE.track(e)]:[2];case 1:return t.sent(),[2]}})})},o.trackError=function(t){o.LIB_INSTANCE&&o.LIB_INSTANCE.submitError(t,!1)},o.trackErrors=function(t){return o.LIB_INSTANCE?o.LIB_INSTANCE.trackErrors(t):w},o.trackPageview=function(t,e,n){o.LIB_INSTANCE&&o.LIB_INSTANCE.submitPageView({pg:t},Boolean(n),{})},o.trackViews=function(e){return new Promise(function(t){o.LIB_INSTANCE?"undefined"==typeof document||"complete"===document.readyState?t(o.LIB_INSTANCE.trackPageViews(e)):window.addEventListener("load",function(){t(o.LIB_INSTANCE.trackPageViews(e))}):t(w)})},Object.defineProperty(o,"__esModule",{value:!0})});
|
package/dist/swetrix.orig.js
CHANGED
|
@@ -311,34 +311,6 @@
|
|
|
311
311
|
this.trackPage(newPath, false);
|
|
312
312
|
}
|
|
313
313
|
};
|
|
314
|
-
Lib.prototype.getPreviousPage = function () {
|
|
315
|
-
// Assuming that this function is called in trackPage and this.activePage is not overwritten by new value yet
|
|
316
|
-
// That method of getting previous page works for SPA websites
|
|
317
|
-
if (this.activePage) {
|
|
318
|
-
return this.activePage;
|
|
319
|
-
}
|
|
320
|
-
// Checking if URL is supported by the browser (for example, IE11 does not support it)
|
|
321
|
-
if (typeof URL === 'function') {
|
|
322
|
-
// That method of getting previous page works for websites with page reloads
|
|
323
|
-
var referrer = getReferrer();
|
|
324
|
-
if (!referrer) {
|
|
325
|
-
return null;
|
|
326
|
-
}
|
|
327
|
-
var host = location.host;
|
|
328
|
-
try {
|
|
329
|
-
var url = new URL(referrer);
|
|
330
|
-
var refHost = url.host, pathname = url.pathname;
|
|
331
|
-
if (host !== refHost) {
|
|
332
|
-
return null;
|
|
333
|
-
}
|
|
334
|
-
return pathname;
|
|
335
|
-
}
|
|
336
|
-
catch (_a) {
|
|
337
|
-
return null;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
return null;
|
|
341
|
-
};
|
|
342
314
|
Lib.prototype.trackPage = function (pg, unique) {
|
|
343
315
|
if (unique === void 0) { unique = false; }
|
|
344
316
|
if (!this.pageData)
|
|
@@ -350,13 +322,12 @@
|
|
|
350
322
|
};
|
|
351
323
|
Lib.prototype.submitPageView = function (payload, unique, perf, evokeCallback) {
|
|
352
324
|
var _a;
|
|
353
|
-
var prev = this.getPreviousPage();
|
|
354
325
|
var privateData = {
|
|
355
326
|
pid: this.projectID,
|
|
356
327
|
perf: perf,
|
|
357
328
|
unique: unique,
|
|
358
329
|
};
|
|
359
|
-
var pvPayload = __assign({ lc: getLocale(), tz: getTimezone(), ref: getReferrer(), so: getUTMSource(), me: getUTMMedium(), ca: getUTMCampaign(), te: getUTMTerm(), co: getUTMContent()
|
|
330
|
+
var pvPayload = __assign({ lc: getLocale(), tz: getTimezone(), ref: getReferrer(), so: getUTMSource(), me: getUTMMedium(), ca: getUTMCampaign(), te: getUTMTerm(), co: getUTMContent() }, payload);
|
|
360
331
|
if (evokeCallback && ((_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.callback)) {
|
|
361
332
|
var callbackResult = this.pageViewsOptions.callback(pvPayload);
|
|
362
333
|
if (callbackResult === false) {
|
|
@@ -495,14 +466,14 @@
|
|
|
495
466
|
*
|
|
496
467
|
* @deprecated This function is deprecated and will be removed soon, please use the `pageview` instead.
|
|
497
468
|
* @param pg Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
|
|
498
|
-
* @param
|
|
469
|
+
* @param _prev Path of the previous page (deprecated and ignored).
|
|
499
470
|
* @param unique If set to `true`, only 1 event with the same ID will be saved per user session.
|
|
500
471
|
* @returns void
|
|
501
472
|
*/
|
|
502
|
-
function trackPageview(pg,
|
|
473
|
+
function trackPageview(pg, _prev, unique) {
|
|
503
474
|
if (!exports.LIB_INSTANCE)
|
|
504
475
|
return;
|
|
505
|
-
exports.LIB_INSTANCE.submitPageView({ pg: pg
|
|
476
|
+
exports.LIB_INSTANCE.submitPageView({ pg: pg }, Boolean(unique), {});
|
|
506
477
|
}
|
|
507
478
|
function pageview(options) {
|
|
508
479
|
if (!exports.LIB_INSTANCE)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swetrix",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "The JavaScript analytics client for Swetrix Analytics",
|
|
5
5
|
"main": "dist/swetrix.cjs.js",
|
|
6
6
|
"module": "dist/swetrix.es5.js",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"type": "git",
|
|
27
27
|
"url": "git+https://github.com/Swetrix/swetrix-js.git"
|
|
28
28
|
},
|
|
29
|
-
"author": "Andrii
|
|
29
|
+
"author": "Andrii Romasiun, Swetrix Ltd. <contact@swetrix.com>",
|
|
30
30
|
"funding": "https://ko-fi.com/andriir",
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"bugs": {
|
package/src/Lib.ts
CHANGED
|
@@ -55,8 +55,9 @@ export interface IPageViewPayload {
|
|
|
55
55
|
so: string | undefined
|
|
56
56
|
me: string | undefined
|
|
57
57
|
ca: string | undefined
|
|
58
|
+
te: string | undefined
|
|
59
|
+
co: string | undefined
|
|
58
60
|
pg: string | null | undefined
|
|
59
|
-
prev: string | null | undefined
|
|
60
61
|
|
|
61
62
|
/** Pageview-related metadata object with string values. */
|
|
62
63
|
meta?: {
|
|
@@ -380,41 +381,6 @@ export class Lib {
|
|
|
380
381
|
}
|
|
381
382
|
}
|
|
382
383
|
|
|
383
|
-
private getPreviousPage(): string | null {
|
|
384
|
-
// Assuming that this function is called in trackPage and this.activePage is not overwritten by new value yet
|
|
385
|
-
// That method of getting previous page works for SPA websites
|
|
386
|
-
if (this.activePage) {
|
|
387
|
-
return this.activePage
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
// Checking if URL is supported by the browser (for example, IE11 does not support it)
|
|
391
|
-
if (typeof URL === 'function') {
|
|
392
|
-
// That method of getting previous page works for websites with page reloads
|
|
393
|
-
const referrer = getReferrer()
|
|
394
|
-
|
|
395
|
-
if (!referrer) {
|
|
396
|
-
return null
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
const { host } = location
|
|
400
|
-
|
|
401
|
-
try {
|
|
402
|
-
const url = new URL(referrer)
|
|
403
|
-
const { host: refHost, pathname } = url
|
|
404
|
-
|
|
405
|
-
if (host !== refHost) {
|
|
406
|
-
return null
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
return pathname
|
|
410
|
-
} catch {
|
|
411
|
-
return null
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
return null
|
|
416
|
-
}
|
|
417
|
-
|
|
418
384
|
private trackPage(pg: string, unique: boolean = false): void {
|
|
419
385
|
if (!this.pageData) return
|
|
420
386
|
this.pageData.path = pg
|
|
@@ -431,7 +397,6 @@ export class Lib {
|
|
|
431
397
|
perf: IPerfPayload | {},
|
|
432
398
|
evokeCallback?: boolean,
|
|
433
399
|
): void {
|
|
434
|
-
const prev = this.getPreviousPage()
|
|
435
400
|
const privateData = {
|
|
436
401
|
pid: this.projectID,
|
|
437
402
|
perf,
|
|
@@ -447,7 +412,6 @@ export class Lib {
|
|
|
447
412
|
ca: getUTMCampaign(),
|
|
448
413
|
te: getUTMTerm(),
|
|
449
414
|
co: getUTMContent(),
|
|
450
|
-
prev,
|
|
451
415
|
...payload,
|
|
452
416
|
}
|
|
453
417
|
|
package/src/index.ts
CHANGED
|
@@ -99,14 +99,14 @@ export function trackError(payload: IErrorEventPayload): void {
|
|
|
99
99
|
*
|
|
100
100
|
* @deprecated This function is deprecated and will be removed soon, please use the `pageview` instead.
|
|
101
101
|
* @param pg Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
|
|
102
|
-
* @param
|
|
102
|
+
* @param _prev Path of the previous page (deprecated and ignored).
|
|
103
103
|
* @param unique If set to `true`, only 1 event with the same ID will be saved per user session.
|
|
104
104
|
* @returns void
|
|
105
105
|
*/
|
|
106
|
-
export function trackPageview(pg: string,
|
|
106
|
+
export function trackPageview(pg: string, _prev?: string, unique?: boolean): void {
|
|
107
107
|
if (!LIB_INSTANCE) return
|
|
108
108
|
|
|
109
|
-
LIB_INSTANCE.submitPageView({ pg
|
|
109
|
+
LIB_INSTANCE.submitPageView({ pg }, Boolean(unique), {})
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
export interface IPageviewOptions {
|