# Page addresses

Replace the IDs and names in your page addresses before they leave the browser, so reports group pages by route and hold no personal data.

Many apps put IDs and names in their page addresses, such as `/orders/8412` or `/team/jane`. Each one then shows up as its own page in your reports, and the address can tell who the visitor is. Give the script a `url` function to replace them in the browser, before anything leaves it.

## Add the function

The function gets each address the script is about to send and returns the one to send in its place.

**Script tag**

Set it in a line above the snippet.

```html
<script>window.ultanimus = { url: (url) => url.replace(/\/orders\/\d+/, '/orders/[id]') }</script>
<script defer src="https://cdn.ultanimus.com/s.js" data-site="YOUR_SITE_ID"></script>
```

If you also use the queue line from [Custom events](/docs/tracking/custom-events#from-the-script-tag), add `url` to the same object.

**React**

Pass it to `Analytics`.

```tsx
<Analytics site="YOUR_SITE_ID" url={(url) => url.replace(/\/orders\/\d+/, '/orders/[id]')} />
```

**Next.js**

A function cannot pass from a server component to the browser. Render `Analytics` in a client component, and put that component in your root layout.

`app/tracking.tsx`

```tsx
'use client'

import { Analytics } from '@ultanimus/next'

export function Tracking() {
  return <Analytics site="YOUR_SITE_ID" url={(url) => url.replace(/\/orders\/\d+/, '/orders/[id]')} />
}
```

Pages then group by route in your reports: `/orders/[id]` counts every order page together.

## What it gets

The function runs on every event the script sends: pageviews, custom events, link clicks, page loads, web vitals and errors. On the first event of each page load, it also gets the address the visitor came from, which can be another site's.

- Return an address, and it goes out in place of the real one.
- Return `null` for the page, and the event is not sent.
- Return `null` for the referrer, and the event goes out without one.

If the function throws, the event is not sent and your page carries on.

Return a full address on your own domain, as you got it. Events from another domain do not count, with or without the function.

## Keep campaign tags

Campaign tags such as `utm_source` sit in the query string and decide where a visit came from, so never drop the whole query string. To drop a private parameter, such as a reset token, remove that parameter alone:

```js
url: (url) => url.replace(/([?&])token=[^&#]*&?/, '$1')
```

## Goals, funnels and rules

Goals, funnels and [excluded pages](/docs/tracking/excluded-pages) see the address the function returned. Write their patterns against it, such as `/orders/[id]`.

An excluded page still sends its address, and the server drops it on arrival. When an address must never leave the browser, change it here.
