Skip to main content
Grain provides two SDKs for different use cases:
  • Grain Tag (@grainql/tag) — The primary SDK for browser-side analytics. Cookieless by default, auto-tracks page views, clicks, scroll, sessions, and more.
  • Analytics Web (@grainql/analytics-web) — For remote configuration, React hooks, template events, and server-side tracking.

Grain Tag

The default SDK for browser analytics. Lightweight, privacy-first, and SSR safe.

Import Paths

Lifecycle

  1. init(config?) — Creates the singleton instance and starts auto-tracking
  2. track(name, props?) / identify(userId) — Send events (works before init via pre-init queue)
  3. flush() — Force-send all pending events
  4. destroy() — Tear down the SDK and clear the singleton

Quick Reference

Instance Methods


Analytics Web

For remote configuration, React hooks, template events, and server-side tracking.

Import Paths

Quick Reference

Remote Configuration

Template Events

React Hooks


Return Values

  • Synchronous methods: Direct values or undefined
  • Async methods: Promise<T> that resolves to the result
  • Hooks: Objects with data, loading states, and errors

Error Handling

Methods handle errors gracefully:
  • track(): Fire-and-forget, errors logged if debug enabled
  • Config methods: Return cached/default on failure
  • Async methods: Throw errors, catch with try/catch
  • Hooks: Provide error property
Learn more in Error Handling.

Explore the API

Core Methods

Event tracking and user management

Config Methods

Remote configuration access

Template Methods

Pre-built event methods

React Hooks

React integration hooks

Types

TypeScript type definitions