Documentation
03Tracking

Custom events

Report your own events with track() and attach structured data.

Custom events record actions that are not page views, such as a sign-up click or a completed purchase.

Report an event

Call track after the page has loaded. The script starts the first visit when the document finishes loading, and events reported before that are dropped, so wait for DOMContentLoaded if you call it from inline code:

<script defer src="/script.js?siteId=YOUR_SITE_ID"></script>
<script>
  window.addEventListener("DOMContentLoaded", () => {
    window.insightflare.track("signup_click", {
      plan: "pro",
      source: "pricing",
    });
  });
</script>

You can also report events without writing JavaScript. See DOM attributes.

Methods

MethodBehavior
track(eventName, eventData?)Reports an event. The name is trimmed and an empty name is ignored.
trackOnce(eventName, eventData?)Reports the event only the first time that name is used during the current page load. The memory is kept for the life of the page, including route changes in a single-page application.
setGlobalProperties(props)Merges properties into a shared set that is added to every later event.
clearGlobalProperties()Empties the shared set.

When an event is sent, the payload is the shared properties merged with the eventData you pass. Values you pass override shared properties with the same key.

Event data

eventData must be a JSON object. Each event is validated when it is received, and an event that breaks one of these limits is rejected rather than truncated:

LimitValue
Total serialized size8 KB
Nodes (all keys and values)200
Values100
Nesting depth6
Array length50
Key length120 characters
String value length500 characters

Event names are trimmed and cut to 120 characters. Numbers must be finite and no larger than 9007199254740991 in absolute value, and values must be JSON-serializable. Objects and arrays are allowed, and the dashboard analyzes them field by field. See events.

Debugging

Call window.insightflare.debug() to log page views, events, and identification to the browser console while you test.