Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Entry / Exit pages filters support

Blue Mouse9dc3860e5eac
diff --git a/backend/apps/cloud/src/analytics/analytics.service.ts b/backend/apps/cloud/src/analytics/analytics.service.ts
index 787301625..5241534e8 100644
--- a/backend/apps/cloud/src/analytics/analytics.service.ts
+++ b/backend/apps/cloud/src/analytics/analytics.service.ts
@@ -943,7 +943,9 @@ export class AnalyticsService {
} else if (
!_includes(SUPPORTED_COLUMNS, column) &&
!_includes(TRAFFIC_METAKEY_COLUMNS, column) &&
- !_startsWith(column, 'tag:key:')
+ !_startsWith(column, 'tag:key:') &&
+ column !== 'entryPage' &&
+ column !== 'exitPage'
) {
return prev
}
@@ -1003,6 +1005,19 @@ export class AnalyticsService {
const param = `qf_${col}_${f}`
params[param] = filter
+ // Entry/Exit page filters (virtual columns via session scope)
+ if (column === 'entryPage' || column === 'exitPage') {
+ const pageSelector =
+ column === 'entryPage'
+ ? 'argMin(pg, created)'
+ : 'argMax(pg, created)'
+ const subQueryForPages = `SELECT psid FROM (SELECT psid, ${pageSelector} as page FROM analytics WHERE pid = {pid:FixedString(12)} GROUP BY psid) WHERE page = {${param}:String}`
+
+ // For exclusive filter (isNot) we exclude sessions with matching entry/exit page
+ query += `psid ${isExclusive ? 'NOT IN' : 'IN'} (${subQueryForPages})`
+ continue
+ }
+
// when we want to filter meta.value for a specific meta.key
if (_startsWith(column, 'ev:key:') || _startsWith(column, 'tag:key:')) {
const key = column.replace(/^ev:key:/, '').replace(/^tag:key:/, '')
@@ -1868,6 +1883,30 @@ export class AnalyticsService {
)
}
+ // Special handling for virtual columns
+ if (type === 'entryPage' || type === 'exitPage') {
+ const selector =
+ type === 'entryPage' ? 'argMin(pg, created)' : 'argMax(pg, created)'
+ const query = `
+ WITH session_pages AS (
+ SELECT psid, ${selector} as page
+ FROM analytics
+ WHERE pid = {pid:FixedString(12)}
+ GROUP BY psid
+ )
+ SELECT page FROM session_pages WHERE page IS NOT NULL GROUP BY page
+ `
+
+ const { data } = await clickhouse
+ .query({
+ query,
+ query_params: { pid },
+ })
+ .then(resultSet => resultSet.json<any>())
+
+ return _map(data, 'page')
+ }
+
let query = `SELECT ${type} FROM analytics WHERE pid={pid:FixedString(12)} AND ${type} IS NOT NULL GROUP BY ${type}`
if (type === 'ev') {
diff --git a/backend/apps/cloud/src/common/constants.ts b/backend/apps/cloud/src/common/constants.ts
index de6a23d7e..28b2b433b 100644
--- a/backend/apps/cloud/src/common/constants.ts
+++ b/backend/apps/cloud/src/common/constants.ts
@@ -116,7 +116,7 @@ const TRAFFIC_COLUMNS = [
const TRAFFIC_METAKEY_COLUMNS = ['tag:key', 'tag:value']
-const ALL_COLUMNS = [...TRAFFIC_COLUMNS, 'ev']
+const ALL_COLUMNS = [...TRAFFIC_COLUMNS, 'ev', 'entryPage', 'exitPage']
const CAPTCHA_COLUMNS = ['cc', 'br', 'os', 'dv']
const PERFORMANCE_COLUMNS = ['cc', 'rg', 'ct', 'host', 'pg', 'dv', 'br', 'brv']
const ERROR_COLUMNS = [
diff --git a/backend/apps/community/src/analytics/analytics.service.ts b/backend/apps/community/src/analytics/analytics.service.ts
index b9429a031..fc7c51e62 100644
--- a/backend/apps/community/src/analytics/analytics.service.ts
+++ b/backend/apps/community/src/analytics/analytics.service.ts
@@ -924,7 +924,9 @@ export class AnalyticsService {
} else if (
!_includes(SUPPORTED_COLUMNS, column) &&
!_includes(TRAFFIC_METAKEY_COLUMNS, column) &&
- !_startsWith(column, 'tag:key:')
+ !_startsWith(column, 'tag:key:') &&
+ column !== 'entryPage' &&
+ column !== 'exitPage'
) {
return prev
}
@@ -984,6 +986,17 @@ export class AnalyticsService {
const param = `qf_${col}_${f}`
params[param] = filter
+ // Entry/Exit page virtual filters
+ if (column === 'entryPage' || column === 'exitPage') {
+ const pageSelector =
+ column === 'entryPage'
+ ? 'argMin(pg, created)'
+ : 'argMax(pg, created)'
+ const subQueryForPages = `SELECT psid FROM (SELECT psid, ${pageSelector} as page FROM analytics WHERE pid = {pid:FixedString(12)} GROUP BY psid) WHERE page = {${param}:String}`
+ query += `psid ${isExclusive ? 'NOT IN' : 'IN'} (${subQueryForPages})`
+ continue
+ }
+
// when we want to filter meta.value for a specific meta.key
if (_startsWith(column, 'ev:key:') || _startsWith(column, 'tag:key:')) {
const key = column.replace(/^ev:key:/, '').replace(/^tag:key:/, '')
@@ -1698,6 +1711,30 @@ export class AnalyticsService {
)
}
+ // Handle virtual columns
+ if (type === 'entryPage' || type === 'exitPage') {
+ const selector =
+ type === 'entryPage' ? 'argMin(pg, created)' : 'argMax(pg, created)'
+ const query = `
+ WITH session_pages AS (
+ SELECT psid, ${selector} as page
+ FROM analytics
+ WHERE pid = {pid:FixedString(12)}
+ GROUP BY psid
+ )
+ SELECT page FROM session_pages WHERE page IS NOT NULL GROUP BY page
+ `
+
+ const { data } = await clickhouse
+ .query({
+ query,
+ query_params: { pid },
+ })
+ .then(resultSet => resultSet.json<any>())
+
+ return _map(data, 'page')
+ }
+
let query = `SELECT ${type} FROM analytics WHERE pid={pid:FixedString(12)} AND ${type} IS NOT NULL GROUP BY ${type}`
if (type === 'ev') {
diff --git a/backend/apps/community/src/common/constants.ts b/backend/apps/community/src/common/constants.ts
index e98be07ff..fdf070670 100644
--- a/backend/apps/community/src/common/constants.ts
+++ b/backend/apps/community/src/common/constants.ts
@@ -99,7 +99,7 @@ const ERROR_COLUMNS = [
'ct',
]
-const ALL_COLUMNS = [...TRAFFIC_COLUMNS, 'ev']
+const ALL_COLUMNS = [...TRAFFIC_COLUMNS, 'ev', 'entryPage', 'exitPage']
const PERFORMANCE_COLUMNS = ['cc', 'rg', 'ct', 'host', 'pg', 'dv', 'br', 'brv']
diff --git a/web/app/lib/constants/index.ts b/web/app/lib/constants/index.ts
index a984372f6..6b0cde84f 100644
--- a/web/app/lib/constants/index.ts
+++ b/web/app/lib/constants/index.ts
@@ -250,7 +250,7 @@ export const PERIOD_PAIRS_COMPARE = {
export const TRAFFIC_PANELS_ORDER = ['location', 'pg', 'devices', 'traffic-sources']
export const PERFORMANCE_PANELS_ORDER = ['location', 'pg', 'devices']
export const ERROR_PANELS_ORDER = ['location', 'pg', 'devices']
-export const FILTERS_PANELS_ORDER = ['cc', 'pg', 'br', 'os', 'ref', 'lc', 'dv']
+export const FILTERS_PANELS_ORDER = ['cc', 'pg', 'entryPage', 'exitPage', 'br', 'os', 'ref', 'lc', 'dv']
export const ERRORS_FILTERS_PANELS_ORDER = ['cc', 'pg', 'br', 'os', 'lc', 'dv']
// the maximum amount of months user can go back when picking a date in flat picker (project view)
diff --git a/web/app/pages/Project/View/ViewProject.helpers.tsx b/web/app/pages/Project/View/ViewProject.helpers.tsx
index b6411318e..1aa4e827c 100644
--- a/web/app/pages/Project/View/ViewProject.helpers.tsx
+++ b/web/app/pages/Project/View/ViewProject.helpers.tsx
@@ -1533,6 +1533,8 @@ const typeNameMapping = (t: typeof i18next.t) => ({
rg: t('project.mapping.rg'),
ct: t('project.mapping.ct'),
pg: t('project.mapping.pg'),
+ entryPage: t('project.entryPages'),
+ exitPage: t('project.exitPages'),
lc: t('project.mapping.lc'),
ref: t('project.mapping.ref'),
dv: t('project.mapping.dv'),
diff --git a/web/app/pages/Project/View/components/SearchFilters.tsx b/web/app/pages/Project/View/components/SearchFilters.tsx
index e1d2d9597..4d1e54af6 100644
--- a/web/app/pages/Project/View/components/SearchFilters.tsx
+++ b/web/app/pages/Project/View/components/SearchFilters.tsx
@@ -164,10 +164,12 @@ const SearchFilters = ({ showModal, setShowModal, tnMapping, filters, type }: Se
<Select
label={t('project.selectCategory')}
items={type === 'traffic' ? FILTERS_PANELS_ORDER : ERRORS_FILTERS_PANELS_ORDER}
- labelExtractor={(item) => t(`project.mapping.${item}`)}
+ labelExtractor={(item) => tnMapping[item] || t(`project.mapping.${item}`)}
onSelect={(item) => setFilterType(item)}
title={
- _isEmpty(filterType) ? t('project.settings.reseted.selectFilters') : t(`project.mapping.${filterType}`)
+ _isEmpty(filterType)
+ ? t('project.settings.reseted.selectFilters')
+ : tnMapping[filterType] || t(`project.mapping.${filterType}`)
}
/>
{!_isEmpty(filters) ? (
diff --git a/web/app/pages/Project/View/utils/filters.tsx b/web/app/pages/Project/View/utils/filters.tsx
index beab3fa75..2b8b47534 100644
--- a/web/app/pages/Project/View/utils/filters.tsx
+++ b/web/app/pages/Project/View/utils/filters.tsx
@@ -21,6 +21,8 @@ const validFilters = [
'rg',
'ct',
'pg',
+ 'entryPage',
+ 'exitPage',
'lc',
'ref',
'dv',