Add Sumly to a React Router or Vite React app

In React Router's framework mode the line goes into the head of the root layout; in a plain Vite app, into index.html. Route changes count by themselves.

Drawn with an example line.

Step by step

  1. 1

    In Sumly, open Visitors and copy your project's line.

  2. 2

    With React Router's framework mode, paste it into the <head> of the Layout in app/root.tsx, after <Links />. In a plain Vite app, paste it into the <head> of index.html at the project's root.

  3. 3

    Deploy. Open the app and the visit shows on Visitors; each route you go to counts as a page view.

In the head the root layout renders for every route.

export function Layout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <head>
        <meta charSet="utf-8" />
        <Meta />
        <Links />
        <script defer src="https://sumly.dev/s.js" data-site="sl_your_key"></script>
      </head>
      <body>
        {children}
        <ScrollRestoration />
        <Scripts />
      </body>
    </html>
  );
}

Or let your coding assistant do it

Paste this into Claude Code, Cursor or Codex in your project. It fits the code to how your project is built, asks you for the dashboard steps and leaves the keys to you.

See what it says
Set up React Router and Vite for Sumly in this project.

Sumly (https://sumly.dev) shows revenue next to the visits and app users it came from. The full guide is https://sumly.dev/install/react-router; read it if anything below is unclear.

Steps:
1. In Sumly, open Visitors and copy your project's line.
2. With React Router's framework mode, paste it into the `<head>` of the `Layout` in `app/root.tsx`, after `<Links />`. In a plain Vite app, paste it into the `<head>` of `index.html` at the project's root.
3. Deploy. Open the app and the visit shows on Visitors; each route you go to counts as a page view.

app/root.tsx: In the head the root layout renders for every route.
```
export function Layout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <head>
        <meta charSet="utf-8" />
        <Meta />
        <Links />
        <script defer src="https://sumly.dev/s.js" data-site="sl_your_key"></script>
      </head>
      <body>
        {children}
        <ScrollRestoration />
        <Scripts />
      </body>
    </html>
  );
}
```

index.html: A plain Vite app: the page Vite builds from.
```
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <script defer src="https://sumly.dev/s.js" data-site="sl_your_key"></script>
  </head>
  <body>
    <div id="root"></div>
    <script type="module" src="/src/main.tsx"></script>
  </body>
</html>
```

Keep in mind: The Layout also draws the error page, so keep the line there rather than in a route: errors then count as visits too. With a nonce-based content security policy, allow the script's address (or your own domain's) in it.

How to work:
- Look at how this project is built first, and fit the code to its framework and its way of doing things; the examples above are a starting point, not something to paste as is.
- Steps that happen in a dashboard (Sumly, or React Router and Vite's own) are mine: tell me exactly what to click, then wait for me.
- Keys the code needs belong in environment variables, never in the code or the repository. Never ask me to paste a secret key into this chat; tell me which variable to set.
- Change only what this needs, show me the changes before you commit, and tell me how to check that it works.
- sl_your_key stands for the project's public key; it is on the Visitors page in Sumly. Ask me for it.

Consent

In the EU, the EEA, the UK and Switzerland the script sets no cookie until you call sumly.consent(true), usually from your cookie banner once the visitor agrees, and counts visits without one until then. To wait for consent everywhere, add data-consent="always" to the line. Or add data-cookieless: no Sumly cookie anywhere, so nothing to ask, but a returning visitor counts as new each day and a payment is only traced to a visit on the same day.

Checkout

Stripe Payment Links, pricing tables and buy buttons, Polar checkout links, Paddle buttons and Gumroad product links on your pages carry the visitor into checkout by themselves. For a checkout your own server creates, pass the sumly_vid cookie as metadata named sumly_visitor_id, or send the buyer back to a page with the script and ?session_id={CHECKOUT_SESSION_ID} (Stripe) or ?checkout_id={CHECKOUT_ID} (Polar).

Your own domain

On Starter and Growth, one DNS record serves the script from your own address, past ad blockers: under Visitors › Add tracking › Your own address, enter one such as signal.your-site.com and add the CNAME it shows. If your checkout or app is on another domain, add it under Projects and payments › Other domains: the line then carries data-domains and one person stays one visitor across them.

Clicks and sections

Clicks on links to other sites count by themselves. Mark a button with data-sumly-event="signup" to count its clicks, and a section with data-sumly-scroll="pricing" to count the page views that reached it, a goal such as reached pricing.

Good to know

  • The Layout also draws the error page, so keep the line there rather than in a route: errors then count as visits too.
  • With a nonce-based content security policy, allow the script's address (or your own domain's) in it.

From React Router and Vite's own documentation, checked 4 November 2026: reactrouter.com/api/framework-conventions/root.tsx, vite.dev/guide .

Other platforms

Try it with your own projects

Sign in with Google or a code by e-mail and connect your first project. Free for one project, and 14 days of a paid plan with no card.

Start free

Or look around first: open the live demo.