📈 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!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
added support for manual pageviews
Blue Mouse77ce79783eeb
diff --git a/src/Lib.ts b/src/Lib.tsindex df6f69d01..2c703a2f2 100644--- a/src/Lib.ts+++ b/src/Lib.ts@@ -303,6 +303,11 @@ export class Lib {prev = this.getPreviousPage()}+ this.activePage = pg+ this.submitPageView(shouldIgnore ? null : pg, prev, unique, perf)+ }++ submitPageView(pg: null | string, prev: string | null | undefined, unique: boolean, perf: any): void {const data = {pid: this.projectID,lc: getLocale(),@@ -312,12 +317,11 @@ export class Lib {me: getUTMMedium(),ca: getUTMCampaign(),unique,- pg: shouldIgnore ? null : pg,+ pg,perf,prev,}- this.activePage = pgthis.sendRequest('', data)}diff --git a/src/index.ts b/src/index.tsindex 6e59a4cce..cf185badf 100644--- a/src/index.ts+++ b/src/index.ts@@ -58,3 +58,18 @@ export 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 function trackPageview(path: string, prev?: string, unique?: boolean): void {+ if (!LIB_INSTANCE) return++ LIB_INSTANCE.submitPageView(path, prev || null, Boolean(unique), {})+}