# Quick start

`saasco-sdk` is the browser SDK. One install covers page views, custom events, identify, the optional ad pixels, the AI support widget and the social-proof widget, all keyed off a single Project ID.

It is the only entry point that sees the browser, so sessions, referrers, UTM parameters and device details come from here rather than from the [REST API](/docs/api).

## Setup

### Copy your Project ID

It's on **Settings → Project** in your dashboard. There is no API key involved. The SDK runs in your users' browsers and only ever writes into the project the id names.

### Install

**npm**

```bash
npm install saasco-sdk
```

Create one instance and export it:

```ts title="lib/saasco.ts"
import { Saasco } from "saasco-sdk";

export const saasco = new Saasco({ projectId: "YOUR-PROJECT-ID" });
```

**Script tag**

Drop one tag in just before `</body>`. It constructs the instance and calls `init()` for you, and exposes it as `window.saasco`:

```html
<script
  src="https://www.saasco.com/sdk/saasco-sdk.js"
  data-projectId="YOUR-PROJECT-ID"
  async
></script>
```

Common constructor options map to `data-*` attributes. See [Configuration](/docs/sdk/configuration#script-tag-attributes). Skip the next step; you're already initialized.

### Call `init()` once

`init()` is what starts automatic page tracking and injects the widget loaders. Constructing `new Saasco(...)` on its own does neither.

```ts
import { saasco } from "./lib/saasco";

saasco.init();
```

In the Next.js App Router, wrap it in a client component so it only runs in the browser:

```tsx title="components/SaascoAnalytics.tsx"
"use client";

import { useEffect } from "react";

import { saasco } from "../lib/saasco";

export function SaascoAnalytics() {
  useEffect(() => {
    saasco.init();
  }, []);

  return null;
}
```

Then render `<SaascoAnalytics />` from your root layout.

### Verify

Load a page with `?saasco-debug=true` on the URL and watch the console. Every event the SDK sends is logged. Then open **Analytics → Events** in the dashboard; the `Page View` should be there within a few seconds.

If nothing arrives, check that `init()` actually ran (the debug log starts with `Saasco started`) and that `enabled` isn't `false` for this environment. From a terminal, the [setup progress check](/docs/getting-started#check-it-works) reports the same steps.

## What you get from here

[Tracking](/docs/sdk/tracking)

Page views, custom events, and sending events from a server.

[Identify](/docs/sdk/identify)

Tie events to a CRM contact, before or after they have an account.

[Configuration](/docs/sdk/configuration)

Every constructor option, script-tag attribute, debug switch and ad pixel.

[Widgets](/docs/sdk/widgets)

The AI support widget and social-proof notifications.

- [Tracking](https://www.saasco.com/docs/sdk/tracking): page views, custom events, and sending events from a server.
- [Identify](https://www.saasco.com/docs/sdk/identify): tie events to a CRM contact.
- [Configuration](https://www.saasco.com/docs/sdk/configuration): every constructor option, script-tag attribute, debug switch and ad pixel.
- [Widgets](https://www.saasco.com/docs/sdk/widgets): the AI support widget and social-proof notifications.
- [All docs as plain text](https://www.saasco.com/llms-full.txt), and the [index](https://www.saasco.com/llms.txt).

## Development and staging

On `localhost`, hosting-provider preview deployments and `staging.`-style subdomains, the SDK sends to your test project (`test_YOUR-PROJECT-ID`) by itself. Pass `test: true` on any other non-production host so only production reaches the live one. Test data stays out of your live dashboard, and test usage is free up to a monthly allowance. See [Test and live](/docs/getting-started#test-and-live).

To send nothing at all outside production, gate it instead:

```ts title="lib/saasco.ts"
export const saasco = new Saasco({
  projectId: "YOUR-PROJECT-ID",
  enabled: process.env.NODE_ENV === "production",
});
```

Debug logging still works while `enabled` is `false`. The events just aren't sent.

## Privacy

By default the SDK tracks nobody in particular: activity sits behind an anonymous visitor id and a session id, stored in first-party `saasco-sdk-*` cookies on your own root domain (about a year for the visitor, 30 minutes for the session). Personal data only enters when you [identify](/docs/sdk/identify) someone.
