---
title: "Install DataPocket on React Router"
description: "Add DataPocket web analytics with revenue attribution to React Router. Framework mode (Remix) and library mode. pushState navigations are tracked automatically."
url: "https://datapocket.vo1d.studio/docs/react-router"
lang: "en"
updated: "2026-11-13"
---

# Install DataPocket on React Router

Framework mode (Remix) and library mode. pushState navigations are tracked automatically. Replace `YOUR_SITE_ID` and `YOUR_DOMAIN` with the values from your site's Install page.

## Steps

1. Framework mode: add the script in app/root.tsx inside <head>:

```tsx
export function Layout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <head>
        <Meta />
        <Links />
        <script defer data-site-id="YOUR_SITE_ID" data-domain="YOUR_DOMAIN" src="https://datapocket.vo1d.studio/js/script.js" />
      </head>
      <body>{children}<ScrollRestoration /><Scripts /></body>
    </html>
  );
}
```

2. Library mode (Vite SPA): paste the tag into index.html <head>. Using HashRouter? Load script.hash.js instead:

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

## Revenue attribution

1. Pass the visitor cookie to Stripe Checkout so each sale is attributed to the channel that brought the buyer:

```js
const session = await stripe.checkout.sessions.create({
  // …your line_items, mode, success_url…
  metadata: {
    datapocket_visitor_id: req.cookies.dp_vid,
    datapocket_session_id: req.cookies.dp_sid,
  },
});
```

2. Using another payment provider? Send payments from your backend (create an API key in Settings):

```bash
curl -X POST https://datapocket.vo1d.studio/api/v1/payments \
  -H "Authorization: Bearer dpk_…" \
  -H "Content-Type: application/json" \
  -d '{"amount": 29.99, "currency": "USD", "transaction_id": "order_123", "visitor_id": "<dp_vid cookie>"}'
```

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

- [Vue.js](https://datapocket.vo1d.studio/docs/vue): Vue 3 + Vue Router, Nuxt, Vite. History-mode routing is tracked automatically.
- [JavaScript apps](https://datapocket.vo1d.studio/docs/npm): React, Vue, Svelte or Angular: the script tag with typed calls, plus server-side payments and goals over HTTP.
- [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)
