Hanzo

Insights Event Catalog

Reference for @hanzo/insights event tracking — standard events, custom events, feature flags, and session recording.

Insights Event Catalog

Hanzo Insights is a self-hosted behavioral analytics platform (fork of PostHog) running at insights.hanzo.ai. The @hanzo/insights-* ecosystem provides 13 packages for browser, server, and framework-specific event tracking.

Platform: insights.hanzo.ai Core SDK: @hanzo/insights (browser) Server SDK: @hanzo/insights-node (Node.js) React SDK: @hanzo/insights-react (hooks and providers) Total Packages: 13 in the @hanzo/insights-* namespace

Package Ecosystem

PackagePurpose
@hanzo/insightsBrowser SDK -- autocapture, pageviews, session recording
@hanzo/insights-nodeServer-side SDK for Node.js
@hanzo/insights-reactReact hooks (useInsights, useFeatureFlag) and <InsightsProvider>
@hanzo/insights-react-nativeReact Native SDK
@hanzo/insights-nextNext.js integration (App Router + Pages Router)
@hanzo/insights-webLightweight web-only variant
@hanzo/insights-js-liteMinimal SDK for bandwidth-constrained environments
@hanzo/insights-androidAndroid SDK
@hanzo/insights-iosiOS SDK
@hanzo/insights-flutterFlutter SDK
@hanzo/insights-pythonPython SDK
@hanzo/insights-rubyRuby SDK
@hanzo/insights-goGo SDK (separate repo: hanzoai/insights-go)

Quick Start

Browser

npmpnpm
npm install @hanzo/insights
pnpm add @hanzo/insights
import insights from '@hanzo/insights';

insights.init('your-project-api-key', {
  api_host: 'https://insights.hanzo.ai',
  autocapture: true,
  capture_pageview: true,
  capture_pageleave: true,
  session_recording: {
    maskAllInputs: true,
  },
});

React

npm install @hanzo/insights @hanzo/insights-react
import { InsightsProvider, useInsights, useFeatureFlag } from '@hanzo/insights-react';

function App() {
  return (
    <InsightsProvider
      apiKey="your-project-api-key"
      options={{
        api_host: 'https://insights.hanzo.ai',
        autocapture: true,
      }}
    >
      <MyApp />
    </InsightsProvider>
  );
}

function MyApp() {
  const insights = useInsights();
  const showNewUI = useFeatureFlag('new-dashboard-ui');

  const handleSignup = () => {
    insights.capture('user_signed_up', {
      plan: 'pro',
      source: 'landing_page',
    });
  };

  return showNewUI ? <NewDashboard /> : <LegacyDashboard />;
}

Server-Side (Node.js)

npm install @hanzo/insights-node
import { Insights } from '@hanzo/insights-node';

const insights = new Insights('your-project-api-key', {
  host: 'https://insights.hanzo.ai',
});

// Capture a server-side event
insights.capture({
  distinctId: 'user-123',
  event: 'api_request',
  properties: {
    endpoint: '/v1/chat/completions',
    model: 'zen-coder-32b-instruct',
    tokens: 1500,
    latency_ms: 340,
  },
});

// Identify a user
insights.identify({
  distinctId: 'user-123',
  properties: {
    email: 'user@example.com',
    plan: 'pro',
    organization: 'acme-corp',
  },
});

// Graceful shutdown
await insights.shutdown();

Standard Events

These events are captured automatically by the browser SDK when enabled.

$pageview

Captured on every page load and client-side navigation.

PropertyTypeDescription
$current_urlstringFull page URL
$pathnamestringURL path without query string
$hoststringHostname
$referrerstringReferrer URL
$referring_domainstringReferrer domain
$screen_heightnumberScreen height in pixels
$screen_widthnumberScreen width in pixels
$viewport_heightnumberViewport height
$viewport_widthnumberViewport width
$browserstringBrowser name
$browser_versionstringBrowser version
$osstringOperating system
$device_typestringDesktop, Mobile, or Tablet

$pageleave

Captured when the user leaves a page (before unload or visibility change).

PropertyTypeDescription
$current_urlstringPage being left
$pathnamestringPath being left
$prev_pageview_durationnumberTime spent on page in seconds
$prev_pageview_last_scrollnumberDeepest scroll position (0-1)

$autocapture

Captured on clicks, form submissions, and input changes when autocapture: true.

PropertyTypeDescription
$event_typestringclick, submit, change, rageclick
$elementsarrayDOM element chain from target to body
$elements[].tag_namestringHTML tag name
$elements[].textstringElement text content (truncated)
$elements[].hrefstringLink href (if applicable)
$elements[].attr__classstringCSS class names
$elements[].attr__idstringElement ID
$elements[].nth_childnumberPosition among siblings
$elements[].nth_of_typenumberPosition among same-type siblings

$identify

Captured when insights.identify() is called to associate an anonymous user with a known identity.

PropertyTypeDescription
$anon_distinct_idstringPrevious anonymous ID
$setobjectProperties to set on the person profile
$set_onceobjectProperties to set only if not already set

$groupidentify

Captured when insights.group() is called to associate a user with a group (organization, company, workspace).

PropertyTypeDescription
$group_typestringGroup type (e.g., organization, company)
$group_keystringGroup identifier
$group_setobjectProperties to set on the group

$feature_flag_called

Captured when a feature flag is evaluated.

PropertyTypeDescription
$feature_flagstringFlag key
$feature_flag_responseanyFlag value (boolean, string, or JSON)

$session_recording

Session recording events (captured continuously when session recording is enabled).

PropertyTypeDescription
$snapshot_dataobjectrrweb recording snapshot
$session_idstringSession identifier
$window_idstringWindow/tab identifier

Custom Events

Capture domain-specific events with insights.capture():

// E-commerce
insights.capture('product_viewed', {
  product_id: 'prod_001',
  product_name: 'AI API Credits',
  price: 49.99,
  currency: 'USD',
  category: 'credits',
});

insights.capture('purchase_completed', {
  order_id: 'ord_abc123',
  total: 149.99,
  currency: 'USD',
  items: [
    { item_id: 'prod_001', quantity: 2, price: 49.99 },
  ],
});

// AI/LLM
insights.capture('model_inference', {
  model: 'zen-coder-32b-instruct',
  tokens_in: 150,
  tokens_out: 500,
  latency_ms: 1240,
  stream: true,
});

insights.capture('agent_task_completed', {
  agent_id: 'agent_xyz',
  task_type: 'code_review',
  duration_ms: 45000,
  tools_used: ['read_file', 'grep', 'edit'],
  success: true,
});

// User lifecycle
insights.capture('onboarding_step_completed', {
  step: 3,
  step_name: 'connect_repository',
  total_steps: 5,
  duration_seconds: 45,
});

Feature Flags

Evaluate feature flags for gradual rollouts and A/B testing:

// Boolean flag
if (insights.isFeatureEnabled('new-checkout-flow')) {
  renderNewCheckout();
}

// Multivariate flag
const variant = insights.getFeatureFlag('pricing-experiment');
switch (variant) {
  case 'control':
    showOriginalPricing();
    break;
  case 'variant-a':
    showDiscountedPricing();
    break;
  case 'variant-b':
    showUsageBasedPricing();
    break;
}

// Flag with payload (JSON)
const config = insights.getFeatureFlagPayload('dashboard-layout');
// { "columns": 3, "showSidebar": true, "theme": "dark" }

React Feature Flags

import { useFeatureFlag, useFeatureFlagPayload } from '@hanzo/insights-react';

function Dashboard() {
  const showNewNav = useFeatureFlag('new-navigation');
  const layoutConfig = useFeatureFlagPayload('dashboard-layout');

  return (
    <div>
      {showNewNav ? <NewNavigation /> : <LegacyNavigation />}
      <DashboardGrid columns={layoutConfig?.columns ?? 2} />
    </div>
  );
}

Experiments

Run A/B tests with automatic statistical significance tracking:

// Experiments use feature flags under the hood
const experiment = insights.getFeatureFlag('signup-cta-experiment');

// Track the conversion metric
insights.capture('signup_completed', {
  experiment_variant: experiment,
});

Experiments are configured in the Insights UI at insights.hanzo.ai with:

  • Minimum sample size calculation
  • Bayesian or frequentist significance testing
  • Automatic winner detection
  • Holdout groups

Session Recording

Capture full session replays with privacy controls:

insights.init('your-api-key', {
  api_host: 'https://insights.hanzo.ai',
  session_recording: {
    maskAllInputs: true,          // Mask all input values
    maskTextSelector: '.sensitive', // Mask elements with this class
    blockSelector: '.no-record',   // Block elements entirely
    recordCrossOriginIframes: false,
  },
});

Session recordings capture:

  • DOM mutations (via rrweb)
  • Mouse movements and clicks
  • Scroll events
  • Network requests (optional)
  • Console logs (optional)
  • Performance metrics

Super Properties

Set properties that are automatically included with every event:

// Set once (persisted in localStorage)
insights.register({
  app_version: '2.4.1',
  environment: 'production',
  deployment: 'us-east-1',
});

// Set per-session only
insights.registerForSession({
  ab_test_group: 'variant-b',
});

// Unregister
insights.unregister('ab_test_group');

Person Properties

Set properties on the identified user profile:

insights.identify('user-123', {
  $set: {
    email: 'user@example.com',
    plan: 'pro',
    company: 'Acme Corp',
    signup_date: '2026-01-15',
  },
  $set_once: {
    first_seen: new Date().toISOString(),
    original_referrer: document.referrer,
  },
});

Group Analytics

Track organization or workspace-level metrics:

// Associate user with a group
insights.group('organization', 'org-acme', {
  name: 'Acme Corporation',
  plan: 'enterprise',
  employee_count: 500,
  industry: 'technology',
});

// Events are now tagged with this group
insights.capture('api_key_created', {
  key_type: 'production',
});
// This event is attributed to both user-123 AND org-acme

Configuration Reference

Browser SDK Options

OptionTypeDefaultDescription
api_hoststringhttps://insights.hanzo.aiInsights server URL
autocapturebooleantrueAuto-capture clicks, forms, page changes
capture_pageviewbooleantrueAuto-capture $pageview events
capture_pageleavebooleantrueAuto-capture $pageleave events
cross_subdomain_cookiebooleantrueShare identity across subdomains
persistencestringlocalStorage+cookieStorage method for identity
session_recordingobject{}Session recording configuration
disable_session_recordingbooleanfalseDisable session recording entirely
mask_all_textbooleanfalseMask all text in session recordings
mask_all_element_attributesbooleanfalseMask all HTML attributes
loadedfunction--Callback after SDK initialization
bootstrapobject--Pre-load feature flags and distinct ID
advanced_disable_decidebooleanfalseSkip /decide call (disables autocapture config)

Server SDK Options

OptionTypeDefaultDescription
hoststringhttps://insights.hanzo.aiInsights server URL
flushAtnumber20Events per batch
flushIntervalnumber10000Flush interval in ms
personalApiKeystring--Personal API key for feature flag evaluation
featureFlagsPollingIntervalnumber300000Flag refresh interval in ms

Platform-level usage and cost analytics (distinct from Insights behavioral analytics)

Commerce event catalog for order and checkout tracking

AI training data collection (distinct from behavioral analytics)

LLM observability with tracing and prompt management

How is this guide?

Last updated on

On this page