Skip to content
Frameworks

SvelteKit analytics with Reveata

1 min read · Updated · By the Reveata team

Short answerPaste the Reveata snippet into the head of src/app.html, before %sveltekit.head%. It works with every adapter and on prerendered pages, and SvelteKit's in-browser navigation is counted automatically. Form actions can pass the visitor id to your checkout through hidden inputs.

SvelteKit renders every page from one template, src/app.html, which makes it one of the easiest frameworks to instrument. The tag goes there once and covers server-rendered, prerendered and client-navigated pages alike.

What you get

  • Every page counted. SvelteKit changes pages through the History API, which the script follows. Preloading a link on hover is not a pageview; only the navigation is.
  • Form goals that survive use:enhance. A <form> with data-reveata-goal counts its goal on submit, enhanced forms included.
  • Revenue attribution from form actions and endpoints that create checkouts.
  • Any adapter: Node, Vercel, Netlify, Cloudflare or static.

How to install it

In src/app.html, paste the snippet in <head>, before %sveltekit.head%:

html
<head>
  <script defer data-website-id="ws_your_tracking_id" src="https://reveata.com/js/script.js"></script>
  %sveltekit.head%
</head>

The template is described in SvelteKit's project structure docs (opens in a new tab). With TypeScript, declare reveata?: (command: string, ...args: unknown[]) => void on Window in src/app.d.ts.

Goals

svelte
<button onclick={() => window.reveata?.('goal', 'start_trial', { plan: 'pro' })}>Start free trial</button>
<form method="POST" use:enhance data-reveata-goal="newsletter">…</form>

See custom goals for properties.

Linking payments to visits

When a form action creates the checkout, send window.reveata.metadata() with the form in hidden inputs named reveata_visitor_id and reveata_session_id, then copy them into the checkout metadata in the action. For Stripe, that is the Checkout Session's metadata (Stripe Checkout attribution); other providers take the same keys in their custom data (connect a payment provider). The action can also read Reveata's _dt_v and _dt_s cookies directly.

Frequently asked questions

Does it work on prerendered pages?

Yes. The tag is part of app.html, so it is in every prerendered file.

Why don't my local visits appear?

The script ignores localhost unless you add data-allow-localhost="true". Test the deployed site.

Can I serve the script from my own domain?

Yes, with the managed proxy or your host's rewrites (proxy through your own server).

See it with your own numbersReveata ties every visit and sale to the source that brought it. Add your website in a minute.
Get started
Was this page useful?
IntegrationStripe Checkout analytics and attributionAdd the Reveata visitor and session ids to the metadata of each Stripe Checkout Session your server creates. When Stripe reports the payment, Reveata reads the ids and credits the money to the exact visit that started the checkout.IntegrationAngular analytics with ReveataPaste the Reveata snippet before the closing head tag of src/index.html. ng build keeps it in the built page, server-side rendering included, and the Angular Router's History API navigation is counted automatically. HashLocationStrategy needs data-hash="true".IntegrationAstro analytics with revenue attributionPaste the Reveata snippet with is:inline into the Astro layout that renders the head of every page. Astro then leaves the tag as written, view transitions are tracked, and payment links or checkouts started from your pages are credited to the visit behind them.IntegrationDjango analytics with revenue attributionPaste the Reveata snippet before the closing head tag of the base template your Django templates extend. Every page is tracked, the Django admin is not, and two hidden form fields let your checkout view put the visitor id into the payment's metadata.IntegrationDocusaurus analytics for documentation sitesAdd the Reveata script to the scripts array in docusaurus.config.js, or build the entry with @reveata/next/snippet. Page changes inside the docs are tracked by the script, so every page a reader opens is counted.IntegrationExpress.js analytics with a first-party proxyPaste the Reveata snippet into the layout, static HTML or front-end index.html your Express app serves. Two Express routes can serve the script from your own domain with your proxy secret, and your checkout route can copy the visitor id into the checkout metadata.