Installation/Script tag

Script tag

The zero code install. One script tag on every page and tracking starts immediately, no build step and no configuration.

Add the snippet

Paste this before the closing </head> tag, with the public key from Site settings → Tracking:

html
<script
  src="https://cdn.jsdelivr.net/npm/@analyse.net/sdk/dist/index.global.js"
  data-public-key="pk_live_your_key"
  defer
></script>

The script initializes itself from the data-public-key attribute. Pageviews and page leave signals are tracked from that point on, including route changes in single page apps.

Options

You can tune the behavior with extra data attributes on the same tag.

AttributeEffect
data-hostSend events to a different ingest host instead of the hosted Analyse endpoint.
data-auto-pageviews="false"Turn off automatic pageview tracking. Call Analyse.page() yourself.
data-auto-page-leave="false"Turn off the automatic page_leave event.

Using the global object

The script exposes a global Analyse object with the full SDK API, so you can track custom events without installing anything:

html
<script>
  Analyse.track("newsletter_subscribed", { placement: "footer" });
  Analyse.identify("user_123");
  Analyse.signedUp({ method: "email" });
</script>

See Custom events and Standard events for what to send.

Note

The snippet is the open source @analyse.net/sdk package served from jsDelivr. If you prefer to serve it from your own domain, download the file and self host it, or use the npm package.