# Websites

> Track any website with one script tag: pageviews, outbound clicks and custom events.

One line of HTML tracks any website: pageviews (including client-side navigation in single-page apps), where visitors come from, and clicks on links to other sites. It's about 5 KB and loads without blocking the page.

## Install the tag

Paste this into the `<head>` of every page. Your project's setup page shows it with your write key filled in.

`index.html`:

```html
<!-- AnyAnalytics: pageviews are tracked automatically -->
<script defer src="https://api.anyanalytics.org/script.js" data-key="vxw_YOUR_WRITE_KEY"></script>
```

### Site builders and CMSs

| Platform | Where the tag goes |
| --- | --- |
| WordPress | A header-scripts plugin, or your theme's header template |
| Shopify | Online Store → Themes → Edit code → theme.liquid, before </head> |
| Webflow | Site settings → Custom code → Head code |
| Wix | Settings → Custom code → Add code to the head of all pages |
| Squarespace | Settings → Advanced → Code injection → Header |
| Framer | Site settings → General → Custom code → Start of <head> tag |
| Ghost | Settings → Code injection → Site header |

## Custom events

The tag exposes `window.anyanalytics`. Track anything visitors do, and identify them once they sign in:

`anywhere.js`:

```ts
// Anywhere in your page scripts, after the tag has loaded
window.anyanalytics?.track("signup", { plan: "pro", source: "pricing_page" });
```

`after-login.js`:

```ts
// After someone logs in: link their visits to a user id
window.anyanalytics?.identify("user_123", { email: "ada@example.com", plan: "pro" });
```

> **Tip**
>
> Use the optional chaining (`anyanalytics?.track`) shown above: if the tag is blocked or hasn't loaded yet, your own code keeps working.

## What's tracked automatically

- `$pageview` on load and on every client-side navigation, with the path, title, referrer and UTM tags.
- `$outbound_click` when a visitor clicks a link to another site, with the URL and domain.
- Browser, operating system, device type and approximate location.
- Ad click ids (`gclid`, `msclkid`…) are recorded by name only, so paid traffic is recognized without storing the id.

URL fragments and query parameters other than `utm_*` and `ref` are removed from recorded URLs, since they often contain tokens or personal data.

## Subdomains

Put the same tag on `example.com`, `shop.example.com` and `blog.example.com` and a person moving between them stays one visitor with one session. The tag keeps their anonymous id and session in a first-party cookie on your parent domain, which it finds on its own (the widest domain the browser accepts, so `example.co.uk` for `shop.example.co.uk`). Visitors who were tracked before keep their id.

- `aa_` followed by the start of your write key holds the random anonymous id for a year. Your user ids are never put in cookies: once a visitor signs in on any subdomain, their anonymous id is linked to them.
- The same name ending in `_s` holds the current session and expires after 30 minutes without activity.

To pin the domain, set `data-cookie-domain="example.com"`. To keep each subdomain separate, set `data-cookie-domain="false"`. Cookieless mode sets no cookies.

## Options

| Attribute | What it does |
| --- | --- |
| `data-key` | Your project's write key. Required. |
| `data-cookieless` | Store nothing in the visitor's browser. See [Cookieless mode](https://anyanalytics.org/docs/privacy.md#cookieless). |
| `data-cookie-domain` | The parent domain that shares the visitor across subdomains, or `false` to keep each subdomain separate. Detected when left out. See [Subdomains](https://anyanalytics.org/docs/websites.md#subdomains). |
| `data-api` | Send events to another endpoint, such as a path on your own domain. See [Ad blockers and proxies](https://anyanalytics.org/docs/ad-blockers.md). |
| `data-host` | The address events are sent to, when it isn't the one the script was loaded from. |
| `data-debug` | Log everything the tag does to the browser console. |

## Exclude your own visits

Open any page of your site with `?anyanalytics_ignore=true` once: that browser stops being tracked, on every subdomain of your site. Use `?anyanalytics_ignore=false` to undo it. To exclude a whole office or team, add its IP addresses in the project's **Settings → Traffic filters**. Automated browsers are never tracked.

## Prefer npm?

For apps with a build step you can install the same tracker from npm instead and control it from your code. See the [JavaScript SDK](https://anyanalytics.org/docs/javascript.md).

---

Web version: https://anyanalytics.org/docs/websites. All docs: https://anyanalytics.org/docs.md
