JavaScript API
View as MarkdownEvery command and method of the tracking script, including payment, reset, decorate and scroll goals with a threshold and delay.
On this page
The tracking script adds window.reveata. Call it after the script has loaded, or add the queue snippet so calls made earlier are kept. No call ever throws into your page.
Commands
| Command | What it does |
|---|---|
reveata('goal', name, props?) |
Records a goal. Names are lowercase letters, digits, _, - and : (for namespaces such as checkout:started), up to 64 characters. Up to 20 properties. |
reveata('identify', { userId, email?, name?, ...props }) |
Links the visitor to your user. See identify visitors. |
reveata('pageview', { url?, props? }) |
Sends a pageview yourself (with data-auto="false", or for virtual pages). |
reveata('payment', { email?, transactionId?, amount?, currency? }) |
On a thank-you page: links the payment that just happened to this visitor. See thank-you page payments. |
reveata('reset') |
On log out: forgets this browser's visitor. The next pageview starts a new visitor and a first visit, so a shared computer doesn't merge two people. Nothing happens in cookieless mode, which stores nothing. |
reveata('optout') / reveata('optin') |
Stops (or resumes) counting this browser. |
Methods
| Method | Returns |
|---|---|
reveata.visitorId() |
The visitor id, or null (cookieless mode, before the first pageview). |
reveata.sessionId() |
The current visit id, or null. |
reveata.metadata() |
{ reveata_visitor_id, reveata_session_id } for checkout metadata, or {}. |
reveata.decorate(url) |
url with Reveata's ids added, for links you open from code. |
decorate(url)
The script adds ids to links people click: the cross-domain id _dt on links to your other domains (data-domains). Stripe Payment Links get a client_reference_id. Links you open from JavaScript are never clicked, so pass them through decorate first:
window.location.href = reveata.decorate('https://shop.example-checkout.com/cart');
window.open(reveata.decorate('https://buy.stripe.com/test_123'));Any other address comes back unchanged, as it does in cookieless mode. The _dt id is only accepted on arrival when the visitor comes from one of your domains within 2 minutes, so a decorated link that gets copied and shared later doesn't carry the visitor along.
Scroll goals
data-reveata-scroll records a goal the first time an element is visible enough:
<section data-reveata-scroll="scroll:pricing">…</section>With the opt-in extras script (script.extras.js) on the page, scroll goals take options:
<section
data-reveata-scroll="scroll:pricing"
data-reveata-scroll-threshold="0.8"
data-reveata-scroll-delay="1500"
data-reveata-scroll-plan="pro">
…
</section>data-reveata-scroll-threshold: how much of the element must be visible, from0to1. The default is0.5. An element taller than the screen can never be fully visible, so keep the threshold below the share of it that fits on screen.data-reveata-scroll-delay: how many milliseconds it must stay visible. If the visitor scrolls away earlier, nothing is sent, and the wait starts again when it comes back.- Any other
data-reveata-scroll-<name>attribute becomes a goal property, with dashes turned into underscores (plan_name).
Each element fires once per page. Without the extras script, the main script fires at half visible, without a delay or properties, so a page never loses its scroll goals. Load the extras script with defer next to the main one (before or after it).
npm and Next.js
The npm packages have the same calls:
import { goal, identify, payment, reset, decorate } from '@reveata/tracker';import { trackGoal, identify, trackPayment, resetVisitor, decorateUrl } from '@reveata/next';Calls made before the script has loaded are queued. decorate and decorateUrl return the address unchanged until then.