feat: implement custom events tracking and goals management in the dashboard

This commit is contained in:
Usman Baig
2026-02-04 14:33:06 +01:00
parent 0d16f3ba55
commit 90a743c170
7 changed files with 362 additions and 2 deletions

48
lib/api/goals.ts Normal file
View File

@@ -0,0 +1,48 @@
import apiRequest from './client'
export interface Goal {
id: string
site_id: string
name: string
event_name: string
funnel_steps: string[]
created_at: string
updated_at: string
}
export interface CreateGoalRequest {
name: string
event_name: string
funnel_steps?: string[]
}
export interface UpdateGoalRequest {
name: string
event_name: string
funnel_steps?: string[]
}
export async function listGoals(siteId: string): Promise<Goal[]> {
const res = await apiRequest<{ goals: Goal[] }>(`/sites/${siteId}/goals`)
return res?.goals ?? []
}
export async function createGoal(siteId: string, data: CreateGoalRequest): Promise<Goal> {
return apiRequest<Goal>(`/sites/${siteId}/goals`, {
method: 'POST',
body: JSON.stringify(data),
})
}
export async function updateGoal(siteId: string, goalId: string, data: UpdateGoalRequest): Promise<Goal> {
return apiRequest<Goal>(`/sites/${siteId}/goals/${goalId}`, {
method: 'PUT',
body: JSON.stringify(data),
})
}
export async function deleteGoal(siteId: string, goalId: string): Promise<void> {
await apiRequest(`/sites/${siteId}/goals/${goalId}`, {
method: 'DELETE',
})
}

View File

@@ -33,6 +33,11 @@ export interface PerformanceByPageStat {
inp: number | null
}
export interface GoalCountStat {
event_name: string
count: number
}
export interface TopReferrer {
referrer: string
pageviews: number
@@ -280,6 +285,7 @@ export interface DashboardData {
screen_resolutions: ScreenResolutionStat[]
performance?: PerformanceStats
performance_by_page?: PerformanceByPageStat[]
goal_counts?: GoalCountStat[]
}
export async function getDashboard(siteId: string, startDate?: string, endDate?: string, limit = 10, interval?: string): Promise<DashboardData> {