The analytics SDK

Install the SDK and track pageviews, custom events, and identities.

The SDK is one dependency and one provider. Pageviews come free; events and identity are one call each.

Install

pnpm add @plainalpha/analytics

Wrap your app and pass the site key from your repository's analytics settings:

app.tsxreact
import { PlainAnalytics } from "@plainalpha/analytics/react";

export function App({ children }) {
  return (
    <>
      {children}
      <PlainAnalytics publicKey="pa_pub_..." host="https://alpha.plain.jxd.dev" />
    </>
  );
}

The key is public by design; it identifies the site, not a secret.

Automatic pageviews

The SDK patches history navigation, so single-page apps report every route change as a pageview, not just the first load. There is nothing to wire into your router.

Custom events

import { track } from "@plainalpha/analytics";

track("signup_completed", { plan: "hobby" });

Events take a name and a properties object. Properties power the breakdowns and funnels, so send the dimensions you will want to slice by.

Identifying users

import { identify, reset } from "@plainalpha/analytics";

identify(user.id, { plan: user.plan });
reset(); // on sign-out

identify ties subsequent events to a user and upserts their traits; reset returns the session to anonymous. Identified activity appears in the People tab with each person's event history.