Skip to Content

API Reference

Complete method and type reference for the Web SDK.

Methods

init(config: SDKConfig): void

Initialize the SDK. Must be called before any other method. Calling twice is a no-op.

import { init } from '@attributehq/web-sdk' init({ apiKey: 'ak_your_api_key', appId: 'your-app-uuid', debug: true, })

track(eventName: string, properties?: Record<string, unknown>): void

Queue a custom event. Properties can be any JSON-serializable object.

import { track } from '@attributehq/web-sdk' track('button_click', { screen: 'home', button: 'signup' })

trackPageView(properties?: Record<string, unknown>): void

Queue a page view event. Automatically includes url, path, title, referrer.

import { trackPageView } from '@attributehq/web-sdk' trackPageView({ section: 'pricing' })

trackRevenue(amount: number, currency?: string, properties?: Record<string, unknown>): void

Queue a revenue event. Currency defaults to 'NGN'.

import { trackRevenue } from '@attributehq/web-sdk' trackRevenue(5000, 'NGN', { product: 'premium_plan' })

identify(userId: string, properties?: Record<string, unknown>): void

Associate the current user with a known ID. Persists across page loads.

import { identify } from '@attributehq/web-sdk' identify('user_12345', { email: 'user@example.com' })

flush(): void

Immediately send all queued events.

import { flush } from '@attributehq/web-sdk' flush()

getAttribution(): AttributionResult | null

Get the cached attribution result. Returns null if install tracking hasn’t completed yet.

import { getAttribution } from '@attributehq/web-sdk' const result = getAttribution()

Types

SDKConfig

interface SDKConfig { apiKey: string // Required. Format: ak_xxx appId: string // Required. App UUID batchSize?: number // Default: 10 flushInterval?: number // Default: 5000 (ms) maxQueueSize?: number // Default: 100 autoTrackPageViews?: boolean // Default: true debug?: boolean // Default: false }

AttributionResult

interface AttributionResult { matchType: 'device_id' | 'fingerprint' | 'organic' confidence: number mediaSource: string | null campaignId: string | null isOrganic: boolean attributedTouchTime: number | null }

DeviceInfo

interface DeviceInfo { screen_resolution: string timezone: string language: string platform: string }

QueuedEvent

interface QueuedEvent { event_name: string properties: Record<string, unknown> timestamp: number session_id: string }

Import Types

import type { SDKConfig, AttributionResult, DeviceInfo, QueuedEvent, } from '@attributehq/web-sdk'