Skip to content

Commit

Permalink
(selfhosted) fix: funnel filters does not work for custom events
Browse files Browse the repository at this point in the history
  • Loading branch information
Blaumaus committed Jun 9, 2024
1 parent b9ca71b commit 4d8df69
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 9 additions & 2 deletions apps/selfhosted/src/analytics/analytics.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
ERROR_COLUMNS,
MIN_PAGES_IN_FUNNEL,
MAX_PAGES_IN_FUNNEL,
ALL_COLUMNS,
} from '../common/constants'
import {
getFunnelsClickhouse,
Expand Down Expand Up @@ -1552,13 +1553,19 @@ export class AnalyticsService {
}

async getFilters(pid: string, type: string): Promise<Array<string>> {
if (!_includes(TRAFFIC_COLUMNS, type)) {
if (!_includes(ALL_COLUMNS, type)) {
throw new UnprocessableEntityException(
`The provided type (${type}) is incorrect`,
)
}

const query = `SELECT ${type} FROM analytics WHERE pid={pid:FixedString(12)} AND ${type} IS NOT NULL GROUP BY ${type}`
let query = `SELECT ${type} FROM analytics WHERE pid={pid:FixedString(12)} AND ${type} IS NOT NULL GROUP BY ${type}`

if (type === 'ev') {
query =
'SELECT ev FROM customEV WHERE pid={pid:FixedString(12)} AND ev IS NOT NULL GROUP BY ev'
}

const results = await clickhouse
.query(query, { params: { pid } })
.toPromise()
Expand Down
3 changes: 3 additions & 0 deletions apps/selfhosted/src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ const TRAFFIC_COLUMNS = [
'ca',
]

const ALL_COLUMNS = [...TRAFFIC_COLUMNS, 'ev']

const PERFORMANCE_COLUMNS = ['cc', 'rg', 'ct', 'pg', 'dv', 'br']
const ERROR_COLUMNS = ['pg', 'dv', 'br', 'os', 'lc', 'cc', 'rg', 'ct']

Expand Down Expand Up @@ -152,4 +154,5 @@ export {
ERROR_COLUMNS,
REDIS_LOG_ERROR_CACHE_KEY,
PID_REGEX,
ALL_COLUMNS,
}

0 comments on commit 4d8df69

Please sign in to comment.