mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-14 21:10:34 +01:00
Allow alternate host url in tracker.
This commit is contained in:
parent
aec012fb79
commit
cebd3fd924
@ -1,11 +1,11 @@
|
|||||||
export function removeTrailingSlash(url) {
|
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) {
|
export function getDomainName(str) {
|
||||||
try {
|
try {
|
||||||
return new URL(str).hostname;
|
return new URL(str).hostname;
|
||||||
} catch {
|
} catch (e) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "umami",
|
"name": "umami",
|
||||||
"version": "0.19.0",
|
"version": "0.20.0",
|
||||||
"description": "A simple, fast, website analytics alternative to Google Analytics. ",
|
"description": "A simple, fast, website analytics alternative to Google Analytics. ",
|
||||||
"author": "Mike Cao <mike@mikecao.com>",
|
"author": "Mike Cao <mike@mikecao.com>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import 'promise-polyfill/src/polyfill';
|
import 'promise-polyfill/src/polyfill';
|
||||||
import 'unfetch/polyfill';
|
import 'unfetch/polyfill';
|
||||||
import { post, hook, doNotTrack } from '../lib/web';
|
import { post, hook, doNotTrack } from '../lib/web';
|
||||||
|
import { removeTrailingSlash } from '../lib/url';
|
||||||
|
|
||||||
(window => {
|
(window => {
|
||||||
const {
|
const {
|
||||||
@ -17,7 +18,10 @@ import { post, hook, doNotTrack } from '../lib/web';
|
|||||||
if (!script || (__DNT__ && doNotTrack())) return;
|
if (!script || (__DNT__ && doNotTrack())) return;
|
||||||
|
|
||||||
const website = script.getAttribute('data-website-id');
|
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 screen = `${width}x${height}`;
|
||||||
const listeners = [];
|
const listeners = [];
|
||||||
|
|
||||||
@ -42,7 +46,7 @@ import { post, hook, doNotTrack } from '../lib/web';
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return post(`${hostUrl}/api/collect`, {
|
return post(`${root}/api/collect`, {
|
||||||
type,
|
type,
|
||||||
payload,
|
payload,
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user