# Install and verify the script

> Add your website, put the tracking script on every page, confirm the first visit and set the script's options.

Source: https://supametrics.io/docs/install-the-script

Supametrics counts visitors with one small script (about 5 KB gzipped) on your website. It uses first-party
cookies on your own domain and loads with `defer`, so it never holds up your page. This page covers adding a
website, installing the script on common platforms, confirming that it works and the options you can add to
the script tag.

## Add your website

After you create your account, the **Add your website** screen asks for:

- **Domain**: for example `example.com`. Subdomains (`www.example.com`, `app.example.com`) are included
  automatically; visits from any other domain are rejected. You can paste a full address; it is reduced to
  the domain.
- **Name (optional)**: a nickname shown in the website switcher, such as `My product`.
- **Currency**: the currency your Stripe prices are in. Revenue is reported in this currency only; payments in
  other currencies are listed but not added up.
- **Timezone**: decides where each day starts on the charts. It defaults to your browser's timezone.

Click **Continue**. The steps at the top of the screen (**Add website**, **Install script**, **First visit**)
show where you are.

You can change these later in **Site settings › General** (domain, additional domains and timezone, next to
the install snippet and the installation status) and **Site settings › Revenue** (currency, next to the Stripe
connection). After a domain change, visits from the old domain are rejected. After a currency change, only
payments in the new currency count, including past ones.

To add another website later, see [Websites and workspaces](https://supametrics.io/docs/websites).

## Copy the snippet

Until the first visit arrives, the app opens on the **Setup** screen (`/setup`). Once the website is verified,
`/setup` takes you to **Site settings › General**, which shows the same snippet. Copy it with **Copy snippet**.
It looks like this, with your own site ID:

```html
<script defer data-site="YOUR_SITE_ID" src="https://app.supametrics.io/js/ax.js"></script>
```

Put it inside `<head>` on every page. If your site still loads the script from `app.analyticsx.io`, our previous
address, it keeps working and nothing is lost: events sent there are recorded as before. Switch to
`app.supametrics.io` when convenient.

The site ID is also shown as **Public site ID** under the domain in
**Site settings › General**. It is not a secret: it appears in your page source, and the server only accepts
data for it from your own domains.

Above the snippet, **Install method** switches between **Script**, **Next.js**, **npm**, **WordPress** and
**Shopify**. Two checkboxes change the snippet:

- **Wait for cookie consent** adds `data-consent="required"`. See [Cookie consent](#cookie-consent).
- **Cookieless / privacy mode** is marked **Soon**. It is not available yet and can't be ticked.

Single-page apps (Next.js, React Router, Vue, Svelte) are tracked automatically: every route change counts
as a pageview.

### Plain HTML

Paste the line before `</head>` in your site template (or in every HTML file). The same applies to any site
builder or CMS that lets you add code to the page head.

### Next.js (App Router)

```tsx
// app/layout.tsx
import Script from 'next/script';

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html>
      <head>
        <Script strategy="afterInteractive" data-site="YOUR_SITE_ID" src="https://app.supametrics.io/js/ax.js" />
      </head>
      <body>{children}</body>
    </html>
  );
}
```

### Bundled apps (npm)

The **npm** tab is for apps built with a bundler (React, Vue, Svelte and others). The `@analyticsx/web`
package is not published yet (**Soon**). Until it is, load the script from your app's entry file. This needs
no dependency:

```js
// main.ts (or your app's entry file)
const s = document.createElement('script');
s.defer = true;
s.src = 'https://app.supametrics.io/js/ax.js';
s.dataset.site = 'YOUR_SITE_ID';
document.head.appendChild(s);

// Then, anywhere in your app:
// window.analyticsx?.('track', 'signup');
```

With **Wait for cookie consent** ticked, the code also sets `s.dataset.consent = 'required';`.

### WordPress

There is no Supametrics plugin yet. Use a plugin that adds code to the page head:

1. In WordPress, open **Plugins › Add New** and install a header-code plugin such as **WPCode**.
2. Open its **Header & Footer** page and paste the snippet into the **Header** box.
3. Save. Visits appear within a minute. WooCommerce pages are tracked like any other page.

### Shopify

Connecting a Shopify store directly is marked **Soon**: the fields on the **Shopify** tab are disabled and do
nothing yet. Until then, add the **Script** snippet to the `<head>` of your theme's `theme.liquid`.

## Confirm the first visit

Keep the **Setup** screen open and visit your site in another tab (the screen links to your domain). The
screen checks every few seconds. When the first accepted visit arrives, the status changes from **Waiting** to
**Verified** and shows when the first visit arrived and on which page. It only passes when your site really
sends an accepted visit; nothing else can turn it on.

If nothing arrives after two minutes, the screen shows **Nothing yet? Check these**:

- The page you opened is on your domain or a subdomain (`localhost` isn't counted).
- The snippet is deployed, not only saved locally. View the page source to confirm.
- An ad blocker in your browser may block it. Try a private window with extensions off.
- You haven't excluded this browser with `?ax_ignore=true`.

More causes are in [Troubleshooting](https://supametrics.io/docs/troubleshooting#the-install-check-stays-on-waiting).

Below the status, the **Website settings** card shows the site ID, the **Last accepted event**, the Stripe
connection status, and a form to change the name, domain, currency and timezone (**Save settings**).

Once verified, the app opens on the [dashboard](https://supametrics.io/docs/dashboard) instead.

## Domains

- **Domain** (**Site settings › General**): your main domain. All its subdomains are accepted.
- **Additional domains**: other domains (and their subdomains) that may send data to this website, for
  example a separate checkout or docs domain. Type the domain and click **Add**; **Remove** takes it off.
  Links between your main and additional domains are treated as internal navigation, not referrals.
- **Allow all domains**: a switch above the additional domains, for embedded widgets and custom domains. When
  it is on, any hostname may send data to this website.
- **Managed proxy** is marked **Soon**: serving the script through a subdomain of yours with a CNAME record is
  not available yet. You can proxy it yourself today; see [Serve the script from your domain](#serve-the-script-from-your-domain).

Visitors are identified with a cookie on the domain the page is on, so `example.com` and `app.example.com`
share one visitor, but `example.com` and `another-domain.com` count the same person as two visitors.

Only owners and members can change domains and other settings. Viewers can open the page and copy the
snippet. See [Team members and roles](https://supametrics.io/docs/team-and-roles).

## Options

Add these attributes to the script tag when you need them.

| Attribute | What it does |
|---|---|
| `data-consent="required"` | Sends nothing and sets no cookies until your consent tool calls `analyticsx('consent', true)`. |
| `data-domain="example.com"` | Cookie domain, if automatic detection picks the wrong one. |
| `data-api="https://..."` | Where to send events, when you proxy them through your own domain. |
| `data-allow-localhost` | Also track on `localhost` and other local development hosts, for testing. |

### Cookie consent

With `data-consent="required"`, call this from your consent tool's callbacks:

```js
window.analyticsx?.('consent', true);  // visitor accepted
window.analyticsx?.('consent', false); // visitor withdrew (cookies are removed)
```

The choice is remembered in the visitor's browser. Until consent is given, `analyticsx('visitorId')` returns
`null`, so payments from that browser are Unattributed.

### Test on localhost

By default the script does nothing on `localhost`, `127.x.x.x`, `0.0.0.0`, `[::1]`, `*.local` hosts and
`file:` pages. Add `data-allow-localhost` to the tag while testing locally. Those visits are stored under
their hostname (for example `localhost`), and you can drop them later with a hostname rule in
**Site settings › Exclusions**. Remove the attribute before you deploy, or keep it: it has no effect on your
live domain.

### Serve the script from your domain

Some ad blockers block requests to analytics services. To avoid that, forward requests from a path on your own
domain to `https://app.supametrics.io/api/event` and point the script at it:

```html
<script defer data-site="YOUR_SITE_ID" data-api="https://example.com/your-path/event" src="https://app.supametrics.io/js/ax.js"></script>
```

Your proxy must:

- Forward the request body unchanged (`POST`, sent as `text/plain`).
- Forward the visitor's `User-Agent` header. Requests without one are treated as bots and dropped.
- Put the visitor's IP address first in `X-Forwarded-For`. It is used for rate limits and IP exclusions, and
  is never stored.

Behind a proxy, the country comes from the proxy's location, unless the request carries an
`x-vercel-ip-country` header (Vercel adds it), in which case only the country is recorded, not the region or
city.

When your `data-api` address ends in `/event`, click goals load through the same proxy, from the address with
`/event` replaced by `/config/<site ID>` (for example `https://example.com/your-path/config/YOUR_SITE_ID`).
Forward that `GET` to `https://app.supametrics.io/api/config/<site ID>`. If your proxy doesn't answer it, or your
`data-api` address doesn't end in `/event`, they load from the address the script itself came from.

### Identify signed-in users

When someone signs up or logs in to your app, tell Supametrics who they are:

```js
window.analyticsx?.('identify', { id: user.id, email: user.email, name: user.name });
```

All three fields are optional; send what you have. Later calls fill in missing fields without clearing
earlier ones. The person's name or email then shows on the **Visitors** screen, and you can search by it.
Call it on every login so each browser the person uses is linked to them. See
[Visitors and visitor profiles](https://supametrics.io/docs/visitors).

This is personal data. Mention it in your privacy policy, and with `data-consent="required"` it is only
sent after consent.

### Erase a person (deletion requests)

On the **Visitors** screen, **Erase a person** finds someone by email, user ID or visitor ID across all
time and deletes their visits, goals and identity from every browser they were identified on. Their
payments stay in your revenue, without the link to them. This can't be undone. See
[Privacy and deleting data](https://supametrics.io/docs/privacy-and-data).

### Exclude your own visits

Open your site once with `?ax_ignore=true` at the end of the address (**Site settings › Exclusions** has
an **Exclude this browser** button for this). That browser is never counted again. Do it in each browser you
use; undo with `?ax_ignore=false`. The same tab also excludes traffic by IP address, path, hostname or
country; see [Exclusions](https://supametrics.io/docs/exclusions).

### Installed before the rename

Sites that use the DataFaster snippet (`/js/df.js`, `window.datafaster`) keep working unchanged: same script,
same visitors, same goals. Switch to the snippet above whenever convenient.

## What is collected

Per visit: pages viewed, the referring site, UTM tags (`utm_source`, `utm_medium`, `utm_campaign`,
`utm_term`, `utm_content`) or `?ref=`, country (from the network, not GPS), device, browser and OS, and the
screen size (width and height in pixels, shown next to the device in the visitor drawer).
Clicks on links to other websites are recorded as **exit links** (Details › Pages › Exit links): only the
link's address without its query string, and the page it was clicked on. They don't count toward your plan's events. Personal fields
in URLs such as `?email=` or `?token=` are removed in the browser before anything is sent. Bots and automated
browsers are ignored. Names and emails are stored only if you send them with `identify`.

Traffic from AI assistants (ChatGPT, Claude, Perplexity, Gemini, Copilot and others) is grouped as its own
**AI** channel.

The full list of fields, cookies and rules is in [What Supametrics collects](https://supametrics.io/docs/how-tracking-works). To
record conversions, continue with [Goals](https://supametrics.io/docs/goals); to credit revenue, [Connect Stripe](https://supametrics.io/docs/connect-stripe).
