📈 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!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
Fix pg.indexOf analytics error
Blue Mouse304675aa25fb
diff --git a/backend/apps/cloud/src/analytics/dto/events.dto.ts b/backend/apps/cloud/src/analytics/dto/events.dto.tsindex 9d17a5547..e1b1d03ba 100644--- a/backend/apps/cloud/src/analytics/dto/events.dto.ts+++ b/backend/apps/cloud/src/analytics/dto/events.dto.ts@@ -127,6 +127,8 @@ export class EventsDto {example: '/articles/my-awesome-article-1',description: 'A page that user sent data from',})+ @IsOptional()+ @IsString()pg?: string@ApiProperty({diff --git a/backend/apps/cloud/src/analytics/dto/pageviews.dto.ts b/backend/apps/cloud/src/analytics/dto/pageviews.dto.tsindex c4031b947..e63d1afc4 100644--- a/backend/apps/cloud/src/analytics/dto/pageviews.dto.ts+++ b/backend/apps/cloud/src/analytics/dto/pageviews.dto.ts@@ -52,6 +52,8 @@ export class PageviewsDto {example: '/articles/my-awesome-article-1',description: 'A page that user sent data from',})+ @IsOptional()+ @IsString()pg?: string@ApiProperty({diff --git a/backend/apps/cloud/src/analytics/utils/clickIdSources.ts b/backend/apps/cloud/src/analytics/utils/clickIdSources.tsindex bcbf7dc86..ad398d7f5 100644--- a/backend/apps/cloud/src/analytics/utils/clickIdSources.ts+++ b/backend/apps/cloud/src/analytics/utils/clickIdSources.ts@@ -122,8 +122,8 @@ const CLICK_ID_KEYS = Object.keys(CLICK_ID_MAP)* `#hash` fragment stripped. This is a fallback for tracker versions* that don't yet send the dedicated `qs` field.*/-const extractSearchFromPg = (pg: string | null | undefined): string => {- if (!pg) return ''+const extractSearchFromPg = (pg: unknown): string => {+ if (typeof pg !== 'string' || !pg) return ''const qIdx = pg.indexOf('?')if (qIdx === -1) return ''let search = pg.slice(qIdx + 1)@@ -137,8 +137,8 @@ const extractSearchFromPg = (pg: string | null | undefined): string => {* accept it with or without a leading `?` and strip a trailing* `#hash` defensively.*/-const normaliseQs = (qs: string | null | undefined): string => {- if (!qs) return ''+const normaliseQs = (qs: unknown): string => {+ if (typeof qs !== 'string' || !qs) return ''let result = qs.startsWith('?') ? qs.slice(1) : qsconst hashIdx = result.indexOf('#')if (hashIdx !== -1) result = result.slice(0, hashIdx)diff --git a/backend/apps/community/src/analytics/dto/events.dto.ts b/backend/apps/community/src/analytics/dto/events.dto.tsindex 9d17a5547..e1b1d03ba 100644--- a/backend/apps/community/src/analytics/dto/events.dto.ts+++ b/backend/apps/community/src/analytics/dto/events.dto.ts@@ -127,6 +127,8 @@ export class EventsDto {example: '/articles/my-awesome-article-1',description: 'A page that user sent data from',})+ @IsOptional()+ @IsString()pg?: string@ApiProperty({diff --git a/backend/apps/community/src/analytics/dto/pageviews.dto.ts b/backend/apps/community/src/analytics/dto/pageviews.dto.tsindex c4031b947..e63d1afc4 100644--- a/backend/apps/community/src/analytics/dto/pageviews.dto.ts+++ b/backend/apps/community/src/analytics/dto/pageviews.dto.ts@@ -52,6 +52,8 @@ export class PageviewsDto {example: '/articles/my-awesome-article-1',description: 'A page that user sent data from',})+ @IsOptional()+ @IsString()pg?: string@ApiProperty({diff --git a/backend/apps/community/src/analytics/utils/clickIdSources.ts b/backend/apps/community/src/analytics/utils/clickIdSources.tsindex 6e1345400..3eaf48a2c 100644--- a/backend/apps/community/src/analytics/utils/clickIdSources.ts+++ b/backend/apps/community/src/analytics/utils/clickIdSources.ts@@ -122,8 +122,8 @@ const CLICK_ID_KEYS = Object.keys(CLICK_ID_MAP)* `#hash` fragment stripped. This is a fallback for tracker versions* that don't yet send the dedicated `qs` field.*/-const extractSearchFromPg = (pg: string | null | undefined): string => {- if (!pg) return ''+const extractSearchFromPg = (pg: unknown): string => {+ if (typeof pg !== 'string' || !pg) return ''const qIdx = pg.indexOf('?')if (qIdx === -1) return ''let search = pg.slice(qIdx + 1)@@ -137,8 +137,8 @@ const extractSearchFromPg = (pg: string | null | undefined): string => {* accept it with or without a leading `?` and strip a trailing* `#hash` defensively.*/-const normaliseQs = (qs: string | null | undefined): string => {- if (!qs) return ''+const normaliseQs = (qs: unknown): string => {+ if (typeof qs !== 'string' || !qs) return ''let result = qs.startsWith('?') ? qs.slice(1) : qsconst hashIdx = result.indexOf('#')if (hashIdx !== -1) result = result.slice(0, hashIdx)