Install on SvelteKit
View as MarkdownAdd Reveata to a SvelteKit app through src/app.html.
On this page
Every SvelteKit page is rendered from src/app.html, so the snippet goes there once.
Copy the snippet from your Reveata dashboard (it contains your website’s tracking id):
<script
defer
data-website-id="ws_your_tracking_id"
src="https://reveata.com/js/script.js"
></script>Add it to your app
Paste it in the <head> of src/app.html, before %sveltekit.head%:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script defer data-website-id="ws_your_tracking_id" src="https://reveata.com/js/script.js"></script>
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>
</html>This works with every adapter, and on prerendered pages.
SvelteKit changes pages in the browser through the History API, which the script follows, so every page is counted. Preloading a link on hover is not a pageview: only the navigation itself is.
Check it works
Open your deployed site in a private window, then check that the visit appears in your Reveata dashboard. If it doesn’t, follow Verify your installation. Visits to localhost are ignored unless you add data-allow-localhost="true".
Goals
<button data-reveata-goal="signup">Create account</button>
<button onclick={() => window.reveata?.('goal', 'start_trial', { plan: 'pro' })}>
Start free trial
</button>With TypeScript, declare reveata?: (command: string, ...args: unknown[]) => void on Window in src/app.d.ts. A <form> with data-reveata-goal counts its goal when it is submitted, forms with use:enhance included. See Custom goals.
Revenue
Connect your payment provider in Reveata: see Connect a payment provider. When a form action creates the checkout, send window.reveata.metadata() with the form (in hidden inputs) and add it to the checkout metadata.