Core Concepts
The five ideas behind trakoo — events, providers, the client/server split, user identification, and type safety.
trakoo is small, but a few ideas do the heavy lifting. Read these in order and you’ll understand everything the rest of the docs build on.
Events
Define type-safe events once — names, categories, and typed properties.
How Providers Work
The plugin model that fans one event out to every service you use.
Client vs Server
Two APIs — stateful in the browser, stateless on the server.
Identifying Users
Attach user context so events tell you who did what.
Type Safety
How your definitions become autocomplete and compile-time checks.
The shape of the API
Everything comes back to three moves: define events, create an instance with providers, and track.
// 1. Define events once
export const appEvents = {
buttonClicked: {
name: 'button_clicked',
category: 'engagement',
properties: {} as { buttonId: string }
}
} as const satisfies EventCollection<Record<string, CreateEventDefinition<string>>>;
// 2. Create an instance with your providers
const analytics = createClientAnalytics<typeof appEvents>({
providers: [new PostHogClientProvider({ token: 'xxx' })]
});
// 3. Track — fully typed
analytics.track('button_clicked', { buttonId: 'cta' });
Client tracking is stateful: identify() once, and later events carry that user until you reset(). Server tracking is stateless: pass user context with each track(), then shutdown() to flush. Client vs Server covers the difference in full.
Before you start
These guides assume you’ve run through the Quick Start, installed trakoo with at least one provider, and are comfortable with basic TypeScript.
Start with Events →
