Skip to content
trakoo
Esc
navigateopen⌘Jpreview
On this page

Getting Started

trakoo is one typed analytics API for TypeScript. Define your events once, choose your providers, and keep the same track() calls when your stack changes.

trakoo gives your TypeScript app a single, typed analytics API. You define the events your product emits, pick the providers you trust, and call track(). When your analytics stack changes, those call sites stay the same — you swap providers in one place, not across your codebase.

It runs the same way in the browser and on the server, ships zero dependencies, and works on the edge.

Providers

Start with one provider and add more when you need them. Every provider is optional and independently configured.

How it works

You describe your events once. That single definition becomes autocomplete, compile-time validation, and provider routing everywhere you track.

import type { CreateEventDefinition, EventCollection } from 'trakoo';

export const appEvents = {
  userSignedUp: {
    name: 'user_signed_up',
    category: 'user',
    properties: {} as {
      email: string;
      plan: 'free' | 'pro' | 'enterprise';
    }
  }
} as const satisfies EventCollection<Record<string, CreateEventDefinition<string>>>;

export type AppEvents = typeof appEvents;

Create an analytics instance with the providers you want, typed by those events:

import { createClientAnalytics } from 'trakoo/client';
import {
  PostHogClientProvider,
  VisitorsClientProvider
} from 'trakoo/providers/client';
import type { AppEvents } from './events';

export const analytics = createClientAnalytics<AppEvents>({
  providers: [
    new PostHogClientProvider({ token: import.meta.env.VITE_POSTHOG_KEY }),
    new VisitorsClientProvider({ token: import.meta.env.VITE_VISITORS_TOKEN })
  ]
});

Then track from anywhere. TypeScript knows the valid event names and their required properties:

analytics.track('user_signed_up', {
  email: 'ada@example.com',
  plan: 'pro'
});

Add Bento for lifecycle email later, or move browser events through the Proxy — the code calling analytics.track() doesn’t change.

Why trakoo

Next steps

Was this page helpful?