Skip to main content

Overview

track() is the core function of Analytiq. Call it whenever something meaningful happens in your app — a page visit, a button click, a purchase, a form submission. Each event gets saved to your dashboard instantly.

Signature

track(eventName: string, properties?: EventProperties): void

Parameters

ParameterTypeRequiredDescription
eventNamestringYesName of the event. Use lowercase with underscores: page_view, button_click
propertiesobjectNoKey-value pairs with extra data about the event

Properties value types

Properties can only contain these value types:
TypeExample
string'home', 'pro', 'google'
number29, 3, 100
booleantrue, false
nullnull

Examples

Simple event — no properties:
track('page_view')
Event with properties:
track('page_view', {
  page: 'Home',
  path: '/home'
})
Button click:
track('button_click', {
  button: 'signup',
  location: 'hero_section',
  experiment: 'variant_a'
})
Purchase:
track('purchase', {
  plan: 'pro',
  amount: 29,
  currency: 'USD',
  annual: true
})
User signup:
track('user_signed_up', {
  method: 'google',
  referrer: 'product_hunt'
})

Event naming conventions

Use lowercase words separated by underscores:
GoodBad
page_viewPageView
button_clickButton Click
purchase_completedpurchaseCompleted

Built-in features

Auto-deduplication: If you accidentally call track() twice with the exact same event name and properties within 300ms, the second call is silently ignored. This prevents double-counting. Auto-queue: If track() is called before init() runs, the event is queued in memory and sent automatically once init() is called. Auto-retry: If the network request fails, the SDK retries once after 500ms.

TypeScript

import { track } from 'analytiq'
import type { EventProperties } from 'analytiq'

const props: EventProperties = {
  page: 'Dashboard',
  count: 5,
  premium: true,
}

track('dashboard_viewed', props)