Install DataPocket on React Router

Updated

Framework mode (Remix) and library mode. pushState navigations are tracked automatically. Sign in and these snippets fill in your site ID and domain. Until then, swap YOUR_SITE_ID and YOUR_DOMAIN with the values from your Install page.

  1. 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. 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. 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. 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>"}'

Related guides

Install DataPocket on React Router · DataPocket