# Add tracker to React Router App

## 1. Include the UXWizz tracking snippet in your index.html file

You should now be able to use `UST` in your application. If you use TypeScript, you can declare `UST` as any. TypeScript typings for the tracker will be released soon.

## 2. Track pageviews

By default, being a SPA, only the entry pageview will be tracked.

To track all consequent pageviews, include a new UXWizzPageview\.ts in your app

```jsx
import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';

export default function UXWizzPageview() {
    const location = useLocation();
    const isInitialLoad = useRef(true);

    useEffect(() => {
        if (isInitialLoad.current) {
            isInitialLoad.current = false
            return;
        };
        if (typeof window === 'undefined') return;
        const ust = (window as typeof window & { UST: { trackNewPage: () => void } })['UST'];
        if (!ust || !ust.trackNewPage) return;
        ust.trackNewPage(); // Call on route change, but not on initial load
    }, [location]);
    
    return null;
};
```

Then, in your main App component, include `UXWizzPageview`.

<pre class="language-jsx"><code class="lang-jsx">// ...
import UXWizzPageview from './UXWizzPageview';

<strong>export default function App() {
</strong>  return (
    &#x3C;Router>
      &#x3C;UXWizzPageview/>
      {/* your other components */}
    &#x3C;/Router>
  );
}
</code></pre>

{% hint style="info" %}
UXWizz will automatically track the initial page-load (when the tracker file is loaded).

We added a check, to avoid tracking the initial page-load again.
{% endhint %}

{% hint style="warning" %}
If you don't use TypeScript, you can simply remove the typings replace this line:

```javascript
const ust = (window as typeof window & { UST: { trackNewPage: () => void } })['UST'];
```

with

```javascript
const ust = window['UST'];
```

{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.uxwizz.com/installation/adding-the-tracking-code/add-tracker-to-react-router-app.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
