swetrix 3.1.0 → 3.2.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/README.md +5 -1
- package/dist/esnext/Lib.d.ts +5 -1
- package/dist/esnext/Lib.js +4 -5
- package/dist/esnext/Lib.js.map +1 -1
- package/dist/esnext/index.d.ts +12 -8
- package/dist/esnext/index.js +12 -8
- package/dist/esnext/index.js.map +1 -1
- package/dist/swetrix.cjs.js +17 -21
- package/dist/swetrix.es5.js +17 -22
- package/dist/swetrix.js +1 -1
- package/dist/swetrix.orig.js +17 -21
- package/package.json +1 -1
- package/src/Lib.ts +27 -20
- package/src/index.ts +19 -8
package/README.md
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
<
|
|
1
|
+
<picture>
|
|
2
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://swetrix.com/assets/logo_white.png">
|
|
3
|
+
<img alt="" src="https://swetrix.com/assets/logo_blue.png" height="80">
|
|
4
|
+
</picture>
|
|
5
|
+
<br /><br />
|
|
2
6
|
|
|
3
7
|
[](https://data.jsdelivr.com/v1/package/gh/Swetrix/swetrix-js/stats)
|
|
4
8
|
[](https://bundlephobia.com/api/size?package=swetrix)
|
package/dist/esnext/Lib.d.ts
CHANGED
|
@@ -34,6 +34,10 @@ export interface IPageViewPayload {
|
|
|
34
34
|
ca: string | undefined;
|
|
35
35
|
pg: string | null | undefined;
|
|
36
36
|
prev: string | null | undefined;
|
|
37
|
+
/** Pageview-related metadata object with string values. */
|
|
38
|
+
meta?: {
|
|
39
|
+
[key: string]: string;
|
|
40
|
+
};
|
|
37
41
|
}
|
|
38
42
|
export interface IErrorEventPayload {
|
|
39
43
|
name: string;
|
|
@@ -143,7 +147,7 @@ export declare class Lib {
|
|
|
143
147
|
private trackPathChange;
|
|
144
148
|
private getPreviousPage;
|
|
145
149
|
private trackPage;
|
|
146
|
-
submitPageView(
|
|
150
|
+
submitPageView(payload: Partial<IPageViewPayload>, unique: boolean, perf: IPerfPayload | {}, evokeCallback?: boolean): void;
|
|
147
151
|
private canTrack;
|
|
148
152
|
private sendRequest;
|
|
149
153
|
}
|
package/dist/esnext/Lib.js
CHANGED
|
@@ -34,7 +34,7 @@ export class Lib {
|
|
|
34
34
|
// (we want to split error name and message so we could group them together later in dashboard).
|
|
35
35
|
// If message in error object does not exist - lets use a message from the Error event itself.
|
|
36
36
|
message: event.error?.message || event.message,
|
|
37
|
-
});
|
|
37
|
+
}, true);
|
|
38
38
|
}
|
|
39
39
|
trackErrors(options) {
|
|
40
40
|
if (this.errorListenerExists || !this.canTrack()) {
|
|
@@ -204,9 +204,9 @@ export class Lib {
|
|
|
204
204
|
const perf = this.getPerformanceStats();
|
|
205
205
|
const prev = this.getPreviousPage();
|
|
206
206
|
this.activePage = pg;
|
|
207
|
-
this.submitPageView(pg, prev, unique, perf, true);
|
|
207
|
+
this.submitPageView({ pg, prev }, unique, perf, true);
|
|
208
208
|
}
|
|
209
|
-
submitPageView(
|
|
209
|
+
submitPageView(payload, unique, perf, evokeCallback) {
|
|
210
210
|
const privateData = {
|
|
211
211
|
pid: this.projectID,
|
|
212
212
|
perf,
|
|
@@ -219,8 +219,7 @@ export class Lib {
|
|
|
219
219
|
so: getUTMSource(),
|
|
220
220
|
me: getUTMMedium(),
|
|
221
221
|
ca: getUTMCampaign(),
|
|
222
|
-
|
|
223
|
-
prev,
|
|
222
|
+
...payload,
|
|
224
223
|
};
|
|
225
224
|
if (evokeCallback && this.pageViewsOptions?.callback) {
|
|
226
225
|
const callbackResult = this.pageViewsOptions.callback(pvPayload);
|
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,YAAY,EACZ,YAAY,EACZ,OAA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K,CAAA;QACd,CAAC;QAED,OAAO,IAAI,CAAA;IACb,CAAC;IAEO,WAAW,CAAC,IAAY,EAAE,IAAY;QAC5C,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,MAAM,IAAI,gBAAgB,CAAA;QACrD,MAAM,GAAG,GAAG,IAAI,cAAc,EAAE,CAAA;QAChC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,IAAI,IAAI,EAAE,EAAE,IAAI,CAAC,CAAA;QACzC,GAAG,CAAC,gBAAgB,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAA;QACxD,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAA;IAChC,CAAC;CACF"}
|
package/dist/esnext/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Lib, LibOptions, TrackEventOptions, PageViewsOptions, ErrorOptions, PageActions, ErrorActions, IErrorEventPayload } from './Lib';
|
|
1
|
+
import { Lib, LibOptions, TrackEventOptions, PageViewsOptions, ErrorOptions, PageActions, ErrorActions, IErrorEventPayload, IPageViewPayload } from './Lib';
|
|
2
2
|
export declare let LIB_INSTANCE: Lib | null;
|
|
3
3
|
/**
|
|
4
4
|
* Initialise the tracking library instance (other methods won't work if the library is not initialised).
|
|
@@ -24,12 +24,10 @@ export declare function track(event: TrackEventOptions): void;
|
|
|
24
24
|
*/
|
|
25
25
|
export declare function trackViews(options?: PageViewsOptions): Promise<PageActions>;
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* The total number of track calls and their conversion rate will be saved.
|
|
27
|
+
* This function is used to set up automatic error events tracking.
|
|
28
|
+
* It set's up an error listener, and whenever an error happens, it gets tracked.
|
|
30
29
|
*
|
|
31
|
-
* @
|
|
32
|
-
* @returns {PageActions} The actions related to the tracking. Used to stop tracking pages.
|
|
30
|
+
* @returns {ErrorActions} The actions related to the tracking. Used to stop tracking errors.
|
|
33
31
|
*/
|
|
34
32
|
export declare function trackErrors(options?: ErrorOptions): ErrorActions;
|
|
35
33
|
/**
|
|
@@ -44,9 +42,15 @@ export declare function trackError(payload: IErrorEventPayload): void;
|
|
|
44
42
|
* This function is used to manually track a page view event.
|
|
45
43
|
* It's useful if your application uses esoteric routing which is not supported by Swetrix by default.
|
|
46
44
|
*
|
|
47
|
-
* @
|
|
45
|
+
* @deprecated This function is deprecated and will be removed soon, please use the `pageview` instead.
|
|
46
|
+
* @param pg Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
|
|
48
47
|
* @param prev Path of the previous page.
|
|
49
48
|
* @param unique If set to `true`, only 1 event with the same ID will be saved per user session.
|
|
50
49
|
* @returns void
|
|
51
50
|
*/
|
|
52
|
-
export declare function trackPageview(
|
|
51
|
+
export declare function trackPageview(pg: string, prev?: string, unique?: boolean): void;
|
|
52
|
+
export interface IPageviewOptions {
|
|
53
|
+
payload: Partial<IPageViewPayload>;
|
|
54
|
+
unique?: boolean;
|
|
55
|
+
}
|
|
56
|
+
export declare function pageview(options: IPageviewOptions): void;
|
package/dist/esnext/index.js
CHANGED
|
@@ -50,12 +50,10 @@ export function trackViews(options) {
|
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* The total number of track calls and their conversion rate will be saved.
|
|
53
|
+
* This function is used to set up automatic error events tracking.
|
|
54
|
+
* It set's up an error listener, and whenever an error happens, it gets tracked.
|
|
56
55
|
*
|
|
57
|
-
* @
|
|
58
|
-
* @returns {PageActions} The actions related to the tracking. Used to stop tracking pages.
|
|
56
|
+
* @returns {ErrorActions} The actions related to the tracking. Used to stop tracking errors.
|
|
59
57
|
*/
|
|
60
58
|
export function trackErrors(options) {
|
|
61
59
|
if (!LIB_INSTANCE) {
|
|
@@ -79,14 +77,20 @@ export function trackError(payload) {
|
|
|
79
77
|
* This function is used to manually track a page view event.
|
|
80
78
|
* It's useful if your application uses esoteric routing which is not supported by Swetrix by default.
|
|
81
79
|
*
|
|
82
|
-
* @
|
|
80
|
+
* @deprecated This function is deprecated and will be removed soon, please use the `pageview` instead.
|
|
81
|
+
* @param pg Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
|
|
83
82
|
* @param prev Path of the previous page.
|
|
84
83
|
* @param unique If set to `true`, only 1 event with the same ID will be saved per user session.
|
|
85
84
|
* @returns void
|
|
86
85
|
*/
|
|
87
|
-
export function trackPageview(
|
|
86
|
+
export function trackPageview(pg, prev, unique) {
|
|
87
|
+
if (!LIB_INSTANCE)
|
|
88
|
+
return;
|
|
89
|
+
LIB_INSTANCE.submitPageView({ pg, prev: prev || null }, Boolean(unique), {});
|
|
90
|
+
}
|
|
91
|
+
export function pageview(options) {
|
|
88
92
|
if (!LIB_INSTANCE)
|
|
89
93
|
return;
|
|
90
|
-
LIB_INSTANCE.submitPageView(
|
|
94
|
+
LIB_INSTANCE.submitPageView(options.payload, Boolean(options.unique), {});
|
|
91
95
|
}
|
|
92
96
|
//# sourceMappingURL=index.js.map
|
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,
|
|
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;QAClB,YAAY,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IACtC,CAAC;IAED,OAAO,YAAY,CAAA;AACrB,CAAC;AAED;;;;;;GAMG;AACH,MAA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AAE,EAAE,EAAE,IAAI,EAAE,IAAI,IAAI,IAAI,EAAE,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAA;AAC9E,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
|
@@ -131,7 +131,7 @@ var Lib = /** @class */ (function () {
|
|
|
131
131
|
// (we want to split error name and message so we could group them together later in dashboard).
|
|
132
132
|
// If message in error object does not exist - lets use a message from the Error event itself.
|
|
133
133
|
message: ((_c = event.error) === null || _c === void 0 ? void 0 : _c.message) || event.message,
|
|
134
|
-
});
|
|
134
|
+
}, true);
|
|
135
135
|
};
|
|
136
136
|
Lib.prototype.trackErrors = function (options) {
|
|
137
137
|
var _this = this;
|
|
@@ -292,25 +292,16 @@ var Lib = /** @class */ (function () {
|
|
|
292
292
|
var perf = this.getPerformanceStats();
|
|
293
293
|
var prev = this.getPreviousPage();
|
|
294
294
|
this.activePage = pg;
|
|
295
|
-
this.submitPageView(pg, prev, unique, perf, true);
|
|
295
|
+
this.submitPageView({ pg: pg, prev: prev }, unique, perf, true);
|
|
296
296
|
};
|
|
297
|
-
Lib.prototype.submitPageView = function (
|
|
297
|
+
Lib.prototype.submitPageView = function (payload, unique, perf, evokeCallback) {
|
|
298
298
|
var _a;
|
|
299
299
|
var privateData = {
|
|
300
300
|
pid: this.projectID,
|
|
301
301
|
perf: perf,
|
|
302
302
|
unique: unique,
|
|
303
303
|
};
|
|
304
|
-
var pvPayload = {
|
|
305
|
-
lc: getLocale(),
|
|
306
|
-
tz: getTimezone(),
|
|
307
|
-
ref: getReferrer(),
|
|
308
|
-
so: getUTMSource(),
|
|
309
|
-
me: getUTMMedium(),
|
|
310
|
-
ca: getUTMCampaign(),
|
|
311
|
-
pg: pg,
|
|
312
|
-
prev: prev,
|
|
313
|
-
};
|
|
304
|
+
var pvPayload = __assign({ lc: getLocale(), tz: getTimezone(), ref: getReferrer(), so: getUTMSource(), me: getUTMMedium(), ca: getUTMCampaign() }, payload);
|
|
314
305
|
if (evokeCallback && ((_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.callback)) {
|
|
315
306
|
var callbackResult = this.pageViewsOptions.callback(pvPayload);
|
|
316
307
|
if (callbackResult === false) {
|
|
@@ -396,12 +387,10 @@ function trackViews(options) {
|
|
|
396
387
|
});
|
|
397
388
|
}
|
|
398
389
|
/**
|
|
399
|
-
*
|
|
400
|
-
*
|
|
401
|
-
* The total number of track calls and their conversion rate will be saved.
|
|
390
|
+
* This function is used to set up automatic error events tracking.
|
|
391
|
+
* It set's up an error listener, and whenever an error happens, it gets tracked.
|
|
402
392
|
*
|
|
403
|
-
* @
|
|
404
|
-
* @returns {PageActions} The actions related to the tracking. Used to stop tracking pages.
|
|
393
|
+
* @returns {ErrorActions} The actions related to the tracking. Used to stop tracking errors.
|
|
405
394
|
*/
|
|
406
395
|
function trackErrors(options) {
|
|
407
396
|
if (!exports.LIB_INSTANCE) {
|
|
@@ -425,18 +414,25 @@ function trackError(payload) {
|
|
|
425
414
|
* This function is used to manually track a page view event.
|
|
426
415
|
* It's useful if your application uses esoteric routing which is not supported by Swetrix by default.
|
|
427
416
|
*
|
|
428
|
-
* @
|
|
417
|
+
* @deprecated This function is deprecated and will be removed soon, please use the `pageview` instead.
|
|
418
|
+
* @param pg Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
|
|
429
419
|
* @param prev Path of the previous page.
|
|
430
420
|
* @param unique If set to `true`, only 1 event with the same ID will be saved per user session.
|
|
431
421
|
* @returns void
|
|
432
422
|
*/
|
|
433
|
-
function trackPageview(
|
|
423
|
+
function trackPageview(pg, prev, unique) {
|
|
424
|
+
if (!exports.LIB_INSTANCE)
|
|
425
|
+
return;
|
|
426
|
+
exports.LIB_INSTANCE.submitPageView({ pg: pg, prev: prev || null }, Boolean(unique), {});
|
|
427
|
+
}
|
|
428
|
+
function pageview(options) {
|
|
434
429
|
if (!exports.LIB_INSTANCE)
|
|
435
430
|
return;
|
|
436
|
-
exports.LIB_INSTANCE.submitPageView(
|
|
431
|
+
exports.LIB_INSTANCE.submitPageView(options.payload, Boolean(options.unique), {});
|
|
437
432
|
}
|
|
438
433
|
|
|
439
434
|
exports.init = init;
|
|
435
|
+
exports.pageview = pageview;
|
|
440
436
|
exports.track = track;
|
|
441
437
|
exports.trackError = trackError;
|
|
442
438
|
exports.trackErrors = trackErrors;
|
package/dist/swetrix.es5.js
CHANGED
|
@@ -127,7 +127,7 @@ var Lib = /** @class */ (function () {
|
|
|
127
127
|
// (we want to split error name and message so we could group them together later in dashboard).
|
|
128
128
|
// If message in error object does not exist - lets use a message from the Error event itself.
|
|
129
129
|
message: ((_c = event.error) === null || _c === void 0 ? void 0 : _c.message) || event.message,
|
|
130
|
-
});
|
|
130
|
+
}, true);
|
|
131
131
|
};
|
|
132
132
|
Lib.prototype.trackErrors = function (options) {
|
|
133
133
|
var _this = this;
|
|
@@ -288,25 +288,16 @@ var Lib = /** @class */ (function () {
|
|
|
288
288
|
var perf = this.getPerformanceStats();
|
|
289
289
|
var prev = this.getPreviousPage();
|
|
290
290
|
this.activePage = pg;
|
|
291
|
-
this.submitPageView(pg, prev, unique, perf, true);
|
|
291
|
+
this.submitPageView({ pg: pg, prev: prev }, unique, perf, true);
|
|
292
292
|
};
|
|
293
|
-
Lib.prototype.submitPageView = function (
|
|
293
|
+
Lib.prototype.submitPageView = function (payload, unique, perf, evokeCallback) {
|
|
294
294
|
var _a;
|
|
295
295
|
var privateData = {
|
|
296
296
|
pid: this.projectID,
|
|
297
297
|
perf: perf,
|
|
298
298
|
unique: unique,
|
|
299
299
|
};
|
|
300
|
-
var pvPayload = {
|
|
301
|
-
lc: getLocale(),
|
|
302
|
-
tz: getTimezone(),
|
|
303
|
-
ref: getReferrer(),
|
|
304
|
-
so: getUTMSource(),
|
|
305
|
-
me: getUTMMedium(),
|
|
306
|
-
ca: getUTMCampaign(),
|
|
307
|
-
pg: pg,
|
|
308
|
-
prev: prev,
|
|
309
|
-
};
|
|
300
|
+
var pvPayload = __assign({ lc: getLocale(), tz: getTimezone(), ref: getReferrer(), so: getUTMSource(), me: getUTMMedium(), ca: getUTMCampaign() }, payload);
|
|
310
301
|
if (evokeCallback && ((_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.callback)) {
|
|
311
302
|
var callbackResult = this.pageViewsOptions.callback(pvPayload);
|
|
312
303
|
if (callbackResult === false) {
|
|
@@ -392,12 +383,10 @@ function trackViews(options) {
|
|
|
392
383
|
});
|
|
393
384
|
}
|
|
394
385
|
/**
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
* The total number of track calls and their conversion rate will be saved.
|
|
386
|
+
* This function is used to set up automatic error events tracking.
|
|
387
|
+
* It set's up an error listener, and whenever an error happens, it gets tracked.
|
|
398
388
|
*
|
|
399
|
-
* @
|
|
400
|
-
* @returns {PageActions} The actions related to the tracking. Used to stop tracking pages.
|
|
389
|
+
* @returns {ErrorActions} The actions related to the tracking. Used to stop tracking errors.
|
|
401
390
|
*/
|
|
402
391
|
function trackErrors(options) {
|
|
403
392
|
if (!LIB_INSTANCE) {
|
|
@@ -421,15 +410,21 @@ function trackError(payload) {
|
|
|
421
410
|
* This function is used to manually track a page view event.
|
|
422
411
|
* It's useful if your application uses esoteric routing which is not supported by Swetrix by default.
|
|
423
412
|
*
|
|
424
|
-
* @
|
|
413
|
+
* @deprecated This function is deprecated and will be removed soon, please use the `pageview` instead.
|
|
414
|
+
* @param pg Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
|
|
425
415
|
* @param prev Path of the previous page.
|
|
426
416
|
* @param unique If set to `true`, only 1 event with the same ID will be saved per user session.
|
|
427
417
|
* @returns void
|
|
428
418
|
*/
|
|
429
|
-
function trackPageview(
|
|
419
|
+
function trackPageview(pg, prev, unique) {
|
|
420
|
+
if (!LIB_INSTANCE)
|
|
421
|
+
return;
|
|
422
|
+
LIB_INSTANCE.submitPageView({ pg: pg, prev: prev || null }, Boolean(unique), {});
|
|
423
|
+
}
|
|
424
|
+
function pageview(options) {
|
|
430
425
|
if (!LIB_INSTANCE)
|
|
431
426
|
return;
|
|
432
|
-
LIB_INSTANCE.submitPageView(
|
|
427
|
+
LIB_INSTANCE.submitPageView(options.payload, Boolean(options.unique), {});
|
|
433
428
|
}
|
|
434
429
|
|
|
435
|
-
export { LIB_INSTANCE, init, track, trackError, trackErrors, trackPageview, trackViews };
|
|
430
|
+
export { LIB_INSTANCE, init, pageview, track, trackError, trackErrors, trackPageview, trackViews };
|
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(o){"use strict";function t(t){return(t=location.search.match(t))&&t[2]||void 0}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";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 a(){return document.referrer||void 0}function s(){return t(e)}function c(){return t(p)}function u(){return t(n)}function l(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 h=function(){return(h=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)},e=/[?&](ref|source|utm_source)=([^?&]+)/,n=/[?&](utm_campaign)=([^?&]+)/,p=/[?&](utm_medium)=([^?&]+)/,d={stop:function(){}},f=(g.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)},g.prototype.trackErrors=function(t){var e=this;return this.errorListenerExists||!this.canTrack()?d:(this.errorsOptions=t,window.addEventListener("error",this.captureError),this.errorListenerExists=!0,{stop:function(){window.removeEventListener("error",e.captureError)}})},g.prototype.submitError=function(t,e){var n={pid:this.projectID},o=h({pg:this.activePage||l({hash:null==(o=this.pageViewsOptions)?void 0:o.hash,search:null==(o=this.pageViewsOptions)?void 0:o.search}),lc:i(),tz:r()},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)},g.prototype.track=function(t){this.canTrack()&&(t=h(h({},t),{pid:this.projectID,pg:this.activePage,lc:i(),tz:r(),ref:a(),so:s(),me:c(),ca:u()}),this.sendRequest("custom",t))},g.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=l({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):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=l({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=a();if(!t)return null;var e=location.host;try{var n=new URL(t),o=n.host,i=n.pathname;return e!==o?null:i}catch(t){}}return null},g.prototype.trackPage=function(t,e){var n,o;void 0===e&&(e=!1),this.pageData&&(this.pageData.path=t,n=this.getPerformanceStats(),o=this.getPreviousPage(),this.activePage=t,this.submitPageView({pg:t,prev:o},e,n,!0))},g.prototype.submitPageView=function(t,e,n,o){n={pid:this.projectID,perf:n,unique:e},e=h({lc:i(),tz:r(),ref:a(),so:s(),me:c(),ca:u()},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)},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",o=new XMLHttpRequest;o.open("POST","".concat(n,"/").concat(t),!0),o.setRequestHeader("Content-Type","application/json"),o.send(JSON.stringify(e))},g);function g(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 f(t,e)),o.LIB_INSTANCE},o.pageview=function(t){o.LIB_INSTANCE&&o.LIB_INSTANCE.submitPageView(t.payload,Boolean(t.unique),{})},o.track=function(t){o.LIB_INSTANCE&&o.LIB_INSTANCE.track(t)},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):d},o.trackPageview=function(t,e,n){o.LIB_INSTANCE&&o.LIB_INSTANCE.submitPageView({pg:t,prev:e||null},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(d)})},Object.defineProperty(o,"__esModule",{value:!0})});
|
package/dist/swetrix.orig.js
CHANGED
|
@@ -133,7 +133,7 @@
|
|
|
133
133
|
// (we want to split error name and message so we could group them together later in dashboard).
|
|
134
134
|
// If message in error object does not exist - lets use a message from the Error event itself.
|
|
135
135
|
message: ((_c = event.error) === null || _c === void 0 ? void 0 : _c.message) || event.message,
|
|
136
|
-
});
|
|
136
|
+
}, true);
|
|
137
137
|
};
|
|
138
138
|
Lib.prototype.trackErrors = function (options) {
|
|
139
139
|
var _this = this;
|
|
@@ -294,25 +294,16 @@
|
|
|
294
294
|
var perf = this.getPerformanceStats();
|
|
295
295
|
var prev = this.getPreviousPage();
|
|
296
296
|
this.activePage = pg;
|
|
297
|
-
this.submitPageView(pg, prev, unique, perf, true);
|
|
297
|
+
this.submitPageView({ pg: pg, prev: prev }, unique, perf, true);
|
|
298
298
|
};
|
|
299
|
-
Lib.prototype.submitPageView = function (
|
|
299
|
+
Lib.prototype.submitPageView = function (payload, unique, perf, evokeCallback) {
|
|
300
300
|
var _a;
|
|
301
301
|
var privateData = {
|
|
302
302
|
pid: this.projectID,
|
|
303
303
|
perf: perf,
|
|
304
304
|
unique: unique,
|
|
305
305
|
};
|
|
306
|
-
var pvPayload = {
|
|
307
|
-
lc: getLocale(),
|
|
308
|
-
tz: getTimezone(),
|
|
309
|
-
ref: getReferrer(),
|
|
310
|
-
so: getUTMSource(),
|
|
311
|
-
me: getUTMMedium(),
|
|
312
|
-
ca: getUTMCampaign(),
|
|
313
|
-
pg: pg,
|
|
314
|
-
prev: prev,
|
|
315
|
-
};
|
|
306
|
+
var pvPayload = __assign({ lc: getLocale(), tz: getTimezone(), ref: getReferrer(), so: getUTMSource(), me: getUTMMedium(), ca: getUTMCampaign() }, payload);
|
|
316
307
|
if (evokeCallback && ((_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.callback)) {
|
|
317
308
|
var callbackResult = this.pageViewsOptions.callback(pvPayload);
|
|
318
309
|
if (callbackResult === false) {
|
|
@@ -398,12 +389,10 @@
|
|
|
398
389
|
});
|
|
399
390
|
}
|
|
400
391
|
/**
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
* The total number of track calls and their conversion rate will be saved.
|
|
392
|
+
* This function is used to set up automatic error events tracking.
|
|
393
|
+
* It set's up an error listener, and whenever an error happens, it gets tracked.
|
|
404
394
|
*
|
|
405
|
-
* @
|
|
406
|
-
* @returns {PageActions} The actions related to the tracking. Used to stop tracking pages.
|
|
395
|
+
* @returns {ErrorActions} The actions related to the tracking. Used to stop tracking errors.
|
|
407
396
|
*/
|
|
408
397
|
function trackErrors(options) {
|
|
409
398
|
if (!exports.LIB_INSTANCE) {
|
|
@@ -427,18 +416,25 @@
|
|
|
427
416
|
* This function is used to manually track a page view event.
|
|
428
417
|
* It's useful if your application uses esoteric routing which is not supported by Swetrix by default.
|
|
429
418
|
*
|
|
430
|
-
* @
|
|
419
|
+
* @deprecated This function is deprecated and will be removed soon, please use the `pageview` instead.
|
|
420
|
+
* @param pg Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
|
|
431
421
|
* @param prev Path of the previous page.
|
|
432
422
|
* @param unique If set to `true`, only 1 event with the same ID will be saved per user session.
|
|
433
423
|
* @returns void
|
|
434
424
|
*/
|
|
435
|
-
function trackPageview(
|
|
425
|
+
function trackPageview(pg, prev, unique) {
|
|
426
|
+
if (!exports.LIB_INSTANCE)
|
|
427
|
+
return;
|
|
428
|
+
exports.LIB_INSTANCE.submitPageView({ pg: pg, prev: prev || null }, Boolean(unique), {});
|
|
429
|
+
}
|
|
430
|
+
function pageview(options) {
|
|
436
431
|
if (!exports.LIB_INSTANCE)
|
|
437
432
|
return;
|
|
438
|
-
exports.LIB_INSTANCE.submitPageView(
|
|
433
|
+
exports.LIB_INSTANCE.submitPageView(options.payload, Boolean(options.unique), {});
|
|
439
434
|
}
|
|
440
435
|
|
|
441
436
|
exports.init = init;
|
|
437
|
+
exports.pageview = pageview;
|
|
442
438
|
exports.track = track;
|
|
443
439
|
exports.trackError = trackError;
|
|
444
440
|
exports.trackErrors = trackErrors;
|
package/package.json
CHANGED
package/src/Lib.ts
CHANGED
|
@@ -55,6 +55,11 @@ export interface IPageViewPayload {
|
|
|
55
55
|
ca: string | undefined
|
|
56
56
|
pg: string | null | undefined
|
|
57
57
|
prev: string | null | undefined
|
|
58
|
+
|
|
59
|
+
/** Pageview-related metadata object with string values. */
|
|
60
|
+
meta?: {
|
|
61
|
+
[key: string]: string
|
|
62
|
+
}
|
|
58
63
|
}
|
|
59
64
|
|
|
60
65
|
// Partial user-editable error payload
|
|
@@ -182,24 +187,27 @@ export class Lib {
|
|
|
182
187
|
return
|
|
183
188
|
}
|
|
184
189
|
|
|
185
|
-
this.submitError(
|
|
186
|
-
|
|
187
|
-
|
|
190
|
+
this.submitError(
|
|
191
|
+
{
|
|
192
|
+
// The file in which error occured.
|
|
193
|
+
filename: event.filename,
|
|
188
194
|
|
|
189
|
-
|
|
190
|
-
|
|
195
|
+
// The line of code error occured on.
|
|
196
|
+
lineno: event.lineno,
|
|
191
197
|
|
|
192
|
-
|
|
193
|
-
|
|
198
|
+
// The column of code error occured on.
|
|
199
|
+
colno: event.colno,
|
|
194
200
|
|
|
195
|
-
|
|
196
|
-
|
|
201
|
+
// Name of the error, if not exists (i.e. it's a custom thrown error). The initial value of name is "Error", but just in case lets explicitly set it here too.
|
|
202
|
+
name: event.error?.name || 'Error',
|
|
197
203
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
204
|
+
// Description of the error. By default, we use message from Error object, is it does not contain the error name
|
|
205
|
+
// (we want to split error name and message so we could group them together later in dashboard).
|
|
206
|
+
// If message in error object does not exist - lets use a message from the Error event itself.
|
|
207
|
+
message: event.error?.message || event.message,
|
|
208
|
+
},
|
|
209
|
+
true,
|
|
210
|
+
)
|
|
203
211
|
}
|
|
204
212
|
|
|
205
213
|
trackErrors(options?: ErrorOptions): ErrorActions {
|
|
@@ -412,12 +420,11 @@ export class Lib {
|
|
|
412
420
|
const prev = this.getPreviousPage()
|
|
413
421
|
|
|
414
422
|
this.activePage = pg
|
|
415
|
-
this.submitPageView(pg, prev, unique, perf, true)
|
|
423
|
+
this.submitPageView({ pg, prev }, unique, perf, true)
|
|
416
424
|
}
|
|
417
425
|
|
|
418
426
|
submitPageView(
|
|
419
|
-
|
|
420
|
-
prev: string | null | undefined,
|
|
427
|
+
payload: Partial<IPageViewPayload>,
|
|
421
428
|
unique: boolean,
|
|
422
429
|
perf: IPerfPayload | {},
|
|
423
430
|
evokeCallback?: boolean,
|
|
@@ -427,6 +434,7 @@ export class Lib {
|
|
|
427
434
|
perf,
|
|
428
435
|
unique,
|
|
429
436
|
}
|
|
437
|
+
|
|
430
438
|
const pvPayload = {
|
|
431
439
|
lc: getLocale(),
|
|
432
440
|
tz: getTimezone(),
|
|
@@ -434,12 +442,11 @@ export class Lib {
|
|
|
434
442
|
so: getUTMSource(),
|
|
435
443
|
me: getUTMMedium(),
|
|
436
444
|
ca: getUTMCampaign(),
|
|
437
|
-
|
|
438
|
-
prev,
|
|
445
|
+
...payload,
|
|
439
446
|
}
|
|
440
447
|
|
|
441
448
|
if (evokeCallback && this.pageViewsOptions?.callback) {
|
|
442
|
-
const callbackResult = this.pageViewsOptions.callback(pvPayload)
|
|
449
|
+
const callbackResult = this.pageViewsOptions.callback(pvPayload as IPageViewPayload)
|
|
443
450
|
|
|
444
451
|
if (callbackResult === false) {
|
|
445
452
|
return
|
package/src/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
ErrorActions,
|
|
9
9
|
defaultActions,
|
|
10
10
|
IErrorEventPayload,
|
|
11
|
+
IPageViewPayload,
|
|
11
12
|
} from './Lib'
|
|
12
13
|
|
|
13
14
|
export let LIB_INSTANCE: Lib | null = null
|
|
@@ -66,12 +67,10 @@ export function trackViews(options?: PageViewsOptions): Promise<PageActions> {
|
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* The total number of track calls and their conversion rate will be saved.
|
|
70
|
+
* This function is used to set up automatic error events tracking.
|
|
71
|
+
* It set's up an error listener, and whenever an error happens, it gets tracked.
|
|
72
72
|
*
|
|
73
|
-
* @
|
|
74
|
-
* @returns {PageActions} The actions related to the tracking. Used to stop tracking pages.
|
|
73
|
+
* @returns {ErrorActions} The actions related to the tracking. Used to stop tracking errors.
|
|
75
74
|
*/
|
|
76
75
|
export function trackErrors(options?: ErrorOptions): ErrorActions {
|
|
77
76
|
if (!LIB_INSTANCE) {
|
|
@@ -98,13 +97,25 @@ export function trackError(payload: IErrorEventPayload): void {
|
|
|
98
97
|
* This function is used to manually track a page view event.
|
|
99
98
|
* It's useful if your application uses esoteric routing which is not supported by Swetrix by default.
|
|
100
99
|
*
|
|
101
|
-
* @
|
|
100
|
+
* @deprecated This function is deprecated and will be removed soon, please use the `pageview` instead.
|
|
101
|
+
* @param pg Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
|
|
102
102
|
* @param prev Path of the previous page.
|
|
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(
|
|
106
|
+
export function trackPageview(pg: string, prev?: string, unique?: boolean): void {
|
|
107
|
+
if (!LIB_INSTANCE) return
|
|
108
|
+
|
|
109
|
+
LIB_INSTANCE.submitPageView({ pg, prev: prev || null }, Boolean(unique), {})
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface IPageviewOptions {
|
|
113
|
+
payload: Partial<IPageViewPayload>
|
|
114
|
+
unique?: boolean
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function pageview(options: IPageviewOptions): void {
|
|
107
118
|
if (!LIB_INSTANCE) return
|
|
108
119
|
|
|
109
|
-
LIB_INSTANCE.submitPageView(
|
|
120
|
+
LIB_INSTANCE.submitPageView(options.payload, Boolean(options.unique), {})
|
|
110
121
|
}
|