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!

remove unused code

Blue Mouse03ff4564b3e2
diff --git a/backend/.env.example b/backend/.env.example
index fb06c8629..b69ee6bd6 100644
--- a/backend/.env.example
+++ b/backend/.env.example
@@ -55,9 +55,6 @@ OIDC_CLIENT_SECRET=
CDN_URL=http://localhost:5006
CDN_ACCESS_TOKEN=SOME_SECRET_TOKEN
-# Captcha API
-CAPTCHA_SALT=
-
# Google SSO
GOOGLE_OAUTH2_CLIENT_ID=
GOOGLE_OAUTH2_CLIENT_SECRET=
diff --git a/backend/apps/cloud/src/captcha/captcha.service.ts b/backend/apps/cloud/src/captcha/captcha.service.ts
index 4fb8c054d..da97807cd 100644
--- a/backend/apps/cloud/src/captcha/captcha.service.ts
+++ b/backend/apps/cloud/src/captcha/captcha.service.ts
@@ -23,7 +23,7 @@ import { clickhouse } from '../common/integrations/clickhouse'
dayjs.extend(utc)
// Default difficulty: number of leading hex zeros required (4 = ~65k iterations avg)
-export const DEFAULT_POW_DIFFICULTY = 4
+const DEFAULT_POW_DIFFICULTY = 4
// Challenge TTL in seconds (5 minutes)
const CHALLENGE_TTL = 300
diff --git a/backend/apps/cloud/src/common/constants.ts b/backend/apps/cloud/src/common/constants.ts
index 92591ba8a..900727070 100644
--- a/backend/apps/cloud/src/common/constants.ts
+++ b/backend/apps/cloud/src/common/constants.ts
@@ -51,9 +51,6 @@ const REDIS_PROJECTS_COUNT_KEY = 'stats:projects_count'
const REDIS_EVENTS_COUNT_KEY = 'stats:events'
const REDIS_SSO_UUID = 'sso:uuid'
-// Captcha service
-const { CAPTCHA_SALT } = process.env
-
// 3600 sec -> 1 hour
const redisProjectCacheTimeout = 3600
@@ -183,7 +180,6 @@ export {
TWO_FACTOR_AUTHENTICATION_APP_NAME,
IP_REGEX,
ORIGINS_REGEX,
- CAPTCHA_SALT,
EMAIL_ACTION_ENCRYPTION_KEY,
isDevelopment,
getRedisCaptchaKey,
diff --git a/backend/apps/cloud/src/goal/goal.controller.ts b/backend/apps/cloud/src/goal/goal.controller.ts
index 2c8184da3..17506f690 100644
--- a/backend/apps/cloud/src/goal/goal.controller.ts
+++ b/backend/apps/cloud/src/goal/goal.controller.ts
@@ -673,106 +673,4 @@ export class GoalController {
},
}
}
-
- @ApiBearerAuth()
- @Get('/:id/sessions')
- @Auth()
- async getGoalSessions(
- @CurrentUserId() userId: string,
- @Param('id') id: string,
- @Query('period') period: string,
- @Query('from') from?: string,
- @Query('to') to?: string,
- @Query('take', new ParseIntPipe({ optional: true })) take: number = 30,
- @Query('skip', new ParseIntPipe({ optional: true })) skip: number = 0,
- @Query('timezone') timezone?: string,
- ) {
- this.logger.log(
- { userId, id, period, from, to, take, skip },
- 'GET /goal/:id/sessions',
- )
-
- const goal = await this.goalService.findOneWithRelations(id)
-
- if (_isEmpty(goal)) {
- throw new NotFoundException('Goal not found')
- }
-
- const project = await this.projectService.getFullProject(goal.project.id)
- this.projectService.allowedToView(project, userId)
-
- const safeTimezone = this.analyticsService.getSafeTimezone(timezone)
- const timeBucket = getLowestPossibleTimeBucket(period, from, to)
-
- const { groupFromUTC, groupToUTC } = this.analyticsService.getGroupFromTo(
- from,
- to,
- timeBucket,
- period,
- safeTimezone,
- )
-
- const table = goal.type === GoalType.CUSTOM_EVENT ? 'customEV' : 'analytics'
-
- const { condition: matchCondition, params: matchParams } =
- this.buildGoalMatchCondition(goal, table)
- const { condition: metaCondition, params: metaParams } =
- this.buildMetadataCondition(goal)
-
- const sessionsQuery = `
- SELECT
- DISTINCT psid,
- any(cc) as country,
- any(br) as browser,
- any(os) as os,
- any(dv) as device,
- min(created) as firstConversion,
- count(*) as conversionCount
- FROM ${table}
- WHERE
- pid = {pid:FixedString(12)}
- AND ${matchCondition}
- ${metaCondition}
- AND created BETWEEN {groupFrom:String} AND {groupTo:String}
- AND psid IS NOT NULL
- GROUP BY psid
- ORDER BY firstConversion DESC
- LIMIT {take:UInt32} OFFSET {skip:UInt32}
- `
-
- const countQuery = `
- SELECT count(DISTINCT psid) as total
- FROM ${table}
- WHERE
- pid = {pid:FixedString(12)}
- AND ${matchCondition}
- ${metaCondition}
- AND created BETWEEN {groupFrom:String} AND {groupTo:String}
- AND psid IS NOT NULL
- `
-
- const queryParams = {
- pid: goal.project.id,
- groupFrom: groupFromUTC,
- groupTo: groupToUTC,
- take,
- skip,
- ...matchParams,
- ...metaParams,
- }
-
- const [sessionsResult, countResult] = await Promise.all([
- clickhouse
- .query({ query: sessionsQuery, query_params: queryParams })
- .then(resultSet => resultSet.json<any>()),
- clickhouse
- .query({ query: countQuery, query_params: queryParams })
- .then(resultSet => resultSet.json<{ total: number }>()),
- ])
-
- return {
- sessions: sessionsResult.data,
- total: countResult.data[0]?.total || 0,
- }
- }
}
diff --git a/backend/apps/cloud/src/goal/goal.service.ts b/backend/apps/cloud/src/goal/goal.service.ts
index 7490c562b..4a95c3d15 100644
--- a/backend/apps/cloud/src/goal/goal.service.ts
+++ b/backend/apps/cloud/src/goal/goal.service.ts
@@ -3,7 +3,6 @@ import { InjectRepository } from '@nestjs/typeorm'
import { FindManyOptions, FindOneOptions, Repository } from 'typeorm'
import { Pagination, PaginationOptionsInterface } from '../common/pagination'
import { Goal } from './entity/goal.entity'
-import { CreateGoalDto, UpdateGoalDto } from './dto/goal.dto'
@Injectable()
export class GoalService {
diff --git a/backend/apps/community/src/goal/dto/goal.dto.ts b/backend/apps/community/src/goal/dto/goal.dto.ts
index d5d0c66be..2e0725b7f 100644
--- a/backend/apps/community/src/goal/dto/goal.dto.ts
+++ b/backend/apps/community/src/goal/dto/goal.dto.ts
@@ -86,23 +86,3 @@ export class UpdateGoalDto {
@IsOptional()
active?: boolean
}
-
-export class GoalDto {
- id: string
- name: string
- type: GoalType
- matchType: GoalMatchType
- value: string | null
- metadataFilters: MetadataFilterDto[] | null
- active: boolean
- pid: string
- created: string
-}
-
-export class GoalStatsDto {
- conversions: number
- uniqueSessions: number
- conversionRate: number
- previousConversions: number
- trend: number
-}
diff --git a/backend/apps/community/src/goal/goal.controller.ts b/backend/apps/community/src/goal/goal.controller.ts
index 23e3e6834..3dfdd556c 100644
--- a/backend/apps/community/src/goal/goal.controller.ts
+++ b/backend/apps/community/src/goal/goal.controller.ts
@@ -29,12 +29,7 @@ import {
import { Auth } from '../auth/decorators'
import { CurrentUserId } from '../auth/decorators/current-user-id.decorator'
import { Goal, GoalType, GoalMatchType } from './entity/goal.entity'
-import {
- CreateGoalDto,
- UpdateGoalDto,
- GoalDto,
- GoalStatsDto,
-} from './dto/goal.dto'
+import { CreateGoalDto, UpdateGoalDto } from './dto/goal.dto'
import { GoalService } from './goal.service'
import { clickhouse } from '../common/integrations/clickhouse'
@@ -619,105 +614,4 @@ export class GoalController {
},
}
}
-
- @Get('/:id/sessions')
- @Auth()
- async getGoalSessions(
- @CurrentUserId() userId: string,
- @Param('id') id: string,
- @Query('period') period: string,
- @Query('from') from?: string,
- @Query('to') to?: string,
- @Query('take', new ParseIntPipe({ optional: true })) take: number = 30,
- @Query('skip', new ParseIntPipe({ optional: true })) skip: number = 0,
- @Query('timezone') timezone?: string,
- ) {
- this.logger.log(
- { userId, id, period, from, to, take, skip },
- 'GET /goal/:id/sessions',
- )
-
- const goal = await this.goalService.findOne(id)
-
- if (_isEmpty(goal)) {
- throw new NotFoundException('Goal not found')
- }
-
- const project = await this.projectService.getFullProject(goal.projectId)
- this.projectService.allowedToView(project, userId)
-
- const safeTimezone = this.analyticsService.getSafeTimezone(timezone)
- const timeBucket = getLowestPossibleTimeBucket(period, from, to)
-
- const { groupFromUTC, groupToUTC } = this.analyticsService.getGroupFromTo(
- from,
- to,
- timeBucket,
- period,
- safeTimezone,
- )
-
- const table = goal.type === GoalType.CUSTOM_EVENT ? 'customEV' : 'analytics'
-
- const { condition: matchCondition, params: matchParams } =
- this.buildGoalMatchCondition(goal, table)
- const { condition: metaCondition, params: metaParams } =
- this.buildMetadataCondition(goal)
-
- const sessionsQuery = `
- SELECT
- DISTINCT psid,
- any(cc) as country,
- any(br) as browser,
- any(os) as os,
- any(dv) as device,
- min(created) as firstConversion,
- count(*) as conversionCount
- FROM ${table}
- WHERE
- pid = {pid:FixedString(12)}
- AND ${matchCondition}
- ${metaCondition}
- AND created BETWEEN {groupFrom:String} AND {groupTo:String}
- AND psid IS NOT NULL
- GROUP BY psid
- ORDER BY firstConversion DESC
- LIMIT {take:UInt32} OFFSET {skip:UInt32}
- `
-
- const countQuery = `
- SELECT count(DISTINCT psid) as total
- FROM ${table}
- WHERE
- pid = {pid:FixedString(12)}
- AND ${matchCondition}
- ${metaCondition}
- AND created BETWEEN {groupFrom:String} AND {groupTo:String}
- AND psid IS NOT NULL
- `
-
- const queryParams = {
- pid: goal.projectId,
- groupFrom: groupFromUTC,
- groupTo: groupToUTC,
- take,
- skip,
- ...matchParams,
- ...metaParams,
- }
-
- const [sessionsResult, countResult] = await Promise.all([
- clickhouse
- .query({ query: sessionsQuery, query_params: queryParams })
- .then(resultSet => resultSet.json<any>()),
- clickhouse
- .query({ query: countQuery, query_params: queryParams })
- .then(resultSet => resultSet.json<{ total: number }>()),
- ])
-
- return {
- sessions: sessionsResult.data,
- total: countResult.data[0]?.total || 0,
- }
- }
}
diff --git a/backend/apps/community/src/goal/goal.service.ts b/backend/apps/community/src/goal/goal.service.ts
index c127e2744..5dd1250b3 100644
--- a/backend/apps/community/src/goal/goal.service.ts
+++ b/backend/apps/community/src/goal/goal.service.ts
@@ -1,4 +1,4 @@
-import { Injectable, NotFoundException } from '@nestjs/common'
+import { Injectable } from '@nestjs/common'
import { randomUUID } from 'crypto'
import dayjs from 'dayjs'
import utc from 'dayjs/plugin/utc'
@@ -16,7 +16,7 @@ import {
GoalMatchType,
MetadataFilter,
} from './entity/goal.entity'
-import { Pagination } from '../common/pagination'
+import { Pagination } from '../common/pagination/pagination'
import { PaginationOptionsInterface } from '../common/pagination/pagination.results.interface'
dayjs.extend(utc)
diff --git a/backend/package-lock.json b/backend/package-lock.json
index 1f7b14a82..dab123577 100644
--- a/backend/package-lock.json
+++ b/backend/package-lock.json
@@ -66,7 +66,6 @@
"rimraf": "^6.1.2",
"rxjs": "^7.8.2",
"sns-payload-validator": "^2.1.0",
- "svg-captcha": "^1.4.0",
"telegraf": "^4.16.3",
"typeorm": "^0.3.27",
"validator": "^13.15.23"
@@ -12034,18 +12033,6 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
- "node_modules/opentype.js": {
- "version": "0.7.3",
- "resolved": "https://registry.npmjs.org/opentype.js/-/opentype.js-0.7.3.tgz",
- "integrity": "sha512-Veui5vl2bLonFJ/SjX/WRWJT3SncgiZNnKUyahmXCc2sa1xXW15u3R/3TN5+JFiP7RsjK5ER4HA5eWaEmV9deA==",
- "license": "MIT",
- "dependencies": {
- "tiny-inflate": "^1.0.2"
- },
- "bin": {
- "ot": "bin/ot"
- }
- },
"node_modules/optionator": {
"version": "0.9.4",
"resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz",
@@ -14219,18 +14206,6 @@
"url": "https://github.com/sponsors/ljharb"
}
},
- "node_modules/svg-captcha": {
- "version": "1.4.0",
- "resolved": "https://registry.npmjs.org/svg-captcha/-/svg-captcha-1.4.0.tgz",
- "integrity": "sha512-/fkkhavXPE57zRRCjNqAP3txRCSncpMx3NnNZL7iEoyAtYwUjPhJxW6FQTQPG5UPEmCrbFoXS10C3YdJlW7PDg==",
- "license": "MIT",
- "dependencies": {
- "opentype.js": "^0.7.3"
- },
- "engines": {
- "node": ">=4.x"
- }
- },
"node_modules/swagger-ui-dist": {
"version": "5.30.2",
"resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-5.30.2.tgz",
@@ -14452,12 +14427,6 @@
"node": ">=0.2.6"
}
},
- "node_modules/tiny-inflate": {
- "version": "1.0.3",
- "resolved": "https://registry.npmjs.org/tiny-inflate/-/tiny-inflate-1.0.3.tgz",
- "integrity": "sha512-pkY1fj1cKHb2seWDy0B16HeWyczlJA9/WW3u3c4z/NiWDsO3DOU5D7nhTLE9CF0yXv/QZFY7sEJmj24dK+Rrqw==",
- "license": "MIT"
- },
"node_modules/tiny-lru": {
"version": "11.4.5",
"resolved": "https://registry.npmjs.org/tiny-lru/-/tiny-lru-11.4.5.tgz",
diff --git a/backend/package.json b/backend/package.json
index 0717f18fe..4ec4beeb1 100644
--- a/backend/package.json
+++ b/backend/package.json
@@ -86,7 +86,6 @@
"rimraf": "^6.1.2",
"rxjs": "^7.8.2",
"sns-payload-validator": "^2.1.0",
- "svg-captcha": "^1.4.0",
"telegraf": "^4.16.3",
"typeorm": "^0.3.27",
"validator": "^13.15.23"
diff --git a/web/app/api/index.ts b/web/app/api/index.ts
index 880685ccb..1b8149209 100644
--- a/web/app/api/index.ts
+++ b/web/app/api/index.ts
@@ -1161,16 +1161,6 @@ export interface GoalChartData {
uniqueSessions: number[]
}
-export interface GoalSession {
- psid: string
- country: string | null
- browser: string | null
- os: string | null
- device: string | null
- firstConversion: string
- conversionCount: number
-}
-
export const DEFAULT_GOALS_TAKE = 20
export const getProjectGoals = (projectId: string, take: number = DEFAULT_GOALS_TAKE, skip = 0) =>
@@ -1256,31 +1246,6 @@ export const getGoalChart = (
throw _isEmpty(error.response.data?.message) ? error.response.data : error.response.data.message
})
-export const getGoalSessions = (
- goalId: string,
- period: string,
- from: string = '',
- to: string = '',
- take: number = 30,
- skip: number = 0,
- timezone?: string,
-) =>
- api
- .get(`/goal/${goalId}/sessions`, {
- params: { period, from, to, take, skip, timezone },
- })
- .then(
- (
- response,
- ): {
- sessions: GoalSession[]
- total: number
- } => response.data,
- )
- .catch((error) => {
- throw _isEmpty(error.response.data?.message) ? error.response.data : error.response.data.message
- })
-
export const reGenerateCaptchaSecretKey = (pid: string) =>
api
.post(`project/secret-gen/${pid}`)
diff --git a/web/app/lib/models/Goal.ts b/web/app/lib/models/Goal.ts
deleted file mode 100644
index 01cd4f653..000000000
--- a/web/app/lib/models/Goal.ts
+++ /dev/null
@@ -1,53 +0,0 @@
-export type GoalType = 'pageview' | 'custom_event'
-export type GoalMatchType = 'exact' | 'contains'
-
-export interface MetadataFilter {
- key: string
- value: string
-}
-
-export interface Goal {
- id: string
- name: string
- type: GoalType
- matchType: GoalMatchType
- value: string | null
- metadataFilters: MetadataFilter[] | null
- active: boolean
- pid: string
- created: string
-}
-
-export interface GoalStats {
- conversions: number
- uniqueSessions: number
- conversionRate: number
- previousConversions: number
- trend: number
-}
-
-export interface GoalChartData {
- time: string
- conversions: number
- uniqueSessions: number
-}
-
-export interface GoalSession {
- psid: string
- country: string | null
- browser: string | null
- os: string | null
- device: string | null
- firstConversion: string
- conversionCount: number
-}
-
-export const GOAL_TYPE_LABELS: Record<GoalType, string> = {
- pageview: 'Pageview',
- custom_event: 'Custom Event',
-}
-
-export const GOAL_MATCH_TYPE_LABELS: Record<GoalMatchType, string> = {
- exact: 'Exact match',
- contains: 'Contains',
-}
diff --git a/web/app/pages/Project/Goals/View/GoalSettingsModal.tsx b/web/app/pages/Project/Goals/View/GoalSettingsModal.tsx
index e6fe64a15..5585b5170 100644
--- a/web/app/pages/Project/Goals/View/GoalSettingsModal.tsx
+++ b/web/app/pages/Project/Goals/View/GoalSettingsModal.tsx
@@ -6,7 +6,7 @@ import { useState, useEffect } from 'react'
import { useTranslation } from 'react-i18next'
import { toast } from 'sonner'
-import { getGoal, createGoal, updateGoal, type CreateGoal, type Goal } from '~/api'
+import { getGoal, createGoal, updateGoal, type CreateGoal } from '~/api'
import Button from '~/ui/Button'
import Input from '~/ui/Input'
import Loader from '~/ui/Loader'