mirror of
https://github.com/umami-software/umami.git
synced 2026-02-08 22:57:12 +01:00
Fixed UTM calculation.
This commit is contained in:
parent
96af798d42
commit
fb3536c352
4 changed files with 22 additions and 25 deletions
|
|
@ -92,29 +92,26 @@ async function clickhouseQuery(
|
|||
).then(result => parseParameters(result as any[]));
|
||||
}
|
||||
|
||||
function parseParameters(result: any[]) {
|
||||
return Object.values(result).reduce((data, { url_query, num }) => {
|
||||
const params = url_query.split('&').map(n => decodeURIComponent(n));
|
||||
function parseParameters(data: any[]) {
|
||||
return data.reduce((obj, { url_query, num }) => {
|
||||
try {
|
||||
const searchParams = new URLSearchParams(url_query);
|
||||
|
||||
for (const param of params) {
|
||||
const [key, value] = param.split('=');
|
||||
|
||||
const match = key.match(/^utm_(\w+)$/);
|
||||
|
||||
if (match) {
|
||||
const group = match[1];
|
||||
const name = decodeURIComponent(value);
|
||||
|
||||
if (!data[group]) {
|
||||
data[group] = { [name]: +num };
|
||||
} else if (!data[group][name]) {
|
||||
data[group][name] = +num;
|
||||
} else {
|
||||
data[group][name] += +num;
|
||||
for (const [key, value] of searchParams) {
|
||||
if (key.match(/^utm_(\w+)$/)) {
|
||||
if (!obj[key]) {
|
||||
obj[key] = { [value]: +num };
|
||||
} else if (!obj[key][value]) {
|
||||
obj[key][value] = +num;
|
||||
} else {
|
||||
obj[key][value] += +num;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
return data;
|
||||
return obj;
|
||||
}, {});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue