Skip to main content

Overview

batchTrack() sends an array of events to Analytiq in one single network request instead of one request per event. Use this when you need to track multiple events at the same time, like when a page loads and you want to record several things at once.

Signature

batchTrack(events: BatchEvent[]): void

Parameters

ParameterTypeRequiredDescription
eventsBatchEvent[]YesAn array of event objects to send together

BatchEvent object

Each item in the array is a BatchEvent with these fields:
FieldTypeRequiredDescription
namestringYesName of the event
propertiesobjectNoSame as track() properties
userIdstringNoOverride user for this specific event (otherwise uses globally identified user)
timestampstringNoISO 8601 timestamp. Auto-generated if not provided

Example

import { batchTrack } from 'analytiq'

batchTrack([
  { name: 'session_start', properties: { referrer: 'google' } },
  { name: 'page_view', properties: { path: '/dashboard' } },
  { name: 'feature_seen', properties: { feature: 'analytics_chart' } },
])

When to use batchTrack vs track

Use track()Use batchTrack()
Single events happening one at a timeMultiple events at the same time
Button clicks, form submitsApp startup events, page load events
Real-time single interactionsSummary of actions at the end of a session

Example — App startup events

import { useEffect } from 'react'
import { batchTrack } from 'analytiq'

export function App() {
  useEffect(() => {
    batchTrack([
      { name: 'app_opened' },
      { name: 'page_view', properties: { path: window.location.pathname } },
      { name: 'session_start', properties: { time: new Date().toISOString() } },
    ])
  }, [])

  return <div>Welcome!</div>
}

TypeScript

import { batchTrack } from 'analytiq'
import type { BatchEvent } from 'analytiq'

const events: BatchEvent[] = [
  { name: 'session_start' },
  { name: 'page_view', properties: { path: '/home' } },
]

batchTrack(events)