Web SDK
The AttributeHQ Web SDK (@attributehq/web-sdk) provides install attribution and event tracking for web applications.
Features
- ~2.9 KB gzipped — Zero runtime dependencies
- Automatic install attribution — Matches device fingerprints against ad clicks
- Event batching — Configurable batch size and flush intervals
- Offline queue — Events persist in localStorage across page loads
- SPA support — Auto-tracks page views via
pushState/replaceState/popstate - Page unload delivery — Uses
fetchwithkeepaliveorsendBeacon - Session management — 30-minute inactivity timeout, UUID-based
- Full TypeScript support — Ships with type declarations
Data Flow
User visits your site
↓
SDK collects device info (screen, timezone, language, UA)
↓
POST /api/v1/installs → Attribution engine matches against ad clicks
↓
Attribution result cached in localStorage
↓
SDK tracks events (page views, custom, revenue) → batched
↓
POST /api/v1/events → Kinesis → Lambda → PostgreSQL + S3Quick Example
import { init, track, trackRevenue, getAttribution } from '@attributehq/web-sdk'
// Initialize once
init({
apiKey: 'ak_your_api_key',
appId: 'your-app-uuid',
})
// Track events
track('signup_completed', { plan: 'premium' })
// Track revenue (defaults to NGN)
trackRevenue(5000, 'NGN', { product: 'premium_plan' })
// Read attribution
const attribution = getAttribution()
if (attribution && !attribution.isOrganic) {
console.log('Attributed to:', attribution.mediaSource)
}Next Steps
- Installation — npm, CDN, and configuration
- Event Tracking — Custom events, revenue, page views
- Attribution — How install attribution works
- API Reference — Full method and type reference
- Privacy & Data — Data collection and GDPR compliance