mirror of
https://github.com/umami-software/umami.git
synced 2025-12-06 01:18:00 +01:00
move parseParameters to UTMView
This commit is contained in:
parent
6d124e7bb0
commit
2203ba1fe7
2 changed files with 28 additions and 28 deletions
|
|
@ -15,6 +15,31 @@ function toArray(data: { [key: string]: number } = {}) {
|
|||
.sort(firstBy('value', -1));
|
||||
}
|
||||
|
||||
function parseParameters(data: any[]) {
|
||||
return data.reduce((obj, { url_query, num }) => {
|
||||
try {
|
||||
const searchParams = new URLSearchParams(url_query);
|
||||
|
||||
for (const [key, value] of searchParams) {
|
||||
if (key.match(/^utm_(\w+)$/)) {
|
||||
const name = value;
|
||||
if (!obj[key]) {
|
||||
obj[key] = { [name]: Number(num) };
|
||||
} else if (!obj[key][name]) {
|
||||
obj[key][name] = Number(num);
|
||||
} else {
|
||||
obj[key][name] += Number(num);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
return obj;
|
||||
}, {});
|
||||
}
|
||||
|
||||
export default function UTMView() {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { report } = useContext(ReportContext);
|
||||
|
|
@ -27,7 +52,7 @@ export default function UTMView() {
|
|||
return (
|
||||
<div>
|
||||
{UTM_PARAMS.map(param => {
|
||||
const items = toArray(data[param]);
|
||||
const items = toArray(parseParameters(data)[param]);
|
||||
const chartData = {
|
||||
labels: items.map(({ name }) => name),
|
||||
datasets: [
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ async function relationalQuery(
|
|||
startDate,
|
||||
endDate,
|
||||
},
|
||||
).then(result => parseParameters(result as any[]));
|
||||
);
|
||||
}
|
||||
|
||||
async function clickhouseQuery(
|
||||
|
|
@ -73,30 +73,5 @@ async function clickhouseQuery(
|
|||
startDate,
|
||||
endDate,
|
||||
},
|
||||
).then(result => parseParameters(result as any[]));
|
||||
}
|
||||
|
||||
function parseParameters(data: any[]) {
|
||||
return data.reduce((obj, { url_query, num }) => {
|
||||
try {
|
||||
const searchParams = new URLSearchParams(url_query);
|
||||
|
||||
for (const [key, value] of searchParams) {
|
||||
if (key.match(/^utm_(\w+)$/)) {
|
||||
const name = value;
|
||||
if (!obj[key]) {
|
||||
obj[key] = { [name]: Number(num) };
|
||||
} else if (!obj[key][name]) {
|
||||
obj[key][name] = Number(num);
|
||||
} else {
|
||||
obj[key][name] += Number(num);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
return obj;
|
||||
}, {});
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue