# Quickstart

Install datacub and see your first event in a few minutes.

## 1. Get your project key

Open [Settings, Integrations](https://datacub.to/en/settings?tab=integrations) in the dashboard. Your project key starts with `pk_live_` (or `pk_test_` while you build). It is public and safe in client code. [More about keys](https://docs.datacub.to/api-keys.md).

In [Settings, General](https://datacub.to/en/settings?tab=general), add your website's domain to the sites allowed to send, or your app's bundle ID or package name to the apps allowed to send. datacub refuses events from anywhere else.

## 2. Add the SDK

Paste this in your HTML `<head>` (in Next.js, TanStack Start or SvelteKit, see [where the head is](https://docs.datacub.to/frameworks.md)). It loads the SDK from datacub and defines the global `datacub`:

```html script
<script>
  (function (w, d, src) {
    var q = (w.datacub = w.datacub || [])
    ;['init', 'track', 'identify', 'reset'].forEach(function (n) {
      q[n] = function () { q.push([n].concat([].slice.call(arguments))) }
    })
    var s = d.createElement('script'); s.async = true; s.src = src; d.head.appendChild(s)
  })(window, document, 'https://ingest.datacub.example/v1/sdk/datacub-0.4.0.min.js')
  datacub.init('pk_live_YOUR_PROJECT_KEY')
</script>
```

On `localhost`, use your test key (`pk_test_`): datacub refuses live keys from `localhost`. Every project comes with one, marked **Test** in [Settings, Integrations](https://datacub.to/en/settings?tab=integrations). [More about keys](https://docs.datacub.to/api-keys#test-and-live).

> Not on npm. Do not install `@datacub/web`, or anything else under `@datacub`, from npm: that npm name does not belong to datacub. The React Native SDK is not published yet: contact the datacub team for early access.

## 3. That is the install

datacub tracks page views, sessions, sources and clicks from the first page view. There is no banner to wire. If you want to wait for your visitors' consent first, see [asking for consent](https://docs.datacub.to/consent.md). What the SDK collects, and how to turn parts off, is in [install the web SDK](https://docs.datacub.to/install-web#what-the-sdk-collects).

## 4. Track one thing that matters

Pick the moment your product works for someone, and track it after it succeeds:

```ts web
async function createProject(name: string) {
  const project = await api.createProject(name)
  datacub.track('project_created', { template: project.template })
  return project
}
```

[How to choose and name events](https://docs.datacub.to/event-naming.md).

## 5. Check it arrived

In [Settings, Integrations](https://datacub.to/en/settings?tab=integrations), choose **Check the connection** and open your site or app: datacub tells you the moment the first event lands. **Realtime** shows events as they arrive. Nothing there? On `localhost` the SDK prints a console warning for every call it refuses. See [troubleshooting](https://docs.datacub.to/troubleshooting.md).

## Working with an AI coding agent?

Paste the [AI setup prompt](https://docs.datacub.to/ai#setup-prompt) into Claude Code, Cursor, Codex or ChatGPT. It reads your app, installs the SDK, proposes a short event plan and waits for your yes.
