Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
124 changes: 58 additions & 66 deletions backend/apps/cloud/src/analytics/analytics.service.ts

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions backend/apps/cloud/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { WebhookModule } from './webhook/webhook.module'
import { PingModule } from './ping/ping.module'
import { MarketplaceModule } from './marketplace/marketplace.module'
import { AlertModule } from './alert/alert.module'
import { GoalModule } from './goal/goal.module'
import { getI18nConfig } from './configs'
import { AuthModule } from './auth/auth.module'
import { CaptchaModule } from './captcha/captcha.module'
Expand Down Expand Up @@ -77,6 +78,7 @@ const modules = [
PingModule,
MarketplaceModule,
AlertModule,
GoalModule,
AuthModule,
CaptchaModule,
OgImageModule,
Expand Down
2 changes: 1 addition & 1 deletion backend/apps/cloud/src/captcha/captcha.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions backend/apps/cloud/src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -183,7 +180,6 @@ export {
TWO_FACTOR_AUTHENTICATION_APP_NAME,
IP_REGEX,
ORIGINS_REGEX,
CAPTCHA_SALT,
EMAIL_ACTION_ENCRYPTION_KEY,
isDevelopment,
getRedisCaptchaKey,
Expand Down
161 changes: 161 additions & 0 deletions backend/apps/cloud/src/goal/dto/goal.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'
import {
IsString,
IsEnum,
IsOptional,
IsArray,
ValidateNested,
MaxLength,
IsBoolean,
IsNotEmpty,
IsIn,
} from 'class-validator'
import { Type } from 'class-transformer'
import { GoalType, GoalMatchType, MetadataFilter } from '../entity/goal.entity'

// Allowed match types for API (regex is disabled for now)
const ALLOWED_MATCH_TYPES = [GoalMatchType.EXACT, GoalMatchType.CONTAINS]

export class MetadataFilterDto implements MetadataFilter {
@ApiProperty()
@IsString()
@IsNotEmpty()
key: string

@ApiProperty()
@IsString()
@IsNotEmpty()
value: string
}

export class CreateGoalDto {
@ApiProperty({ description: 'Project ID' })
@IsString()
@IsNotEmpty()
pid: string

@ApiProperty({ description: 'Goal name' })
@IsString()
@MaxLength(100)
@IsNotEmpty()
name: string

@ApiProperty({ enum: GoalType, description: 'Type of goal' })
@IsEnum(GoalType)
type: GoalType

@ApiProperty({
enum: [GoalMatchType.EXACT, GoalMatchType.CONTAINS],
description: 'How to match the value',
})
@IsIn(ALLOWED_MATCH_TYPES, {
message: 'matchType must be either "exact" or "contains"',
})
matchType: GoalMatchType

@ApiPropertyOptional({ description: 'Page path or event name to match' })
@IsString()
@MaxLength(500)
@IsOptional()
value?: string

@ApiPropertyOptional({
type: [MetadataFilterDto],
description: 'Optional metadata filters',
})
@IsArray()
@ValidateNested({ each: true })
@Type(() => MetadataFilterDto)
@IsOptional()
metadataFilters?: MetadataFilterDto[]
}

export class UpdateGoalDto {
@ApiPropertyOptional({ description: 'Goal name' })
@IsString()
@MaxLength(100)
@IsOptional()
name?: string

@ApiPropertyOptional({ enum: GoalType, description: 'Type of goal' })
@IsEnum(GoalType)
@IsOptional()
type?: GoalType

@ApiPropertyOptional({
enum: [GoalMatchType.EXACT, GoalMatchType.CONTAINS],
description: 'How to match the value',
})
@IsIn(ALLOWED_MATCH_TYPES, {
message: 'matchType must be either "exact" or "contains"',
})
@IsOptional()
matchType?: GoalMatchType

@ApiPropertyOptional({ description: 'Page path or event name to match' })
@IsString()
@MaxLength(500)
@IsOptional()
value?: string

@ApiPropertyOptional({
type: [MetadataFilterDto],
description: 'Optional metadata filters',
})
@IsArray()
@ValidateNested({ each: true })
@Type(() => MetadataFilterDto)
@IsOptional()
metadataFilters?: MetadataFilterDto[]

@ApiPropertyOptional({ description: 'Whether the goal is active' })
@IsBoolean()
@IsOptional()
active?: boolean
}

export class GoalDto {
@ApiProperty()
id: string

@ApiProperty()
name: string

@ApiProperty({ enum: GoalType })
type: GoalType

@ApiProperty({ enum: GoalMatchType })
matchType: GoalMatchType

@ApiPropertyOptional()
value: string | null

@ApiPropertyOptional({ type: [MetadataFilterDto] })
metadataFilters: MetadataFilterDto[] | null

@ApiProperty()
active: boolean

@ApiProperty()
pid: string

@ApiProperty()
created: Date
}

export class GoalStatsDto {
@ApiProperty({ description: 'Total number of conversions' })
conversions: number

@ApiProperty({ description: 'Number of unique sessions that converted' })
uniqueSessions: number

@ApiProperty({ description: 'Conversion rate as percentage' })
conversionRate: number

@ApiProperty({ description: 'Previous period conversions for trend' })
previousConversions: number

@ApiProperty({ description: 'Trend percentage change' })
trend: number
}
76 changes: 76 additions & 0 deletions backend/apps/cloud/src/goal/entity/goal.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import {
Column,
CreateDateColumn,
Entity,
JoinColumn,
ManyToOne,
PrimaryGeneratedColumn,
} from 'typeorm'
import { ApiProperty } from '@nestjs/swagger'
import { Project } from '../../project/entity/project.entity'

export enum GoalType {
PAGEVIEW = 'pageview',
CUSTOM_EVENT = 'custom_event',
}

export enum GoalMatchType {
EXACT = 'exact',
CONTAINS = 'contains',
REGEX = 'regex',
}

export interface MetadataFilter {
key: string
value: string
}

@Entity()
export class Goal {
@ApiProperty()
@PrimaryGeneratedColumn('uuid')
id: string

@ApiProperty()
@Column('varchar', { length: 100 })
name: string

@ApiProperty()
@Column({
type: 'enum',
enum: GoalType,
})
type: GoalType

@ApiProperty()
@Column({
type: 'enum',
enum: GoalMatchType,
default: GoalMatchType.EXACT,
})
matchType: GoalMatchType

@ApiProperty()
@Column('varchar', { length: 500, nullable: true })
value: string | null

@ApiProperty()
@Column('json', { nullable: true })
metadataFilters: MetadataFilter[] | null

@ApiProperty()
@Column({
type: 'boolean',
default: true,
})
active: boolean

@ApiProperty({ type: () => Project })
@ManyToOne(() => Project, project => project.goals)
@JoinColumn()
project: Project

@ApiProperty()
@CreateDateColumn()
created: Date
}
Loading