Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

v2.4.0 build

Blue Mouse05ff4c1b315d
diff --git a/dist/esnext/Lib.d.ts b/dist/esnext/Lib.d.ts
index 02797d5c7..1bdd3a2fd 100644
--- a/dist/esnext/Lib.d.ts
+++ b/dist/esnext/Lib.d.ts
@@ -54,6 +54,16 @@ export interface PageViewsOptions {
heartbeatOnBackground?: boolean;
/** Disable user-flow */
noUserFlow?: boolean;
+ /**
+ * Set to `true` to enable hash-based routing.
+ * For example if you have pages like /#/path or want to track pages like /path#hash
+ */
+ hash?: boolean;
+ /**
+ * Set to `true` to enable search-based routing.
+ * For example if you have pages like /path?search
+ */
+ search?: boolean;
}
export declare const defaultPageActions: {
stop(): void;
@@ -74,6 +84,7 @@ export declare class Lib {
private trackPathChange;
private getPreviousPage;
private trackPage;
+ submitPageView(pg: null | string, prev: string | null | undefined, unique: boolean, perf: any): void;
private debug;
private canTrack;
private sendRequest;
diff --git a/dist/esnext/Lib.js b/dist/esnext/Lib.js
index 55f9947f3..2efa6ab32 100644
--- a/dist/esnext/Lib.js
+++ b/dist/esnext/Lib.js
@@ -47,7 +47,10 @@ export class Lib {
setTimeout(this.heartbeat, 3000);
hbInterval = setInterval(this.heartbeat, 28000);
}
- const path = getPath();
+ const path = getPath({
+ hash: options?.hash,
+ search: options?.search,
+ });
this.pageData = {
path,
actions: {
@@ -117,7 +120,10 @@ export class Lib {
trackPathChange() {
if (!this.pageData)
return;
- const newPath = getPath();
+ const newPath = getPath({
+ hash: this.pageViewsOptions?.hash,
+ search: this.pageViewsOptions?.search,
+ });
const { path } = this.pageData;
if (path !== newPath) {
this.trackPage(newPath, false);
@@ -171,6 +177,10 @@ export class Lib {
if (!this.pageViewsOptions?.noUserFlow) {
prev = this.getPreviousPage();
}
+ this.activePage = pg;
+ this.submitPageView(shouldIgnore ? null : pg, prev, unique, perf);
+ }
+ submitPageView(pg, prev, unique, perf) {
const data = {
pid: this.projectID,
lc: getLocale(),
@@ -180,11 +190,10 @@ export class Lib {
me: getUTMMedium(),
ca: getUTMCampaign(),
unique,
- pg: shouldIgnore ? null : pg,
+ pg,
perf,
prev,
};
- this.activePage = pg;
this.sendRequest('', data);
}
debug(message) {
diff --git a/dist/esnext/Lib.js.map b/dist/esnext/Lib.js.map
index 24f0073bd..bfe9f3478 100644
--- a/dist/esnext/Lib.js.map
+++ b/dist/esnext/Lib.js.map
@@ -1 +1 @@
-{"version":3,"file":"Lib.js","sourceRoot":"","sources":["../../src/Lib.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAC1E,cAAc,EAAE,YAAY,EAAE,YAAY,EAAE,OAAO,GACpD,MAAM,SAAS,CAAA;AA2EhB,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,IAAI,KAAI,CAAC;CACV,CAAA;AAED,MAAM,gBAAgB,GAAG,6BAA6B,CAAA;AAEtD,MAAM,OAAO,GAAG;IAMd,YAAoB,SAAiB,EAAU,OAAoB;QAA/C,cAAS,GAAT,SAAS,CAAQ;QAAU,YAAO,GAAP,OAAO,CAAa;QAL3D,aAAQ,GAAoB,IAAI,CAAA;QAChC,qBAAgB,GAAwC,IAAI,CAAA;QAC5D,uBAAkB,GAAY,KAAK,CAAA;QACnC,eAAU,GAAkB,IAAI,CAAA;QAGtC,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACtD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC5C,CAAC;IAED,KAAK,CAAC,KAAwB;QAC5B,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE;YACpB,OAAM;SACP;QAED,MAAM,IAAI,GAAG;YACX,GAAG,EAAE,IAAI,CAAC,SAAS;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GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAA;IAChC,CAAC;CACF"}
\ No newline at end of file
diff --git a/dist/esnext/index.d.ts b/dist/esnext/index.d.ts
index 9c77fcbb3..eb54f75d8 100644
--- a/dist/esnext/index.d.ts
+++ b/dist/esnext/index.d.ts
@@ -25,3 +25,13 @@ export declare function track(event: TrackEventOptions): void;
* @returns {PageActions} The actions related to the tracking. Used to stop tracking pages.
*/
export declare function trackViews(options?: PageViewsOptions): Promise<PageActions>;
+/**
+ * This function is used to manually track a page view event.
+ * It's useful if your application uses esoteric routing which is not supported by Swetrix by default.
+ *
+ * @param path Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
+ * @param prev Path of the previous page.
+ * @param unique If set to `true`, only 1 event with the same ID will be saved per user session.
+ * @returns void
+ */
+export declare function trackPageview(path: string, prev?: string, unique?: boolean): void;
diff --git a/dist/esnext/index.js b/dist/esnext/index.js
index f96627acd..12accf19b 100644
--- a/dist/esnext/index.js
+++ b/dist/esnext/index.js
@@ -51,4 +51,18 @@ export function trackViews(options) {
}
});
}
+/**
+ * This function is used to manually track a page view event.
+ * It's useful if your application uses esoteric routing which is not supported by Swetrix by default.
+ *
+ * @param path Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
+ * @param prev Path of the previous page.
+ * @param unique If set to `true`, only 1 event with the same ID will be saved per user session.
+ * @returns void
+ */
+export function trackPageview(path, prev, unique) {
+ if (!LIB_INSTANCE)
+ return;
+ LIB_INSTANCE.submitPageView(path, prev || null, Boolean(unique), {});
+}
//# sourceMappingURL=index.js.map
\ No newline at end of file
diff --git a/dist/esnext/index.js.map b/dist/esnext/index.js.map
index 26ac360fa..0aaf98007 100644
--- a/dist/esnext/index.js.map
+++ b/dist/esnext/index.js.map
@@ -1 +1 @@
-{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EAAgE,kBA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 b/dist/esnext/utils.d.ts
@@ -1,3 +1,7 @@
+interface IGetPath {
+ hash?: boolean;
+ search?: boolean;
+}
export declare const isInBrowser: () => boolean;
export declare const isLocalhost: () => boolean;
export declare const isAutomated: () => boolean;
@@ -7,4 +11,19 @@ export declare const getReferrer: () => string | undefined;
export declare const getUTMSource: () => string | undefined;
export declare const getUTMMedium: () => string | undefined;
export declare const getUTMCampaign: () => string | undefined;
-export declare const getPath: () => string;
+/**
+ * Function used to track the current page (path) of the application.
+ * Will work in cases where the path looks like:
+ * - /path
+ * - /#/path
+ * - /path?search
+ * - /path?search#hash
+ * - /path#hash?search
+ *
+ * @param options - Options for the function.
+ * @param options.hash - Whether to trigger on hash change.
+ * @param options.search - Whether to trigger on search change.
+ * @returns The path of the current page.
+ */
+export declare const getPath: (options: IGetPath) => string;
+export {};
diff --git a/dist/esnext/utils.js b/dist/esnext/utils.js
index f376b120c..c8083aa15 100644
--- a/dist/esnext/utils.js
+++ b/dist/esnext/utils.js
@@ -31,8 +31,32 @@ export const getReferrer = () => {
export const getUTMSource = () => findInSearch(utmSourceRegex);
export const getUTMMedium = () => findInSearch(utmMediumRegex);
export const getUTMCampaign = () => findInSearch(utmCampaignRegex);
-export const getPath = () => {
- // TODO: Maybe we should also include such data as location.hash or location.search
- return location.pathname || '';
+/**
+ * Function used to track the current page (path) of the application.
+ * Will work in cases where the path looks like:
+ * - /path
+ * - /#/path
+ * - /path?search
+ * - /path?search#hash
+ * - /path#hash?search
+ *
+ * @param options - Options for the function.
+ * @param options.hash - Whether to trigger on hash change.
+ * @param options.search - Whether to trigger on search change.
+ * @returns The path of the current page.
+ */
+export const getPath = (options) => {
+ let result = location.pathname || '';
+ if (options.hash) {
+ const hashIndex = location.hash.indexOf('?');
+ const hashString = hashIndex > -1 ? location.hash.substring(0, hashIndex) : location.hash;
+ result += hashString;
+ }
+ if (options.search) {
+ const hashIndex = location.hash.indexOf('?');
+ const searchString = location.search || (hashIndex > -1 ? location.hash.substring(hashIndex) : '');
+ result += searchString;
+ }
+ return result;
};
//# sourceMappingURL=utils.js.map
\ No newline at end of file
diff --git a/dist/esnext/utils.js.map b/dist/esnext/utils.js.map
index 78db14da6..ea5ff4542 100644
--- a/dist/esnext/utils.js.map
+++ b/dist/esnext/utils.js.map
@@ -1 +1 @@
-{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,MAAM,YAAY,GAAG,CAAC,GAAW,EAAsB,EAAE;IACvD,MAAM,GAAG,GAAG,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IACtC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,SAAS,CAAA;AACrC,CAAC,CAAA;AAED,MAAM,cAAc,GAAG,sCAAsC,CAAA;AAC7D,MAAM,gBAAgB,GAAG,6BAA6B,CAAA;AACtD,MAAM,cAAc,GAAG,2BAA2B,CAAA;AAElD,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,EAAE;IAC9B,OAAO,OAAO,MAAM,KAAK,WAAW,CAAA;AACtC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,EAAE;IAC9B,OAAO,QAAQ,EAAE,QAAQ,KAAK,WAAW,IAAI,QAAQ,EAAE,QAAQ,KAAK,WAAW,IAAI,QAAQ,EAAE,QAAQ,KAAK,EAAE,CAAA;AAC9G,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,EAAE;IAC9B,OAAO,SAAS,EAAE,SAAS,CAAA;AAC7B,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,EAAE;IAC5B,OAAO,OAAO,SAAS,CAAC,SAAS,KAAK,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAA;AACjG,CAAC,CAAA;AAED,MAAM,CAAC,MAAM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EAAE;QAChB,MAAM,SAAS,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;QAC5C,MAAM,UAAU,GAAG,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAA;QACzF,MAAM,IAAI,UAAU,CAAA;KACrB;IAED,IAAI,OAAO,CAAC,MAAM,EAAE;QAClB,MAAM,SAAS,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;QAC5C,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;QAClG,MAAM,IAAI,YAAY,CAAA;KACvB;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
\ No newline at end of file
diff --git a/dist/swetrix.cjs.js b/dist/swetrix.cjs.js
index a694e2a91..d8fe3bb6c 100644
--- a/dist/swetrix.cjs.js
+++ b/dist/swetrix.cjs.js
@@ -66,9 +66,33 @@ var getReferrer = function () {
var getUTMSource = function () { return findInSearch(utmSourceRegex); };
var getUTMMedium = function () { return findInSearch(utmMediumRegex); };
var getUTMCampaign = function () { return findInSearch(utmCampaignRegex); };
-var getPath = function () {
- // TODO: Maybe we should also include such data as location.hash or location.search
- return location.pathname || '';
+/**
+ * Function used to track the current page (path) of the application.
+ * Will work in cases where the path looks like:
+ * - /path
+ * - /#/path
+ * - /path?search
+ * - /path?search#hash
+ * - /path#hash?search
+ *
+ * @param options - Options for the function.
+ * @param options.hash - Whether to trigger on hash change.
+ * @param options.search - Whether to trigger on search change.
+ * @returns The path of the current page.
+ */
+var getPath = function (options) {
+ var result = location.pathname || '';
+ if (options.hash) {
+ var hashIndex = location.hash.indexOf('?');
+ var hashString = hashIndex > -1 ? location.hash.substring(0, hashIndex) : location.hash;
+ result += hashString;
+ }
+ if (options.search) {
+ var hashIndex = location.hash.indexOf('?');
+ var searchString = location.search || (hashIndex > -1 ? location.hash.substring(hashIndex) : '');
+ result += searchString;
+ }
+ return result;
};
var defaultPageActions = {
@@ -109,7 +133,10 @@ var Lib = /** @class */ (function () {
setTimeout(this.heartbeat, 3000);
hbInterval = setInterval(this.heartbeat, 28000);
}
- var path = getPath();
+ var path = getPath({
+ hash: options === null || options === void 0 ? void 0 : options.hash,
+ search: options === null || options === void 0 ? void 0 : options.search,
+ });
this.pageData = {
path: path,
actions: {
@@ -180,9 +207,13 @@ var Lib = /** @class */ (function () {
};
// Tracking path changes. If path changes -> calling this.trackPage method
Lib.prototype.trackPathChange = function () {
+ var _a, _b;
if (!this.pageData)
return;
- var newPath = getPath();
+ var newPath = getPath({
+ hash: (_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.hash,
+ search: (_b = this.pageViewsOptions) === null || _b === void 0 ? void 0 : _b.search,
+ });
var path = this.pageData.path;
if (path !== newPath) {
this.trackPage(newPath, false);
@@ -239,6 +270,10 @@ var Lib = /** @class */ (function () {
if (!((_b = this.pageViewsOptions) === null || _b === void 0 ? void 0 : _b.noUserFlow)) {
prev = this.getPreviousPage();
}
+ this.activePage = pg;
+ this.submitPageView(shouldIgnore ? null : pg, prev, unique, perf);
+ };
+ Lib.prototype.submitPageView = function (pg, prev, unique, perf) {
var data = {
pid: this.projectID,
lc: getLocale(),
@@ -248,11 +283,10 @@ var Lib = /** @class */ (function () {
me: getUTMMedium(),
ca: getUTMCampaign(),
unique: unique,
- pg: shouldIgnore ? null : pg,
+ pg: pg,
perf: perf,
prev: prev,
};
- this.activePage = pg;
this.sendRequest('', data);
};
Lib.prototype.debug = function (message) {
@@ -347,7 +381,22 @@ function trackViews(options) {
}
});
}
+/**
+ * This function is used to manually track a page view event.
+ * It's useful if your application uses esoteric routing which is not supported by Swetrix by default.
+ *
+ * @param path Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
+ * @param prev Path of the previous page.
+ * @param unique If set to `true`, only 1 event with the same ID will be saved per user session.
+ * @returns void
+ */
+function trackPageview(path, prev, unique) {
+ if (!exports.LIB_INSTANCE)
+ return;
+ exports.LIB_INSTANCE.submitPageView(path, prev || null, Boolean(unique), {});
+}
exports.init = init;
exports.track = track;
+exports.trackPageview = trackPageview;
exports.trackViews = trackViews;
diff --git a/dist/swetrix.es5.js b/dist/swetrix.es5.js
index 25a5f893a..0e9bc1ea6 100644
--- a/dist/swetrix.es5.js
+++ b/dist/swetrix.es5.js
@@ -62,9 +62,33 @@ var getReferrer = function () {
var getUTMSource = function () { return findInSearch(utmSourceRegex); };
var getUTMMedium = function () { return findInSearch(utmMediumRegex); };
var getUTMCampaign = function () { return findInSearch(utmCampaignRegex); };
-var getPath = function () {
- // TODO: Maybe we should also include such data as location.hash or location.search
- return location.pathname || '';
+/**
+ * Function used to track the current page (path) of the application.
+ * Will work in cases where the path looks like:
+ * - /path
+ * - /#/path
+ * - /path?search
+ * - /path?search#hash
+ * - /path#hash?search
+ *
+ * @param options - Options for the function.
+ * @param options.hash - Whether to trigger on hash change.
+ * @param options.search - Whether to trigger on search change.
+ * @returns The path of the current page.
+ */
+var getPath = function (options) {
+ var result = location.pathname || '';
+ if (options.hash) {
+ var hashIndex = location.hash.indexOf('?');
+ var hashString = hashIndex > -1 ? location.hash.substring(0, hashIndex) : location.hash;
+ result += hashString;
+ }
+ if (options.search) {
+ var hashIndex = location.hash.indexOf('?');
+ var searchString = location.search || (hashIndex > -1 ? location.hash.substring(hashIndex) : '');
+ result += searchString;
+ }
+ return result;
};
var defaultPageActions = {
@@ -105,7 +129,10 @@ var Lib = /** @class */ (function () {
setTimeout(this.heartbeat, 3000);
hbInterval = setInterval(this.heartbeat, 28000);
}
- var path = getPath();
+ var path = getPath({
+ hash: options === null || options === void 0 ? void 0 : options.hash,
+ search: options === null || options === void 0 ? void 0 : options.search,
+ });
this.pageData = {
path: path,
actions: {
@@ -176,9 +203,13 @@ var Lib = /** @class */ (function () {
};
// Tracking path changes. If path changes -> calling this.trackPage method
Lib.prototype.trackPathChange = function () {
+ var _a, _b;
if (!this.pageData)
return;
- var newPath = getPath();
+ var newPath = getPath({
+ hash: (_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.hash,
+ search: (_b = this.pageViewsOptions) === null || _b === void 0 ? void 0 : _b.search,
+ });
var path = this.pageData.path;
if (path !== newPath) {
this.trackPage(newPath, false);
@@ -235,6 +266,10 @@ var Lib = /** @class */ (function () {
if (!((_b = this.pageViewsOptions) === null || _b === void 0 ? void 0 : _b.noUserFlow)) {
prev = this.getPreviousPage();
}
+ this.activePage = pg;
+ this.submitPageView(shouldIgnore ? null : pg, prev, unique, perf);
+ };
+ Lib.prototype.submitPageView = function (pg, prev, unique, perf) {
var data = {
pid: this.projectID,
lc: getLocale(),
@@ -244,11 +279,10 @@ var Lib = /** @class */ (function () {
me: getUTMMedium(),
ca: getUTMCampaign(),
unique: unique,
- pg: shouldIgnore ? null : pg,
+ pg: pg,
perf: perf,
prev: prev,
};
- this.activePage = pg;
this.sendRequest('', data);
};
Lib.prototype.debug = function (message) {
@@ -343,5 +377,19 @@ function trackViews(options) {
}
});
}
+/**
+ * This function is used to manually track a page view event.
+ * It's useful if your application uses esoteric routing which is not supported by Swetrix by default.
+ *
+ * @param path Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
+ * @param prev Path of the previous page.
+ * @param unique If set to `true`, only 1 event with the same ID will be saved per user session.
+ * @returns void
+ */
+function trackPageview(path, prev, unique) {
+ if (!LIB_INSTANCE)
+ return;
+ LIB_INSTANCE.submitPageView(path, prev || null, Boolean(unique), {});
+}
-export { LIB_INSTANCE, init, track, trackViews };
+export { LIB_INSTANCE, init, track, trackPageview, trackViews };
diff --git a/dist/swetrix.js b/dist/swetrix.js
index 55ec4db23..c811f736c 100644
--- a/dist/swetrix.js
+++ b/dist/swetrix.js
@@ -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(n){"use strict";function t(t){return(t=location.search.match(t))&&t[2]||void 0}function r(){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 t(o)}function l(){return t(d)}function p(){return t(a)}function i(){return location.pathname||""}var e=function(){return(e=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)},o=/[?&](ref|source|utm_source)=([^?&]+)/,a=/[?&](utm_campaign)=([^?&]+)/,d=/[?&](utm_medium)=([^?&]+)/,h={stop:function(){}},g=(f.prototype.track=function(t){this.canTrack()&&(t=e({pid:this.projectID,pg:this.activePage,lc:r(),tz:s(),ref:c(),so:u(),me:l(),ca:p()},t),this.sendRequest("custom",t))},f.prototype.trackPageViews=function(t){var e,n,o;return this.canTrack()?(this.pageData||(null!=(this.pageViewsOptions=t)&&t.unique||(n=setInterval(this.trackPathChange,2e3)),null!=t&&t.noHeartbeat||(setTimeout(this.heartbeat,3e3),e=setInterval(this.heartbeat,28e3)),o=i(),this.pageData={path:o,actions:{stop:function(){clearInterval(n),clearInterval(e)}}},this.trackPage(o,null==t?void 0:t.unique)),this.pageData.actions):h},f.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}):{}},f.prototype.heartbeat=function(){var t;(null!=(t=this.pageViewsOptions)&&t.heartbeatOnBackground||"hidden"!==document.visibilityState)&&(t={pid:this.projectID},this.sendRequest("hb",t))},f.prototype.checkIgnore=function(t){var e,n=null==(e=this.pageViewsOptions)?void 0:e.ignore;if(Array.isArray(n))for(var o=0;o<n.length;++o){if(n[o]===t)return!0;if(n[o]instanceof RegExp&&n[o].test(t))return!0}return!1},f.prototype.trackPathChange=function(){var t;this.pageData&&(t=i(),this.pageData.path!==t)&&this.trackPage(t,!1)},f.prototype.getPreviousPage=function(){var t;if(this.activePage)return(o=this.checkIgnore(this.activePage))&&null!=(e=this.pageViewsOptions)&&e.doNotAnonymise||o?null:this.activePage;if("function"==typeof URL){var e=c();if(!e)return null;var n=location.host;try{var o,i=new URL(e),a=i.host,r=i.pathname;return n!==a?null:(o=this.checkIgnore(r))&&null!=(t=this.pageViewsOptions)&&t.doNotAnonymise||o?null:r}catch(t){}}return null},f.prototype.trackPage=function(t,e){var n,o,i,a;void 0===e&&(e=!1),this.pageData&&(this.pageData.path=t,(n=this.checkIgnore(t))&&null!=(o=this.pageViewsOptions)&&o.doNotAnonymise||(o=this.getPerformanceStats(),null!=(a=this.pageViewsOptions)&&a.noUserFlow||(i=this.getPreviousPage()),a={pid:this.projectID,lc:r(),tz:s(),ref:c(),so:u(),me:l(),ca:p(),unique:e,pg:n?null:t,perf:o,prev:i},this.activePage=t,this.sendRequest("",a)))},f.prototype.debug=function(t){var e;null!=(e=this.options)&&e.debug&&console.log("[Swetrix]",t)},f.prototype.canTrack=function(){var t;return null!=(t=this.options)&&t.disabled?(this.debug("Tracking disabled: the 'disabled' setting is set to true."),!1):"undefined"==typeof window?(this.debug("Tracking disabled: script does not run in browser environment."),!1):null!=(t=this.options)&&t.respectDNT&&"1"===(null==(t=window.navigator)?void 0:t.doNotTrack)?(this.debug("Tracking disabled: respecting user's 'Do Not Track' preference."),!1):!(!(null!=(t=this.options)&&t.debug||"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&&(this.debug("Tracking disabled: navigation is automated by WebDriver."),1))},f.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))},f);function f(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)}n.LIB_INSTANCE=null,n.init=function(t,e){return n.LIB_INSTANCE||(n.LIB_INSTANCE=new g(t,e)),n.LIB_INSTANCE},n.track=function(t){n.LIB_INSTANCE&&n.LIB_INSTANCE.track(t)},n.trackViews=function(e){return new Promise(function(t){n.LIB_INSTANCE?"undefined"==typeof document||"complete"===document.readyState?t(n.LIB_INSTANCE.trackPageViews(e)):window.addEventListener("load",function(){t(n.LIB_INSTANCE.trackPageViews(e))}):t(h)})},Object.defineProperty(n,"__esModule",{value:!0})});
+!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 a(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch(t){}}function s(){return document.referrer||void 0}function r(){return t(n)}function c(){return t(p)}function u(){return t(h)}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 e=function(){return(e=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)},n=/[?&](ref|source|utm_source)=([^?&]+)/,h=/[?&](utm_campaign)=([^?&]+)/,p=/[?&](utm_medium)=([^?&]+)/,d={stop:function(){}},g=(f.prototype.track=function(t){this.canTrack()&&(t=e({pid:this.projectID,pg:this.activePage,lc:i(),tz:a(),ref:s(),so:r(),me:c(),ca:u()},t),this.sendRequest("custom",t))},f.prototype.trackPageViews=function(t){var e,n,o;return this.canTrack()?(this.pageData||(null!=(this.pageViewsOptions=t)&&t.unique||(n=setInterval(this.trackPathChange,2e3)),null!=t&&t.noHeartbeat||(setTimeout(this.heartbeat,3e3),e=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(n),clearInterval(e)}}},this.trackPage(o,null==t?void 0:t.unique)),this.pageData.actions):d},f.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}):{}},f.prototype.heartbeat=function(){var t;(null!=(t=this.pageViewsOptions)&&t.heartbeatOnBackground||"hidden"!==document.visibilityState)&&(t={pid:this.projectID},this.sendRequest("hb",t))},f.prototype.checkIgnore=function(t){var e,n=null==(e=this.pageViewsOptions)?void 0:e.ignore;if(Array.isArray(n))for(var o=0;o<n.length;++o){if(n[o]===t)return!0;if(n[o]instanceof RegExp&&n[o].test(t))return!0}return!1},f.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)},f.prototype.getPreviousPage=function(){var t;if(this.activePage)return(o=this.checkIgnore(this.activePage))&&null!=(e=this.pageViewsOptions)&&e.doNotAnonymise||o?null:this.activePage;if("function"==typeof URL){var e=s();if(!e)return null;var n=location.host;try{var o,i=new URL(e),a=i.host,r=i.pathname;return n!==a?null:(o=this.checkIgnore(r))&&null!=(t=this.pageViewsOptions)&&t.doNotAnonymise||o?null:r}catch(t){}}return null},f.prototype.trackPage=function(t,e){var n,o,i,a;void 0===e&&(e=!1),this.pageData&&(this.pageData.path=t,(o=this.checkIgnore(t))&&null!=(i=this.pageViewsOptions)&&i.doNotAnonymise||(i=this.getPerformanceStats(),null!=(n=this.pageViewsOptions)&&n.noUserFlow||(a=this.getPreviousPage()),this.activePage=t,this.submitPageView(o?null:t,a,e,i)))},f.prototype.submitPageView=function(t,e,n,o){n={pid:this.projectID,lc:i(),tz:a(),ref:s(),so:r(),me:c(),ca:u(),unique:n,pg:t,perf:o,prev:e};this.sendRequest("",n)},f.prototype.debug=function(t){var e;null!=(e=this.options)&&e.debug&&console.log("[Swetrix]",t)},f.prototype.canTrack=function(){var t;return null!=(t=this.options)&&t.disabled?(this.debug("Tracking disabled: the 'disabled' setting is set to true."),!1):"undefined"==typeof window?(this.debug("Tracking disabled: script does not run in browser environment."),!1):null!=(t=this.options)&&t.respectDNT&&"1"===(null==(t=window.navigator)?void 0:t.doNotTrack)?(this.debug("Tracking disabled: respecting user's 'Do Not Track' preference."),!1):!(!(null!=(t=this.options)&&t.debug||"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&&(this.debug("Tracking disabled: navigation is automated by WebDriver."),1))},f.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))},f);function f(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)}o.LIB_INSTANCE=null,o.init=function(t,e){return o.LIB_INSTANCE||(o.LIB_INSTANCE=new g(t,e)),o.LIB_INSTANCE},o.track=function(t){o.LIB_INSTANCE&&o.LIB_INSTANCE.track(t)},o.trackPageview=function(t,e,n){o.LIB_INSTANCE&&o.LIB_INSTANCE.submitPageView(t,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})});
diff --git a/dist/swetrix.orig.js b/dist/swetrix.orig.js
index 762158ac7..ee952e628 100644
--- a/dist/swetrix.orig.js
+++ b/dist/swetrix.orig.js
@@ -68,9 +68,33 @@
var getUTMSource = function () { return findInSearch(utmSourceRegex); };
var getUTMMedium = function () { return findInSearch(utmMediumRegex); };
var getUTMCampaign = function () { return findInSearch(utmCampaignRegex); };
- var getPath = function () {
- // TODO: Maybe we should also include such data as location.hash or location.search
- return location.pathname || '';
+ /**
+ * Function used to track the current page (path) of the application.
+ * Will work in cases where the path looks like:
+ * - /path
+ * - /#/path
+ * - /path?search
+ * - /path?search#hash
+ * - /path#hash?search
+ *
+ * @param options - Options for the function.
+ * @param options.hash - Whether to trigger on hash change.
+ * @param options.search - Whether to trigger on search change.
+ * @returns The path of the current page.
+ */
+ var getPath = function (options) {
+ var result = location.pathname || '';
+ if (options.hash) {
+ var hashIndex = location.hash.indexOf('?');
+ var hashString = hashIndex > -1 ? location.hash.substring(0, hashIndex) : location.hash;
+ result += hashString;
+ }
+ if (options.search) {
+ var hashIndex = location.hash.indexOf('?');
+ var searchString = location.search || (hashIndex > -1 ? location.hash.substring(hashIndex) : '');
+ result += searchString;
+ }
+ return result;
};
var defaultPageActions = {
@@ -111,7 +135,10 @@
setTimeout(this.heartbeat, 3000);
hbInterval = setInterval(this.heartbeat, 28000);
}
- var path = getPath();
+ var path = getPath({
+ hash: options === null || options === void 0 ? void 0 : options.hash,
+ search: options === null || options === void 0 ? void 0 : options.search,
+ });
this.pageData = {
path: path,
actions: {
@@ -182,9 +209,13 @@
};
// Tracking path changes. If path changes -> calling this.trackPage method
Lib.prototype.trackPathChange = function () {
+ var _a, _b;
if (!this.pageData)
return;
- var newPath = getPath();
+ var newPath = getPath({
+ hash: (_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.hash,
+ search: (_b = this.pageViewsOptions) === null || _b === void 0 ? void 0 : _b.search,
+ });
var path = this.pageData.path;
if (path !== newPath) {
this.trackPage(newPath, false);
@@ -241,6 +272,10 @@
if (!((_b = this.pageViewsOptions) === null || _b === void 0 ? void 0 : _b.noUserFlow)) {
prev = this.getPreviousPage();
}
+ this.activePage = pg;
+ this.submitPageView(shouldIgnore ? null : pg, prev, unique, perf);
+ };
+ Lib.prototype.submitPageView = function (pg, prev, unique, perf) {
var data = {
pid: this.projectID,
lc: getLocale(),
@@ -250,11 +285,10 @@
me: getUTMMedium(),
ca: getUTMCampaign(),
unique: unique,
- pg: shouldIgnore ? null : pg,
+ pg: pg,
perf: perf,
prev: prev,
};
- this.activePage = pg;
this.sendRequest('', data);
};
Lib.prototype.debug = function (message) {
@@ -349,9 +383,24 @@
}
});
}
+ /**
+ * This function is used to manually track a page view event.
+ * It's useful if your application uses esoteric routing which is not supported by Swetrix by default.
+ *
+ * @param path Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
+ * @param prev Path of the previous page.
+ * @param unique If set to `true`, only 1 event with the same ID will be saved per user session.
+ * @returns void
+ */
+ function trackPageview(path, prev, unique) {
+ if (!exports.LIB_INSTANCE)
+ return;
+ exports.LIB_INSTANCE.submitPageView(path, prev || null, Boolean(unique), {});
+ }
exports.init = init;
exports.track = track;
+ exports.trackPageview = trackPageview;
exports.trackViews = trackViews;
Object.defineProperty(exports, '__esModule', { value: true });