Skip to content

SDKs

React SDK

Add Tracklyne to a React or Next.js app with a provider, hooks for events and flags, and an error boundary.

Install

Terminal
npm install @tracklyne/react @tracklyne/js
app/providers.tsx
"use client";
import { TracklyneProvider } from "@tracklyne/react";

export function Providers({ children }: { children: React.ReactNode }) {
  return <TracklyneProvider token="tl_your_project_token" apiHost="https://tracklyne.com">{children}</TracklyneProvider>;
}

Feature flags and errors

Checkout.tsx
const capture = useCapture();
const variant = useFeatureFlag("pricing-test"); // undefined while flags load

<TracklyneErrorBoundary fallback={<p>Something went wrong.</p>}>
  <Checkout onPay={() => capture("checkout paid")} />
</TracklyneErrorBoundary>

The SDK starts once, in the browser, so server rendering is safe. In a single-page app without history tracking, render <PageView path={route} /> once inside your router.