03Tracking
Install the tracking script
Add the InsightFlare script to your website and learn what it records automatically.
Install
Open the site's settings in the dashboard and find Install Tracking Script. Copy the snippet and add it to every page you want to track:
<script defer src="https://your-instance.example.com/script.js?siteId=YOUR_SITE_ID"></script>- Place it in
<head>, or before</body>if you must, and make sure it loads once per page. A second copy on the same page does nothing and logs an error. - The script is served by your own instance, from
/script.js. - Settings changes you make in the dashboard reach all edge locations within about an hour.
What is recorded automatically
- Page views, including navigation in single-page applications. The script wraps
history.pushStateandhistory.replaceStateand listens topopstateandhashchange. A route change is committed after a short settle delay (300 ms), and only if the tracked route actually changed. - Leaving a page, with the time spent on it and an exit reason.
- Page visibility, when a tab is hidden and shown again. If the page stayed hidden for longer than the session window (30 minutes by default), the next time it is shown starts a new visit.
- Context such as title, hostname, language, time zone, screen size, referrer, and browser client hints.
- Web performance metrics (TTFB, FCP, LCP, CLS, INP) for a sampled share of visits, controlled by the performance sample rate. See tracking settings.
Query strings and URL hashes are included in the recorded route according to your tracking settings.
The window.insightflare API
After the script loads, window.insightflare exposes:
| Member | Purpose |
|---|---|
track(eventName, eventData?) | Report a custom event. |
trackOnce(eventName, eventData?) | Report an event only once per page load. |
setGlobalProperties(props) | Add properties to all later events. |
clearGlobalProperties() | Remove those shared properties. |
identify(userId, { name }) | Associate visits with a signed-in user. |
reset() | End the current identity and start a new anonymous visitor. |
debug() | Log tracked page views, events, and identification to the browser console. |
version, siteId | The tracker version ("6") and the site ID it reports to. |
Do Not Track
By default the script ignores the browser's Do Not Track signal. If you turn off Ignore Browser Do Not Track in the site's tracking settings, visitors whose browser sends Do Not Track are not tracked at all.