Insights Script

The Insights script is the easiest way to measure user activity in your browser applications. Once Insights is enabled, you can copy the script URL from the Insights settings page.

Including the script

Once you have the URL at hand, you can include the script in your application by adding the following snippet to your HTML:

<script src="script-url-here" async></script>
html

Initializing the script

Once the script is loaded, you can call the init function to initialize the script.

window.insights.init({
  environmentId: "environment-id-here",
})
js

Tracking user activity

While the Insights script automatically tracks page views, you may want to add additional events to track user activity. You can do this by calling the push function.

window.insights.push({
  category: "category-here",
  kind: "kind-here",
})
js

API

Once loaded, the insights property is attached to the global window object.

declare global {
  interface Window {
    insights?: {
      init: (config: { environmentId: string }) => void;
      identify: (userIdentityId: string) => void;
      push: (event: { category: string; kind: string }) => void;
    };
  }
}
typescript

init

The init function initializes the Insights script. It must be called before any other functions.

identify

The identify function links the current Insights user to a User Management user identity. This allows you to identify users across devices and browsers.

push

The push function pushes an event to the Anzu Insights API. The event will be associated with the current Insights user and session.