Tag JavaScript API
The methods of window.nextanalytica and the attributes of the tag line, for events, people and consent.
Updated
The tag gives your site one object, window.nextanalytica, for what the tag can't see on its own: your own events, orders, who a signed-in person is and the visitor's consent. Everything else (page views, clicks, forms, scroll, errors, speed) it counts without code, so if that's all you need, you can stop reading here.
The line loads async, so the object exists once the tag has loaded. Code that runs early should check first: window.nextanalytica?.track("signup_completed"). Before consent, the tag counts cookieless: events go, but nothing is kept on the device and nobody is identified. See Cookieless counting and consent.
window.nextanalytica.consent(on)
Tells the tag the visitor's answer from your cookie banner.
| Argument | Type | Description |
|---|---|---|
on | boolean | true when the visitor agreed to analytics, false when they said no. |
window.nextanalytica.consent(true);A yes starts the visitor's first-party id and lets identify work. A no removes everything the tag kept in the tab, on the device and in its cookie. A browser sending Global Privacy Control always counts as no.
window.nextanalytica.track(name, props, value)
Sends one of your own events, such as a sign-up or a demo request.
| Argument | Type | Description |
|---|---|---|
name | string | The event's name, at most 60 characters. Use snake_case: signup_started. |
props | object | Optional. At most 10 properties; keys up to 40 characters, values up to 100. |
value | { value, currency } | Optional. What the event is worth, with a three-letter currency (EUR). |
window.nextanalytica.track("demo_requested", { plan: "team" }, { value: 50, currency: "EUR" });Works before consent. Never put an email, a name or other personal details in props.
window.nextanalytica.order(order)
Records a purchase, so revenue ties to the visit it came from.
| Field | Type | Description |
|---|---|---|
ref | string | Your order's reference, at most 100 characters, so a repeated call counts once. |
value | number | The order's total. |
currency | string | Three capitals: EUR, USD. |
window.nextanalytica.order({ ref: "A-10492", value: 129.9, currency: "EUR" });window.nextanalytica.identify(userId, props)
Names a signed-in person, so their visits on any device make one profile.
| Argument | Type | Description |
|---|---|---|
userId | string | Your own id for the person, never an email. |
props | object | Optional. At most 20 properties, such as plan or company. |
window.nextanalytica.identify("u_4821", { plan: "team" });Does nothing without consent. Call it where people sign in, and on page loads while they are signed in.
window.nextanalytica.group(type, key, props)
Puts the person in a group, such as their company or workspace.
| Argument | Type | Description |
|---|---|---|
type | string | The kind of group: company. |
key | string | The group's id: acme. |
props | object | Optional. At most 20 properties of the group. |
window.nextanalytica.group("company", "acme", { seats: 12 });Does nothing without consent.
window.nextanalytica.setPersonProperties(props)
Updates properties of the identified person without sending an event.
window.nextanalytica.setPersonProperties({ plan: "business" });At most 20 properties. Does nothing without consent.
window.nextanalytica.reset()
Forgets who the person is, on sign-out, so the next person on the same browser starts fresh.
window.nextanalytica.reset();Attributes of the tag line
The tag line carries its settings as attributes. Most projects need only data-project.
<script async src="https://t.nextanalytica.app/t.js" data-project="na_…"></script>| Attribute | Values | What it does |
|---|---|---|
data-project | Your project key | Required. Which project the visits belong to. Copy the whole line from the app or from your agent's get_tag. |
data-consent | granted | The page already has the visitor's consent when it loads. |
data-cookieless | off | Wait for consent before sending anything, instead of counting cookieless. |
data-vitals | all | Measure page speed on every page view, not one in ten. |
data-domains | Your other domains, comma-separated | After consent, links to them carry the visitor. See Subdomains, domains and Safari. |
data-search | URL parameters, comma-separated | Kept for older lines; the current tag sends no site-search events. |