Tracking API

Add the heft.io script to your site to track page views automatically. Additionally, you can use the JavaScript API to send custom events (e.g. sign-ups, button clicks).

Script tag

Include the lib.js script once in your HTML, ideally in <head> with defer. Replace YOUR-SITE-ID with your site’s UUID from the heft.io dashboard.

Optional attributes:

The script must be loaded via a <script> tag; it reads data-site-id from that element. Page views are sent on load and on history changes (e.g. client-side navigation).

Custom events

After the script has loaded, call window.heft.track(eventName, properties) to send a custom event.

Each call sends one event to your endpoint with the current URL and referrer. Properties are stored with the event for filtering and breakdowns in the dashboard.

Referrer is captured for cross-origin traffic only. Same-origin referrers are intentionally not sent.

Stored page URL

Non-attribution query parameters are removed before the URL is sent. Allowed parameters are ref, source, and the standard utm_* keys. The URL fragment (#...) is kept so it matches the browser (including hash-only routing with data-track-hash-routing).

Disable and enable

To stop tracking (e.g. during local testing or to avoid spamming analytics), call window.heft.disable(). The tracker writes a flag to localStorage so no pageviews or events are sent until you call window.heft.enable() again.

Page visitors can also run window.heft.disable() in the console if they wish to explicitly opt out of heft.io tracking on the site. The flag persists across page loads in the same browser profile. Browsers that block localStorage (e.g. some private-browsing modes) cannot persist the opt-out — a console warning is shown in that case.

Both functions log a short message in the console explaining the effect and how to revert.

Last updated: July 2026