Skip to main content
SvelteKit uses client-side navigation by default. CookieChimp installs in app.html and reinitializes on every navigation via the afterNavigate lifecycle hook.
Before you start: have your CookieChimp Account ID ready (replace YOUR_ACCOUNT_ID in the snippets below). If you're testing on localhost, add localhost to Additional Domains in your Account Settings — otherwise the banner won't show locally.

How do I load the CookieChimp script?

Add the script tag to src/app.html inside <head>, before %sveltekit.head% and any other tags so it loads first:
Replace YOUR_ACCOUNT_ID with your actual CookieChimp Account ID from your dashboard.

How do I handle client-side navigation?

SvelteKit transitions between pages without a full reload. Use afterNavigate in your root layout to re-inject the CookieChimp script on every navigation — this triggers a rescan of the newly mounted route’s DOM. The static <script> tag in app.html handles the first page load, so we skip the initial afterNavigate call.
The browser check guards against SSR — document and window don’t exist on the server, so any DOM access must be wrapped.

Wrap the CookieChimp events in a Svelte store so any component can subscribe:
Use it in a component:
Replace "Google Analytics" and "analytics" with the exact service and category names you configured in CookieChimp.
For all available events, see Callbacks & Events.

Troubleshooting

  • Banner shows on first load but not after navigation — make sure afterNavigate is called from your root +layout.svelte, not from a nested layout.
  • window is not defined / document is not defined errors — wrap any DOM or window access in a browser check from $app/environment.
  • Banner doesn't appear at all — confirm localhost (or your domain) is in Additional Domains in Account Settings.
  • Enable Debug mode in the CookieChimp dashboard and check the browser console for logs.