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!

fix: Filter dimensions validation fixes

Blue Mouse7f8e94453f38
diff --git a/backend/apps/cloud/src/common/constants.ts b/backend/apps/cloud/src/common/constants.ts
index 5ec7dd2e6..4eeeafd9c 100644
--- a/backend/apps/cloud/src/common/constants.ts
+++ b/backend/apps/cloud/src/common/constants.ts
@@ -137,6 +137,10 @@ const V2_VIEW_FILTER_DIMENSIONS = [
'entry_page',
'exit_page',
'event',
+ // errors-only filter dimensions (error-tab segments persist these)
+ 'error_name',
+ 'error_message',
+ 'error_filename',
'event_metadata',
'page_property',
]
diff --git a/backend/apps/cloud/src/project/dto/create-project-view.dto.ts b/backend/apps/cloud/src/project/dto/create-project-view.dto.ts
index 893992d8f..b0cb42e48 100644
--- a/backend/apps/cloud/src/project/dto/create-project-view.dto.ts
+++ b/backend/apps/cloud/src/project/dto/create-project-view.dto.ts
@@ -1,5 +1,6 @@
import {
ArrayMaxSize,
+ IsArray,
IsEnum,
IsNotEmpty,
IsOptional,
@@ -58,6 +59,10 @@ export interface Filter {
export const MAX_METRICS_IN_VIEW = 3
+// Mirrors MAX_FILTERS in analytics.service β€” the cap applied when filters run
+// against ClickHouse, so a saved view can never hold more than a query accepts.
+export const MAX_FILTERS_IN_VIEW = 100
+
export class CreateProjectViewDto {
@ApiProperty()
@MaxLength(20)
@@ -78,6 +83,8 @@ export class CreateProjectViewDto {
isArray: true,
})
@IsOptional()
+ @IsArray()
+ @ArrayMaxSize(MAX_FILTERS_IN_VIEW)
filters?: Filter[]
@ApiProperty({
diff --git a/backend/apps/community/src/analytics/v2/__tests__/registry.spec.ts b/backend/apps/community/src/analytics/v2/__tests__/registry.spec.ts
index 7194022d3..dc5e5ff27 100644
--- a/backend/apps/community/src/analytics/v2/__tests__/registry.spec.ts
+++ b/backend/apps/community/src/analytics/v2/__tests__/registry.spec.ts
@@ -7,6 +7,7 @@ import {
listDimensions,
parseMetricsParam,
V2_DIMENSIONS,
+ V2_KEYED_FILTER_DIMENSIONS,
} from '../registry'
// Keep the registry in lockstep with the v1 filter column allowlists
@@ -17,6 +18,7 @@ const {
PERFORMANCE_COLUMNS,
ERROR_COLUMNS,
CAPTCHA_COLUMNS,
+ V2_VIEW_FILTER_DIMENSIONS,
// eslint-disable-next-line @typescript-eslint/no-require-imports
} = require('../../../common/constants')
@@ -51,6 +53,22 @@ describe('registry <-> v1 column allowlist lockstep', () => {
})
})
+describe('V2_VIEW_FILTER_DIMENSIONS <-> registry parity', () => {
+ // Saved-view filters (project.service.filterUnsupportedColumns) span traffic,
+ // performance and errors data β€” every such dimension the UI can offer must be
+ // preserved, and no captcha-only or stale name may leak into the allowlist.
+ const expected = [
+ ...V2_DIMENSIONS.filter((dimension) =>
+ dimension.types.some((type) => type !== 'captcha'),
+ ).map((dimension) => dimension.api),
+ ...Object.keys(V2_KEYED_FILTER_DIMENSIONS),
+ ]
+
+ it('matches every non-captcha registry dimension exactly', () => {
+ expect([...V2_VIEW_FILTER_DIMENSIONS].sort()).toEqual([...expected].sort())
+ })
+})
+
describe('dimension lookups', () => {
it('resolves valid breakdown dimensions', () => {
expect(getBreakdownDimension('country', 'traffic').column).toBe('cc')
diff --git a/backend/apps/community/src/common/constants.ts b/backend/apps/community/src/common/constants.ts
index 50a635e52..fc04ac187 100644
--- a/backend/apps/community/src/common/constants.ts
+++ b/backend/apps/community/src/common/constants.ts
@@ -163,6 +163,10 @@ const V2_VIEW_FILTER_DIMENSIONS = [
'entry_page',
'exit_page',
'event',
+ // errors-only filter dimensions (error-tab segments persist these)
+ 'error_name',
+ 'error_message',
+ 'error_filename',
'event_metadata',
'page_property',
]
diff --git a/backend/apps/community/src/project/dto/create-project-view.dto.ts b/backend/apps/community/src/project/dto/create-project-view.dto.ts
index 893992d8f..b0cb42e48 100644
--- a/backend/apps/community/src/project/dto/create-project-view.dto.ts
+++ b/backend/apps/community/src/project/dto/create-project-view.dto.ts
@@ -1,5 +1,6 @@
import {
ArrayMaxSize,
+ IsArray,
IsEnum,
IsNotEmpty,
IsOptional,
@@ -58,6 +59,10 @@ export interface Filter {
export const MAX_METRICS_IN_VIEW = 3
+// Mirrors MAX_FILTERS in analytics.service β€” the cap applied when filters run
+// against ClickHouse, so a saved view can never hold more than a query accepts.
+export const MAX_FILTERS_IN_VIEW = 100
+
export class CreateProjectViewDto {
@ApiProperty()
@MaxLength(20)
@@ -78,6 +83,8 @@ export class CreateProjectViewDto {
isArray: true,
})
@IsOptional()
+ @IsArray()
+ @ArrayMaxSize(MAX_FILTERS_IN_VIEW)
filters?: Filter[]
@ApiProperty({
diff --git a/web/app/routes/projects.$id.tsx b/web/app/routes/projects.$id.tsx
index 521980141..918c16442 100644
--- a/web/app/routes/projects.$id.tsx
+++ b/web/app/routes/projects.$id.tsx
@@ -45,7 +45,19 @@ import {
const GOAL_CONDITION_RELATIONS = new Set(['AND', 'OR'])
const GOAL_CONDITION_COMMON_FIELDS = [
+ // v2 dimension names written by the goal settings modal after the v2 migration
'host',
+ 'country',
+ 'device',
+ 'browser',
+ 'os',
+ 'referrer',
+ 'utm_source',
+ 'utm_medium',
+ 'utm_campaign',
+ 'utm_term',
+ 'utm_content',
+ // legacy v1 short codes (older goals / preserved unmapped conditions)
'ref',
'so',
'me',
@@ -55,7 +67,6 @@ const GOAL_CONDITION_COMMON_FIELDS = [
'cc',
'dv',
'br',
- 'os',
]
const GOAL_CONDITION_EVENT_TYPES: Record<string, Set<string>> = {
any: new Set([