> For the complete documentation index, see [llms.txt](https://docs.humblytics.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.humblytics.com/how-to-get-started/react-router.md).

# React Router

Add Humblytics to your React Router app in about 5 minutes.

{% hint style="info" %}
**You need:** access to your app's HTML shell or root route and a production deploy. A local dev server won't verify.
{% endhint %}

## 1. Copy your tracking code

In Humblytics, open **Site settings → Install** and click **Copy tracking code**.

## 2. Add it once, in the `<head>`

Load the script once for the whole app. Humblytics tracks route changes on its own, so you don't need any code in your routes.

| Setup                                     | Where to paste                                     |
| ----------------------------------------- | -------------------------------------------------- |
| Vite + React Router (SPA)                 | `index.html` in the project root, before `</head>` |
| Create React App                          | `public/index.html`, before `</head>`              |
| React Router v7 framework mode (or Remix) | The `<head>` in `app/root.tsx` (see below)         |

In `app/root.tsx`, JSX needs the inline script as a string. Replace `YOUR_SCRIPT_ID` with the Script ID from your snippet:

```tsx
const HMBL_ANTI_FLICKER = `
(function(){
  var w=window,l=location,d=document.documentElement,done=false;
  function k(p){p=String(p||'/').toLowerCase();while(p.length>1&&p.charAt(p.length-1)==='/')p=p.slice(0,-1);for(var h=5381,i=0;i<p.length;i++)h=((h*33)^p.charCodeAt(i))>>>0;return h.toString(36);}
  function r(){if(done)return;done=true;d.classList.remove('hmbl-pending');if(d.style.opacity==='0')d.style.opacity='';}
  w._hmblReveal=r;
  if(document.readyState!=='loading'||/[?&](hmblEditor|hmblSessionRecording|humblytics_heatmap_token)=|#preview-humblytics-/.test(l.search+l.hash))return;
  var st=new URLSearchParams(l.search).get('_st'),ref=document.referrer,same=!ref;
  try{same=same||new URL(ref).host===l.host;}catch(e){same=true;}
  if(st&&same&&st===k(l.pathname)){
    w._hmblSt=st;
    if(!(w.fbq||w.google_tag_manager||w.ttq)){var u=new URL(l.href);u.searchParams.delete('_st');history.replaceState(history.state,'',u.href);}
    return;
  }
  d.classList.add('hmbl-pending');
  function cap(){setTimeout(function(){if(!w.HumblyticsRedirectRunning)r();},2000);setTimeout(r,4000);}
  if(document.prerendering)document.addEventListener('prerenderingchange',cap,{once:true});else cap();
  w.addEventListener('pageshow',function(e){if(e.persisted)r();});
})();
`

export function Layout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <head>
        <Meta />
        <Links />
        <style>{`html.hmbl-pending body{opacity:0!important}`}</style>
        <script dangerouslySetInnerHTML={{ __html: HMBL_ANTI_FLICKER }} />
        <script async src="https://app.humblytics.com/hmbl.min.js?id=YOUR_SCRIPT_ID" />
      </head>
      <body>{children}</body>
    </html>
  )
}
```

## 3. Deploy and verify

1. Deploy to production.
2. Back in Humblytics, click **Verify install** (during first-time setup, **Check my site now**).
3. Open your live site in a private window and click around. Your visit appears in **Observe → Analytics → Overview** under **Live Activity** within about a minute.

**Not verifying?** Test the production build, and make sure the script is in the HTML shell, not inside a component that mounts later.

Still stuck? See [Verify & Troubleshoot Tracking](https://docs.humblytics.com/how-to-get-started/verify-and-troubleshoot-tracking.md).
