Skip to main content
← All platforms
Quickstart

JavaScript

The browser SDK. Tracks events, reads feature flags and experiments, and captures errors in any web app.

Runs on
ES2020 browsers

Get an API key

Don't have an account yet? Create one, free. Then open Settings → API Keys in the dashboard and copy the publishable key (lp_pub_…). It is safe to ship inside a browser or app bundle.

Install

bash
npm install @sheepit-ai/sdk-js

Initialize and send your first event

sheepit.ts
import { Sheepit } from "@sheepit-ai/sdk-js";

export const sheepit = Sheepit.init({
  apiKey: "lp_pub_...", // publishable key only
  appVersion: "1.4.2", // ties events to the release they came from
});

sheepit.track("signup_completed", { plan: "pro" });

Read a flag and an experiment

ts
// import { sheepit } from "./sheepit";
// Returns the default until the first config fetch lands.
const showNewCheckout = sheepit.flag("new_checkout", false) === true;

const { variant } = sheepit.experiment("pricing_page");

Identify users

ts
// import { sheepit } from "./sheepit";
// After login:
sheepit.identify("user_123", { plan: "pro" });

// On logout:
sheepit.reset();

Check that it worked

Open Events in the dashboard. Your signup_completed event shows up within about a minute: the SDK batches events and sends them every few seconds.

Worth knowing

  • flag() and experiment() return immediately. Until the first config fetch lands they return the default you pass; after that the SDK keeps config fresh in the background, so a flag change reaches a running page after a delay rather than instantly.
  • The browser SDK refuses secret and dev keys at startup, because shipping them would expose your project.
  • Self-hosted install? Add apiUrl: "https://<your-install>/api" to the config. The docs inside your install's dashboard show the exact value.
JavaScript quickstart | Sheepit