---
title: "Install DataPocket on JavaScript apps"
description: "Add DataPocket web analytics with revenue attribution to JavaScript apps. React, Vue, Svelte or Angular: the script tag with typed calls, plus server-side payments and goals over HTTP."
url: "https://datapocket.vo1d.studio/docs/npm"
lang: "en"
updated: "2026-11-13"
---

# Install DataPocket on JavaScript apps

React, Vue, Svelte or Angular: the script tag with typed calls, plus server-side payments and goals over HTTP. Replace `YOUR_SITE_ID` and `YOUR_DOMAIN` with the values from your site's Install page.

## Steps

1. The datapocket npm package isn't on the npm registry yet, so `npm install datapocket` won't work. Add the script tag to index.html (or your framework's document head):

```html
<script
  defer
  data-site-id="YOUR_SITE_ID"
  data-domain="YOUR_DOMAIN"
  src="https://datapocket.vo1d.studio/js/script.js"
></script>
```

2. Call it from your code. This helper is typed and queues calls made before the script loads:

```ts
// datapocket.ts
type Props = Record<string, string | number | boolean>;
declare global {
  interface Window { datapocket?: ((name: string, props?: Props) => void) & { q?: unknown[]; visitorId?: string } }
}

export function track(name: string, props?: Props) {
  const w = window;
  w.datapocket = w.datapocket || Object.assign((...args: unknown[]) => { (w.datapocket!.q = w.datapocket!.q || []).push(args); }, {});
  w.datapocket(name, props);
}

// later
track("signup", { plan: "pro" });
```

3. Server-side (Node, Bun, Deno, edge): record payments and goals with fetch. Every field is in the REST API reference (/reference/rest-api):

```ts
const DP = "https://datapocket.vo1d.studio/api/v1";
const headers = { Authorization: `Bearer ${process.env.DATAPOCKET_KEY}`, "Content-Type": "application/json" };

await fetch(`${DP}/payments`, { method: "POST", headers,
  body: JSON.stringify({ amount: 49, currency: "USD", transaction_id: order.id, visitor_id: cookies.dp_vid }) });

await fetch(`${DP}/goals`, { method: "POST", headers,
  body: JSON.stringify({ visitor_id: cookies.dp_vid, name: "trial_started" }) });
```

## Verify

1. Deploy or publish, then open your site in a normal browser window (ad blockers off).
2. In the browser's Network tab, look for a POST to `/api/event` (or `/dp/api/event` when proxied) that returns `{"ok":true}`.
3. The DataPocket Install page for this site switches to "Receiving data" within a few seconds.

## Related guides

- [React Router](https://datapocket.vo1d.studio/docs/react-router): Framework mode (Remix) and library mode. pushState navigations are tracked automatically.
- [Vue.js](https://datapocket.vo1d.studio/docs/vue): Vue 3 + Vue Router, Nuxt, Vite. History-mode routing is tracked automatically.
- [Express](https://datapocket.vo1d.studio/docs/express): Serve the script and forward events from your Express server.
- [FastAPI](https://datapocket.vo1d.studio/docs/fastapi): Async proxy with httpx.
- [AI crawler tracking](https://datapocket.vo1d.studio/docs/ai-bots)
