Install

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.htmlhtml
<!-- 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

PlatformWhere the tag goes
WordPressA header-scripts plugin, or your theme's header template
ShopifyOnline Store → Themes → Edit code → theme.liquid, before </head>
WebflowSite settings → Custom code → Head code
WixSettings → Custom code → Add code to the head of all pages
SquarespaceSettings → Advanced → Code injection → Header
FramerSite settings → General → Custom code → Start of <head> tag
GhostSettings → Code injection → Site header

Custom events

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

anywhere.jsjs
// Anywhere in your page scripts, after the tag has loaded
window.anyanalytics?.track("signup", { plan: "pro", source: "pricing_page" });
after-login.jsjs
// After someone logs in: link their visits to a user id
window.anyanalytics?.identify("user_123", { email: "[email protected]", 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

AttributeWhat it does
data-keyYour project's write key. Required.
data-cookielessStore nothing in the visitor's browser. See Cookieless mode.
data-cookie-domainThe parent domain that shares the visitor across subdomains, or false to keep each subdomain separate. Detected when left out. See Subdomains.
data-apiSend events to another endpoint, such as a path on your own domain. See Ad blockers and proxies.
data-hostThe address events are sent to, when it isn't the one the script was loaded from.
data-debugLog 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.