Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
Allow alternate host url in tracker.
Mike Caocebd3fd924af
diff --git a/lib/url.js b/lib/url.jsindex e29243fb7..0eb4a04a3 100644--- a/lib/url.js+++ b/lib/url.js@@ -1,11 +1,11 @@export function removeTrailingSlash(url) {- return url.length > 1 && url.endsWith('/') ? url.slice(0, -1) : url;+ return url && url.length > 1 && url.endsWith('/') ? url.slice(0, -1) : url;}export function getDomainName(str) {try {return new URL(str).hostname;- } catch {+ } catch (e) {return str;}}diff --git a/package.json b/package.jsonindex 80bf5f9cc..a6cca6bb9 100644--- a/package.json+++ b/package.json@@ -1,6 +1,6 @@{"name": "umami",- "version": "0.19.0",+ "version": "0.20.0","description": "A simple, fast, website analytics alternative to Google Analytics. ","author": "Mike Cao <[email protected]>","license": "MIT",diff --git a/tracker/index.js b/tracker/index.jsindex a30a02204..f0ad78cda 100644--- a/tracker/index.js+++ b/tracker/index.js@@ -1,6 +1,7 @@import 'promise-polyfill/src/polyfill';import 'unfetch/polyfill';import { post, hook, doNotTrack } from '../lib/web';+import { removeTrailingSlash } from '../lib/url';(window => {const {@@ -17,7 +18,10 @@ import { post, hook, doNotTrack } from '../lib/web';if (!script || (__DNT__ && doNotTrack())) return;const website = script.getAttribute('data-website-id');- const hostUrl = new URL(script.src).href.split('/').slice(0, -1).join('/');+ const hostUrl = script.getAttribute('data-host-url');+ const root = hostUrl+ ? removeTrailingSlash(hostUrl)+ : new URL(script.src).href.split('/').slice(0, -1).join('/');const screen = `${width}x${height}`;const listeners = [];@@ -42,7 +46,7 @@ import { post, hook, doNotTrack } from '../lib/web';});}- return post(`${hostUrl}/api/collect`, {+ return post(`${root}/api/collect`, {type,payload,});