Any framework

Not on Next.js? The package is the recommended path for TypeScript apps, but tracking works anywhere with a plain <script> tag pointing at your Zenith service.

On Next.js, React, or any TypeScript app, prefer the package — it's typed, tracks client-side route changes, and sets up the domain-native dashboard. Use the raw snippet only where you can't add a dependency.

The snippet

Add this to your page <head>, with your site's public key:

<script
  src="https://your-zenith-service.com/track.js"
  data-site-key="zk_your_public_site_key"
  data-endpoint="https://your-zenith-service.com/api/collect"
  defer
></script>

That's it — pageviews are recorded, including history changes in single-page apps. It's cookieless and about 1 KB, so no consent banner.

Custom events

The snippet installs a global zenith:

<button onclick="zenith.track('signup', { plan: 'pro' })">Sign up</button>
zenith.track("download", { file: "guide.pdf" });

What you don't get without the package

The raw snippet tracks pageviews and events, but the domain-native dashboard needs the server-side proxy from zenith-analytics/next (or a proxy you write yourself). If you want your client reading analytics on their own domain, you need the package or an equivalent server route — a <script> tag alone can't do it, because the secret api key must never reach the browser.