# JavaScript quickstart

Source: https://www.sheepit.ai/docs/sdks/js

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

- Package: [@sheepit-ai/sdk-js](https://www.npmjs.com/package/@sheepit-ai/sdk-js)
- Runs on: ES2020 browsers

## 1. Get an API key

Don't have an account yet? [Create one, free](https://www.sheepit.ai/signup). 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.

## 2. Install

```bash
npm install @sheepit-ai/sdk-js
```

## 3. Initialize and send your first event

`sheepit.ts`:

```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" });
```

## 4. 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");
```

## 5. Identify users

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

// On logout:
sheepit.reset();
```

## 6. 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.
