mirror of
https://github.com/umami-software/umami.git
synced 2026-02-10 15:47:13 +01:00
Updated tracker to send full url.
This commit is contained in:
parent
5c2cb97070
commit
a2a39b7ecd
2 changed files with 33 additions and 29 deletions
|
|
@ -1,7 +1,6 @@
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { isbot } from 'isbot';
|
import { isbot } from 'isbot';
|
||||||
import { createToken, parseToken } from '@/lib/jwt';
|
import { createToken, parseToken } from '@/lib/jwt';
|
||||||
import { safeDecodeURI } from '@/lib/url';
|
|
||||||
import clickhouse from '@/lib/clickhouse';
|
import clickhouse from '@/lib/clickhouse';
|
||||||
import { parseRequest } from '@/lib/request';
|
import { parseRequest } from '@/lib/request';
|
||||||
import { badRequest, json, forbidden, serverError } from '@/lib/response';
|
import { badRequest, json, forbidden, serverError } from '@/lib/response';
|
||||||
|
|
@ -129,26 +128,32 @@ export async function POST(request: Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === COLLECTION_TYPE.event) {
|
if (type === COLLECTION_TYPE.event) {
|
||||||
// eslint-disable-next-line prefer-const
|
const base = hostname ? `http://${hostname}` : 'http://localhost';
|
||||||
let [urlPath, urlQuery] = safeDecodeURI(url)?.split('?') || [];
|
const currentUrl = new URL(url, base);
|
||||||
let [referrerPath, referrerQuery] = safeDecodeURI(referrer)?.split('?') || [];
|
|
||||||
let referrerDomain = '';
|
|
||||||
|
|
||||||
if (!urlPath) {
|
let urlPath = currentUrl.pathname;
|
||||||
urlPath = '/';
|
const urlQuery = currentUrl.search.substring(1);
|
||||||
}
|
const urlDomain = currentUrl.hostname.replace(/^www\./, '');
|
||||||
|
|
||||||
if (/^[\w-]+:\/\/\w+/.test(referrerPath)) {
|
|
||||||
const refUrl = new URL(referrer);
|
|
||||||
referrerPath = refUrl.pathname;
|
|
||||||
referrerQuery = refUrl.search.substring(1);
|
|
||||||
referrerDomain = refUrl.hostname.replace(/www\./, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (process.env.REMOVE_TRAILING_SLASH) {
|
if (process.env.REMOVE_TRAILING_SLASH) {
|
||||||
urlPath = urlPath.replace(/(.+)\/$/, '$1');
|
urlPath = urlPath.replace(/(.+)\/$/, '$1');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let referrerPath: string;
|
||||||
|
let referrerQuery: string;
|
||||||
|
let referrerDomain: string;
|
||||||
|
|
||||||
|
if (referrer) {
|
||||||
|
const referrerUrl = new URL(referrer, base);
|
||||||
|
|
||||||
|
referrerPath = referrerUrl.pathname;
|
||||||
|
referrerQuery = referrerUrl.search.substring(1);
|
||||||
|
|
||||||
|
if (referrerUrl.hostname !== 'localhost') {
|
||||||
|
referrerDomain = referrerUrl.hostname.replace(/^www\./, '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await saveEvent({
|
await saveEvent({
|
||||||
websiteId,
|
websiteId,
|
||||||
sessionId,
|
sessionId,
|
||||||
|
|
@ -161,7 +166,7 @@ export async function POST(request: Request) {
|
||||||
pageTitle: title,
|
pageTitle: title,
|
||||||
eventName: name,
|
eventName: name,
|
||||||
eventData: data,
|
eventData: data,
|
||||||
hostname,
|
hostname: hostname || urlDomain,
|
||||||
browser,
|
browser,
|
||||||
os,
|
os,
|
||||||
device,
|
device,
|
||||||
|
|
|
||||||
|
|
@ -35,19 +35,8 @@
|
||||||
|
|
||||||
/* Helper functions */
|
/* Helper functions */
|
||||||
|
|
||||||
const parseURL = url => {
|
|
||||||
try {
|
|
||||||
const { pathname, search, hash } = new URL(url, location.href);
|
|
||||||
|
|
||||||
return pathname + (excludeSearch ? '' : search) + (excludeHash ? '' : hash);
|
|
||||||
} catch (e) {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const getPayload = () => ({
|
const getPayload = () => ({
|
||||||
website,
|
website,
|
||||||
hostname,
|
|
||||||
screen,
|
screen,
|
||||||
language,
|
language,
|
||||||
title,
|
title,
|
||||||
|
|
@ -62,7 +51,17 @@
|
||||||
if (!url) return;
|
if (!url) return;
|
||||||
|
|
||||||
currentRef = currentUrl;
|
currentRef = currentUrl;
|
||||||
currentUrl = parseURL(url.toString());
|
currentUrl = new URL(url, location.href);
|
||||||
|
|
||||||
|
if (excludeSearch) {
|
||||||
|
currentUrl.search = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (excludeHash) {
|
||||||
|
currentUrl.hash = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
currentUrl = currentUrl.toString();
|
||||||
|
|
||||||
if (currentUrl !== currentRef) {
|
if (currentUrl !== currentRef) {
|
||||||
setTimeout(track, delayDuration);
|
setTimeout(track, delayDuration);
|
||||||
|
|
@ -250,7 +249,7 @@
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let currentUrl = parseURL(href);
|
let currentUrl = href;
|
||||||
let currentRef = referrer.startsWith(origin) ? '' : referrer;
|
let currentRef = referrer.startsWith(origin) ? '' : referrer;
|
||||||
let title = document.title;
|
let title = document.title;
|
||||||
let cache;
|
let cache;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue