mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-24 19:10:21 +01:00
Merge branch 'dev' into analytics
This commit is contained in:
commit
08ca6c1433
@ -1,5 +1,5 @@
|
||||
.title {
|
||||
font-size: 18px;
|
||||
font-size: 24px;
|
||||
line-height: 36px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
@ -26,8 +26,8 @@ export default function UTMView() {
|
||||
|
||||
return (
|
||||
<div>
|
||||
{UTM_PARAMS.map(key => {
|
||||
const items = toArray(data[key]);
|
||||
{UTM_PARAMS.map(param => {
|
||||
const items = toArray(data[param]);
|
||||
const chartData = {
|
||||
labels: items.map(({ name }) => name),
|
||||
datasets: [
|
||||
@ -42,9 +42,9 @@ export default function UTMView() {
|
||||
}, 0);
|
||||
|
||||
return (
|
||||
<div key={key} className={styles.row}>
|
||||
<div key={param} className={styles.row}>
|
||||
<div>
|
||||
<div className={styles.title}>{key}</div>
|
||||
<div className={styles.title}>{param.replace(/^utm_/, '')}</div>
|
||||
<ListTable
|
||||
metric={formatMessage(labels.views)}
|
||||
data={items.map(({ name, value }) => ({
|
||||
|
@ -228,7 +228,7 @@ export const URL_LENGTH = 500;
|
||||
export const PAGE_TITLE_LENGTH = 500;
|
||||
export const EVENT_NAME_LENGTH = 50;
|
||||
|
||||
export const UTM_PARAMS = ['source', 'medium', 'campaign', 'term', 'content'];
|
||||
export const UTM_PARAMS = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content'];
|
||||
|
||||
export const DESKTOP_OS = [
|
||||
'BeOS',
|
||||
|
@ -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…
Reference in New Issue
Block a user