AnalyticsUsage
track
Track custom events
Track custom events with optional properties.
Client
Use the useAnalytics hook in client components:
import { } from "@repo/analytics"
const { } = ()Usage
track(event: string, properties?: Record<string, unknown>)| Parameter | Type | Description |
|---|---|---|
event | string | Event name (e.g., "SIGNUP_CLICKED") |
properties | Record<string, unknown> | Optional event properties |
Examples
"use client"
import { } from "@repo/analytics"
export function () {
const { } = ()
return (
< ={() => ("SIGNUP_CLICKED", { : "hero" })}>
Get Started
</>
)
}("PURCHASE_COMPLETED", {
: 99.99,
: "USD",
: "pro-plan"
})Server
Use the track function from @repo/analytics/server in Server Actions, API routes, or server components:
import { } from "@repo/analytics/server"Usage
await track(event: TrackableEvent | TrackableEvent[])Server-side tracking requires a userId or anonymousId:
interface TrackableEvent {
: string
: string
?: string
[: string]: unknown
}Examples
Server Action
"use server"
import { } from "@repo/analytics/server"
import { } from "@repo/auth/server"
export async function (: string) {
const { } = await ()
const = await db.insert(teams).values({ }).returning()
await ({
: "TEAM_CREATED",
: .id,
: .id,
:
})
return
}API Route
import { } from "@repo/analytics/server"
export async function (: Request) {
const { , , } = await .()
await ({
: "PURCHASE_COMPLETED",
,
,
})
return .({ : true })
}Batch tracking
await ([
{ : "TEAM_CREATED", : ., : . },
{ : "TEAM_JOINED", : ., : . }
])Event naming conventions
Use SCREAMING_SNAKE_CASE for consistency:
SIGNUP_CLICKEDPURCHASE_COMPLETEDFEATURE_USEDTEAM_CREATEDERROR_OCCURRED