Skip to content

Install the tracker

The tracker is a small JavaScript file that you add to every page of your website. It records page views, goals, outbound link clicks, payments and identities, and sends them to the tracking worker that runs in your own Cloudflare account. Everything you see under Analytics (dashboard, realtime, insights, visitors, funnels) is built from these events.

This page is the task-oriented guide: which snippet to paste, where, which options exist and how to check that it works. The exact wire format of every event (POST /e, POST /e/server, every field and limit) is documented for developers in Tracker protocol.

Where to find the snippet:

  • Analytics › Overview, toolbar Settings button, then the Tracking tab
  • URL: /t/<workspace>/analytics/settings?tab=tracking
  • Right after you create a site, the {name} is ready dialog also shows the recommended snippet once, together with the site secret.

Before you start you need a site (a website you track, with its allowed hostnames). If the workspace has none, Analytics › Overview shows Track your first website with an Add a site button. See Analytics settings › Sites and Sites.

The recommended snippet has two lines:

<script>window.amable=window.amable||function(){(window.amable.q=window.amable.q||[]).push(arguments)};</script>
<script defer data-site="st_xxxxxxxxxxxxxxxxxxxx" src="https://<tracking-host>/s.js"></script>
  1. The first line installs a tiny queue stub called window.amable. Calls you make before the real script has loaded (for example a goal fired by an inline button handler) are kept in a queue and replayed as soon as the tracker starts.
  2. The second line loads the tracker with defer, so it never blocks the rendering of your page. data-site is the site key (st_ followed by 20 characters): it is public and it is the only required attribute.

The script is served by the tracking worker of your installation (the <tracking-host> above is the public address configured for it). It is cached by browsers for one hour and revalidated in the background, so new tracker versions reach visitors within a day without any change on your side.

When the tracker starts it immediately sends a page view of the current page, then listens for navigation, clicks and form fields as described below. Events are sent with navigator.sendBeacon (or fetch with keepalive as a fallback), so they are delivered even when the visitor leaves the page.

The Tracking snippet card offers four tabs. All of them use the same site key.

Tab Script URL When to use it
Recommended /s.js, or /s.cookieless.js if the site is cookieless Default choice. Includes the queue stub. “Paste it in the <head> of every page. The queue stub records goals sent before the script loads.”
Script only /s.js The plain script tag without the queue stub. “The plain script tag, without the pre-load queue.” Use it only if you never call amable(...) before the script has loaded.
Cookieless /s.cookieless.js “Stores nothing in the browser: no consent banner needed in most jurisdictions.” See Cookies and cookieless mode.
Hash routing /s.hash.js “For single-page apps that route with #hash URLs.” Tracks #/route changes as page views and keeps the #/… part in the recorded path.

The Recommended tab automatically picks the cookieless script when the site has Cookieless switched on in its settings. Snippets you already pasted keep working when you change the switch later: the standard and hash-routing scripts ask the server for the site’s mode before writing any cookie (see Cookies and cookieless mode).

The tracker switches itself off, silently, in these cases (no event is ever sent):

Situation Why How to allow it
The script tag has no data-site No site to report to Add data-site.
The browser opted out (see Opt out a browser) The visitor or you excluded this browser amable('optin')
The browser looks automated: navigator.webdriver is set, the user agent contains words such as bot, crawl, spider, headless, selenium, puppeteer, playwright, lighthouse, pagespeed, prerender, curl/, wget, or automation globals are present Bots never become visitors Not possible.
The page runs inside an iframe Embedded pages are not counted by default Add data-allow-iframe to the script tag.
The page is on localhost, *.localhost, 127.0.0.1, ::1, 0.0.0.0 or a file: URL Development traffic is not counted by default Add data-allow-localhost to the script tag and switch on Allow localhost in the site settings.

On the server side, every event is checked again:

  • The page URL and the Origin (or Referer) of the request must be one of the site’s Hostnames or one of their subdomains. Anything else is rejected with 403 origin_not_allowed.
  • The user agent is matched against a list of known crawlers and bots (AI assistants, model-training crawlers, search engine indexers, SEO tools, link-preview bots, uptime monitors) and against generic patterns. An empty user agent, or one that does not start like a real browser (Mozilla/ or Opera/), is also treated as a bot. Bot hits are counted separately in the Bot traffic card of the dashboard and never create visitors, sessions or page views.

With the default script, the tracker keeps a random visitor id and a session id in first-party cookies on your site’s own domain:

  • A session ends after 30 minutes without activity. The session cookie is renewed on every event, so a visitor who keeps browsing stays in the same session.
  • The visitor id lasts 365 days and is renewed on every visit.
  • The tracker also remembers the visitor’s first-seen time and how many sessions they had, so the first channel and the session number are right even across many visits.

With the cookieless script, or with any script when the site is set to Cookieless, nothing is stored in the browser and the server derives the visitor id from a hash of a daily random salt, the site, the IP address and the user agent. A new session starts after 30 minutes without events. Because the salt changes every day (UTC), the same person is a new visitor every day and cannot be followed across days. See Cookies and cookieless mode.

Data Source Notes
Page URL and path location.href The #hash is dropped, except with the hash-routing script (#/route only). Paths are stored up to 1,024 characters.
Referrer document.referrer Kept only when it is external: navigation between your own hostnames is not a referrer.
UTM and source parameters Landing URL utm_source, utm_medium, utm_campaign, utm_term, utm_content, ref, source, via.
Ad click ids Landing URL gclid, fbclid, msclkid, ttclid, twclid, li_fat_id, wbraid, gbraid.
Language, time zone, viewport and screen size Browser Language and screen width are stored on the session.
Country, region, city, approximate coordinates Cloudflare network location of the request Derived at the edge; the IP address itself is not stored.
Browser, operating system, device class User agent Device is desktop, mobile or tablet.
Channel Referrer, UTM parameters and click ids Classified once per session, see Analytics dashboard › Channels.
  • Outbound links. A click on a link that points to another hostname is recorded as an exit link (shown in the Pages › Exit link tab of the dashboard). Add data-no-external-links to the script tag to turn this off.
  • Email and phone capture. The tracker watches form fields and sends an identify event with the email address and/or phone number as soon as a visitor fills a recognised field and leaves it, and again on submit. A field is recognised when it is a text, email or tel input whose type, autocomplete, name or id suggests an email or a phone number. Password, card, CVC/CVV, IBAN, secret and one-time-code fields are never read. Each value is sent once per page. This is how anonymous visitors become identified and get linked to your CRM contacts. Turn it off for the whole page with data-no-forms, or for one form or field by adding the data-amb-ignore attribute to it or to a parent element.
  1. Open Analytics › Overview and click Settings in the toolbar, then open the Tracking tab. If you have several sites, pick the right one in the Site menu of the toolbar.

  2. In the Tracking snippet card, keep the Recommended tab selected and click Copy.

  3. Paste the snippet inside the <head> element of every page of your site, before any code that calls amable(...). On a website builder or CMS, use its “custom code in head” or “header scripts” setting so it is added to all pages at once.

  4. Publish your site, then open it in a normal browser window (not a private window with strict tracking protection, not an ad-blocking browser profile).

  5. Back on the Tracking tab, click Check again in the Installation card. When the badge says Receiving events, the installation works.

  1. For apps that change the URL with the History API (most modern routers), use the Recommended snippet: the tracker wraps history.pushState and listens to popstate, so every route change is a page view.

  2. For apps that route with #/path URLs, copy the snippet from the Hash routing tab instead.

  3. If your router changes the page with history.replaceState only, or you render a “virtual page” without changing the URL, send the page view yourself after the new content is shown:

    amable('pageview');

The tracker ignores a second page view of the same URL within 60 seconds, because many routers fire the navigation twice. A real reload after a minute is counted again.

Goals are named events such as signup, demo_request or download_pricing. You do not create goals in the app: a goal exists as soon as your site sends it once, and from then on it appears in the Conversions card, can be used as a filter, a funnel step or an alert.

amable('goal', 'signup');
amable('goal', 'download', { file: 'pricing.pdf', plan: 'pro' });

Goal names are normalised: lower case, spaces and dashes become _, only a-z, 0-9 and _ are kept, at most 64 characters. A goal can carry up to 10 parameters; keys follow the same rule as names and values are cut at 255 characters.

If your checkout does not run through the amabledata e-commerce module, report each sale from the thank-you page:

amable('payment', {
amount: 49.90, // major units
currency: 'EUR', // ISO 4217
transaction_id: 'ORD-10293',
email: 'jane@example.com' // optional
});
Field Required Notes
amount Yes Number in major units (49.90), not negative.
currency Yes Three-letter code. Only payments in the site currency count as revenue.
transaction_id Yes Your order or payment id. A payment with an id already recorded is ignored, so reloading the thank-you page never double counts.
email No Links the payment to the buyer’s identity.
customer_id No Your own customer id.
renewal No true for a subscription renewal.
refunded No true for a full refund of a transaction already sent: its revenue is removed.
is_free_trial No true for a free trial start: recorded as the free_trial goal, not as a purchase.

Every new payment also adds a payment goal (or free_trial) to the visitor. Payments recorded in the CRM or the e-commerce module reach analytics automatically and do not need this call. To report payments from your backend instead of the browser, use the server endpoint below.

When a visitor signs in or gives you their details, tell the tracker who they are:

amable('identify', {
user_id: 'u_8812',
email: 'jane@example.com',
name: 'Jane Doe',
plan: 'pro' // any other key is stored as a trait
});

At least one of user_id, email or phone is required. Other keys (up to 10 keys in total) are saved as traits on the visitor profile. When the email matches an existing contact of your CRM, the visitor is linked to that contact on the next synchronisation (every few minutes): their sessions then appear on the contact’s Website journey. Identify never creates a contact.

Server-side events are useful for payments confirmed by your payment provider, goals that happen in your backend, or page views of pages that do not run JavaScript.

  1. Copy the Server endpoint shown under the snippet (it ends with /e/server).

  2. Use the site secret (amb_sk_…) as a Bearer token. The secret is shown only once, when the site is created or when you click Roll secret on the Sites tab.

  3. Send JSON with Authorization: Bearer amb_sk_…:

    Terminal window
    curl -X POST https://<tracking-host>/e/server \
    -H "Authorization: Bearer amb_sk_st_xxxxxxxxxxxxxxxxxxxx.xxxxxxxx" \
    -H "Content-Type: application/json" \
    -d '{"type":"payment","amount":49.9,"currency":"EUR","transaction_id":"ORD-10293","email":"jane@example.com"}'

Server events accept the types goal, payment, identify, pageview and crawler. Goals and identify need the visitor_id of the browser visitor (read it from the amb_vid cookie). The full schema of each type is in Tracker protocol. An alternative with fine-grained scopes is a site API key on the Keys tab.

Crawlers (AI assistants, model-training bots, search engines) do not run JavaScript, so the browser tracker never sees them. To count them:

  1. On the Tracking tab, find the AI crawler tracking (server side) card.

  2. Pick Worker (a Cloudflare Worker route in front of your site), Node (an Express/Connect middleware, Node 18 or later) or PHP (included at the top of index.php).

  3. Copy the code and replace the placeholder amb_sk_REPLACE_WITH_SITE_SECRET with your site secret (store it as a secret or environment variable named AMABLE_SECRET).

  4. Deploy. Each GET request from a bot user agent is reported in the background (user agent, client IP and URL only). The report never blocks or slows the page: it is fire-and-forget with a short timeout.

For bots that publish their IP ranges (for example Googlebot, Bingbot, GPTBot, ChatGPT-User, OAI-SearchBot, ClaudeBot, Claude-User, Applebot, DuckDuckBot), the IP is checked: hits are counted as verified (IP in the provider ranges) or spoofed (user agent from an unexpected IP). Other bots are neither.

If one visit can move between two of your domains (for example example.com and shop-example.net), add both to the site’s Hostnames and list the other domains on the script tag:

<script defer data-site="st_xxxxxxxxxxxxxxxxxxxx" data-cross-domain="shop-example.net,example.org"
src="https://<tracking-host>/s.js"></script>

Links to those domains (and their subdomains) are decorated with the visitor and session ids, so the visit continues on the other domain as the same visitor and session. The ids are removed from the address bar right after they are read, and a decorated link older than 10 minutes is ignored, so a copied or shared link never merges two people.

To exclude your own visits, or to offer visitors an opt-out link, call:

amable('optout'); // stop tracking this browser
amable('optin'); // track it again

The choice is stored in the browser’s local storage (amable_ignore) and is respected on every later visit, until optin or until the browser storage is cleared.

  1. Open the Tracking tab and look at the Installation card. It shows:

    • Receiving events (green) when the site received at least one event in the last 24 hours, otherwise Waiting for the first event with the hint “Open your site in a browser after adding the snippet, then check again.”
    • Last event: when the last browser event arrived, or never.
    • Last URL: the page of that event.
    • Events (24 h): page views plus goals of the last 24 hours.
    • Hostnames: the hostnames the site accepts.
  2. Click Check again to refresh the card after visiting your site.

  3. For a deeper check, open your site with the browser developer tools on the Network tab: you should see s.js loaded with status 200 (or 304) and a POST request to /e answered with 202 on every page view.

  4. Open Analytics › Realtime: your own visit appears in Live feed within seconds.

Until the first event arrives, the dashboard shows a Waiting for the first event banner with a Get the snippet button that opens this tab.

Attribute Default Effect
data-site (required) Site key (st_…). Without it the tracker does nothing.
data-api <script origin>/e Endpoint the events are sent to. Change it only if you proxy the endpoint yourself.
data-domain Root domain of the page Domain of the cookies. The tracker finds the registrable root domain itself (for example example.co.uk for www.example.co.uk), so subdomains share the visitor. Set it to keep visitors separate per subdomain.
data-cross-domain none Comma-separated hostnames whose links carry the visitor across domains.
data-allow-localhost off Also track localhost pages (the site must allow localhost too).
data-allow-iframe off Also track pages loaded inside an iframe.
data-no-external-links off Do not record outbound link clicks.
data-no-forms off Do not capture email and phone numbers from form fields.

All commands go through window.amable(...) (also available as window.amb). Unknown commands are ignored.

Command Arguments What it does
amable('pageview') none Sends a page view of the current URL (deduplicated within 60 seconds).
amable('goal', name, params) Goal name; optional object of up to 10 parameters Sends a goal.
amable('payment', data) See Record a payment Records a payment.
amable('identify', data) user_id, email, name, other traits Identifies the visitor.
amable('conversion', data) value, currency, tx Funnel conversion of the visual funnel tracking, sent as the goal conversion. See Tracking links.
amable('context', data) f, ts, n, p, vid Sets the funnel context of the page. See Tracking links.
amable('optout') / amable('optin') none Excludes or re-includes this browser.
Attribute On Effect
data-amable-goal="name" Any element Sends the goal on click.
data-amable-goal-<key>="value" Same element Adds a goal parameter.
data-amable-scroll="name" Any element Sends the goal when the element scrolls into view.
data-amable-scroll-threshold Same element Visible share, 0–1, default 0.5.
data-amable-scroll-delay Same element Milliseconds of visibility, default 0.
data-amb-ignore Form, field or any parent No email/phone capture inside it.
Parameter Effect
utm_source, utm_medium, utm_campaign, utm_term, utm_content, ref, source, via Source and campaign of the session.
gclid, fbclid, msclkid, ttclid, twclid, li_fat_id, wbraid, gbraid Ad click ids, stored on the session. All except fbclid mark the session as paid traffic (fbclid is also added to organic Facebook links).
he Email of the visitor (plain or SHA-256), added by tracked email links. It is removed from the address bar and from the stored URL.
el, sl Email label (puts the session on the Email channel) and custom source label, added by tracked links.
_amb_c Signed contact token of an email click: links the visitor to the contact. Removed from the address bar.
_amb_vid, _amb_sid, _amb_fs, _amb_sn, _amb_ts Cross-domain handoff. Removed from the address bar.

See Email links for how email clicks carry these parameters.

Name Kind Lifetime Content
amb_vid First-party cookie 365 days Random visitor id
amb_fs First-party cookie 365 days First-seen time of the visitor
amb_sn First-party cookie 365 days Session number
amb_sid First-party cookie 30 minutes, renewed on activity Random session id
amb_dl Session storage Browser tab session Funnel context of a funnel page (only on pages reached through funnel tracking links)
amable_ignore Local storage Until removed Opt-out flag

Cookies are set with SameSite=Lax, path=/, on the root domain, and Secure on HTTPS pages. They contain random ids only, never personal data.

The cookieless script writes nothing at all to the browser (no cookie, no session storage). The server counts visitors with a SHA-256 hash of a random salt, the site, the IP address and the user agent. The salt is random per site and per UTC day, kept only inside your installation and deleted after two days, so the hash cannot be recomputed from an IP later and the same person cannot be linked across days. Consequences:

  • Visitors are unique per day: a person who comes back tomorrow is a new visitor, so session counts per visitor, visitor profiles and identity linking across days are not meaningful.
  • Cross-domain handoff and funnel context across pages are not available.

You do not have to change the snippet when you switch Cookieless on or off. The standard (/s.js) and hash-routing (/s.hash.js) scripts check the site’s mode every time they load, before they write anything:

  1. The script asks the tracking server whether the site is cookieless (a GET request to the events endpoint with ?site=<site key>, sent without cookies).
  2. If the answer is cookieless, the script runs exactly like the cookieless script: it writes no cookie, sends every event as cookieless, and expires the amb_vid, amb_fs, amb_sn and amb_sid cookies that an earlier visit may have left on your domain.
  3. If the site uses cookies, if the server does not know the site, or if no answer arrives within 3 seconds (offline, blocked request), the script keeps using cookies as usual.

amable(...) calls made while the script waits for the answer are queued and sent once it starts, so no goal is lost. Opted-out browsers and browsers that look automated skip the check entirely (they are never tracked anyway). The cookieless script never asks: it is always cookieless.

After you change the switch, allow a few minutes before every visitor sees the new mode: the tracking server picks up site settings within about a minute, and browsers may reuse the mode answer for up to 5 minutes. Meanwhile, the server already treats every event of a cookieless site as cookieless, whatever the browser sends.

amabledata has no built-in consent banner. If your jurisdiction requires consent for analytics cookies, either use the cookieless variant or load the snippet only after the visitor has accepted, through your consent tool.

  • IP addresses are used only while an event is processed: for the location lookup done by Cloudflare, for the daily cookieless hash and to verify crawler IP ranges. They are not stored with sessions, page views or visitors.
  • Emails and phone numbers are stored only when your site sends them (identify, payment, form capture, he link parameter).
  • Each site’s data lives in its own storage inside your Cloudflare account. Raw events older than the site’s Retention (days) are removed every day (see Analytics settings › Sites).
  • There is no sampling: every accepted event is stored and counted.

Some ad blockers and privacy browsers block well-known analytics script names or third-party hosts. The tracker is served from your installation’s own tracking worker, not from a shared third-party service, which already avoids most block lists. To make it fully first-party, add a tracking domain such as track.example.com and, once it is Active, replace the host of the script URL with it:

<script defer data-site="st_xxxxxxxxxxxxxxxxxxxx" src="https://track.example.com/s.js"></script>

The events endpoint follows the script automatically (https://track.example.com/e). Visitors whose browser still blocks the script are simply not counted; nothing breaks on your page.

Limit Value
Event body 16 KB
Page URL, referrer 2,048 characters
Goal name, parameter keys 64 characters, a-z 0-9 _
Goal parameters 10 per goal (20 data keys accepted by the endpoint)
Parameter values 255 characters from the tracker
Hostnames per site 20
Action Permission Roles that have it by default
See the Tracking tab, copy snippets, run the install check analytics:read Owner, Admin, Marketer, Analyst, Viewer
Create a site, change Cookieless / Allow localhost / Hostnames, roll the site secret analytics:configure Owner, Admin, Marketer

See Roles and permissions.

Symptom Cause Fix
Waiting for the first event never changes The snippet is not on the page, the page is cached by a CDN or plugin with the old HTML, or you visit it from an ad-blocking or automated browser View the page source and look for data-site. Purge your site cache. Test from a normal browser window.
POST /e answers 403 with origin_not_allowed The page hostname is not in the site’s Hostnames Add the hostname (subdomains are covered by their parent, so example.com also covers www.example.com). Changes take up to a minute to reach the tracking worker.
POST /e answers 404 with unknown_site Wrong data-site, or the site was deleted Copy the snippet again from the Tracking tab.
POST /e answers 400 with invalid_event A goal name with invalid characters, a payment without amount, currency or transaction_id, an identify without user_id/email/phone Fix the call; see the field tables above.
POST /e answers 413 with payload_too_large The event is over 16 KB Send fewer or shorter parameters.
Nothing is sent on localhost Local pages are ignored by default Add data-allow-localhost to the script tag and switch on Allow localhost for the site.
Nothing is sent inside an embedded widget Iframes are ignored by default Add data-allow-iframe.
Route changes of a single-page app are missing The router uses replaceState or hash URLs Use the Hash routing snippet, or call amable('pageview') after each route change.
Goals fired early on the page are lost The Script only variant has no queue Use the Recommended snippet.
POST /e/server answers 401 with invalid_site_secret Missing or wrong secret, or the secret was rolled Use the current secret as Authorization: Bearer amb_sk_….
Payments do not show as revenue The payment currency differs from the site Currency Send payments in the site currency, or change the site currency.
Every visitor is “new” every day The site is cookieless Expected: cookieless visitors are counted per day.
amb_ cookies are still written after you switched Cookieless on Browsers may reuse the previous mode answer for up to 5 minutes, and the tracking server picks up the change within about a minute Wait a few minutes and reload; on the next page load the script expires the old cookies.
The browser’s network panel shows a GET /e?site=… request before the page view The standard or hash-routing script checks whether the site is cookieless Expected. Use the cookieless script if you want to avoid the extra request on a cookieless site.