mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-06 01:15:42 +01:00
template multiple queries for filtering
This commit is contained in:
parent
3494ae46b7
commit
cb4368e12c
@ -30,7 +30,9 @@ CREATE TABLE umami.website_event
|
|||||||
job_id Nullable(UUID)
|
job_id Nullable(UUID)
|
||||||
)
|
)
|
||||||
engine = MergeTree
|
engine = MergeTree
|
||||||
ORDER BY (website_id, session_id, created_at)
|
PARTITION BY toYYYYMM(created_at)
|
||||||
|
ORDER BY (toStartOfHour(created_at), website_id, session_id, visit_id, created_at)
|
||||||
|
PRIMARY KEY (toStartOfHour(created_at), website_id, session_id, visit_id)
|
||||||
SETTINGS index_granularity = 8192;
|
SETTINGS index_granularity = 8192;
|
||||||
|
|
||||||
CREATE TABLE umami.event_data
|
CREATE TABLE umami.event_data
|
||||||
@ -97,15 +99,9 @@ CREATE TABLE umami.website_event_stats_hourly
|
|||||||
created_at Datetime('UTC')
|
created_at Datetime('UTC')
|
||||||
)
|
)
|
||||||
ENGINE = AggregatingMergeTree
|
ENGINE = AggregatingMergeTree
|
||||||
PARTITION BY toYYYYMM(created_at)
|
PARTITION BY toYYYYMM(created_at)
|
||||||
ORDER BY (
|
ORDER BY (toStartOfDay(created_at), website_id, session_id, visit_id, created_at)
|
||||||
website_id,
|
PRIMARY KEY (toStartOfDay(created_at), website_id, session_id, visit_id)
|
||||||
event_type,
|
|
||||||
toStartOfHour(created_at),
|
|
||||||
cityHash64(visit_id),
|
|
||||||
visit_id
|
|
||||||
)
|
|
||||||
SAMPLE BY cityHash64(visit_id);
|
|
||||||
|
|
||||||
CREATE MATERIALIZED VIEW umami.website_event_stats_hourly_mv
|
CREATE MATERIALIZED VIEW umami.website_event_stats_hourly_mv
|
||||||
TO umami.website_event_stats_hourly
|
TO umami.website_event_stats_hourly
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
/* eslint-disable no-unused-vars, @typescript-eslint/no-unused-vars */
|
|
||||||
import clickhouse from 'lib/clickhouse';
|
import clickhouse from 'lib/clickhouse';
|
||||||
import { EVENT_TYPE } from 'lib/constants';
|
import { EVENT_TYPE } from 'lib/constants';
|
||||||
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
|
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
|
||||||
@ -69,8 +68,30 @@ async function clickhouseQuery(
|
|||||||
});
|
});
|
||||||
|
|
||||||
return rawQuery(
|
return rawQuery(
|
||||||
|
// `
|
||||||
|
// select
|
||||||
|
// sum(t.c) as "pageviews",
|
||||||
|
// count(distinct t.session_id) as "visitors",
|
||||||
|
// count(distinct t.visit_id) as "visits",
|
||||||
|
// sum(if(t.c = 1, 1, 0)) as "bounces",
|
||||||
|
// sum(max_time-min_time) as "totaltime"
|
||||||
|
// from (
|
||||||
|
// select
|
||||||
|
// session_id,
|
||||||
|
// visit_id,
|
||||||
|
// count(*) c,
|
||||||
|
// min(created_at) min_time,
|
||||||
|
// max(created_at) max_time
|
||||||
|
// from website_event
|
||||||
|
// where website_id = {websiteId:UUID}
|
||||||
|
// and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||||
|
// and event_type = {eventType:UInt32}
|
||||||
|
// ${filterQuery}
|
||||||
|
// group by session_id, visit_id
|
||||||
|
// ) as t;
|
||||||
|
// `,
|
||||||
`
|
`
|
||||||
select
|
select
|
||||||
sum(views) as "pageviews",
|
sum(views) as "pageviews",
|
||||||
uniq(session_id) as "visitors",
|
uniq(session_id) as "visitors",
|
||||||
uniq(visit_id) as "visits",
|
uniq(visit_id) as "visits",
|
||||||
|
@ -111,7 +111,25 @@ async function clickhouseQuery(
|
|||||||
groupByQuery = 'group by x';
|
groupByQuery = 'group by x';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// let excludeDomain = '';
|
||||||
|
// if (column === 'referrer_domain') {
|
||||||
|
// excludeDomain = `and referrer_domain != {websiteDomain:String} and referrer_domain != ''`;
|
||||||
|
// }
|
||||||
|
|
||||||
return rawQuery(
|
return rawQuery(
|
||||||
|
// `
|
||||||
|
// select ${column} x, count(*) y
|
||||||
|
// from website_event
|
||||||
|
// where website_id = {websiteId:UUID}
|
||||||
|
// and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||||
|
// and event_type = {eventType:UInt32}
|
||||||
|
// ${excludeDomain}
|
||||||
|
// ${filterQuery}
|
||||||
|
// group by x
|
||||||
|
// order by y desc
|
||||||
|
// limit ${limit}
|
||||||
|
// offset ${offset}
|
||||||
|
// `,
|
||||||
`
|
`
|
||||||
select g.t as x,
|
select g.t as x,
|
||||||
count(*) as y
|
count(*) as y
|
||||||
|
@ -51,12 +51,29 @@ async function clickhouseQuery(
|
|||||||
const columnQuery = unit === 'minute' ? 'count(*)' : 'sum(views)';
|
const columnQuery = unit === 'minute' ? 'count(*)' : 'sum(views)';
|
||||||
|
|
||||||
return rawQuery(
|
return rawQuery(
|
||||||
|
// `
|
||||||
|
// select
|
||||||
|
// ${getDateStringSQL('g.t', unit)} as x,
|
||||||
|
// g.y as y
|
||||||
|
// from (
|
||||||
|
// select
|
||||||
|
// ${getDateSQL('created_at', unit, timezone)} as t,
|
||||||
|
// count(*) as y
|
||||||
|
// from website_event
|
||||||
|
// where website_id = {websiteId:UUID}
|
||||||
|
// and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||||
|
// and event_type = {eventType:UInt32}
|
||||||
|
// ${filterQuery}
|
||||||
|
// group by t
|
||||||
|
// ) as g
|
||||||
|
// order by t
|
||||||
|
// `,
|
||||||
`
|
`
|
||||||
select
|
select
|
||||||
${getDateStringSQL('g.t', unit)} as x,
|
${getDateStringSQL('g.t', unit)} as x,
|
||||||
g.y as y
|
g.y as y
|
||||||
from (
|
from (
|
||||||
select
|
select
|
||||||
${getDateSQL('created_at', unit, timezone)} as t,
|
${getDateSQL('created_at', unit, timezone)} as t,
|
||||||
${columnQuery} as y
|
${columnQuery} as y
|
||||||
from ${table} website_event
|
from ${table} website_event
|
||||||
|
Loading…
Reference in New Issue
Block a user