Now you can track events from any Client Component:
// app/page.tsx'use client';import { track } from '@grainql/tag';export default function HomePage() { return ( <div> <h1>Welcome!</h1> <button onClick={() => track('cta_clicked', { location: 'hero' })}> Get Started </button> </div> );}
Server vs Client Components: track(), identify(), and other Grain Tag functions must be called from Client Components (with the 'use client' directive) or inside useEffect. Grain Tag is SSR safe — init() returns a no-op in non-browser environments — but tracking functions need the browser to work.
Automatic page views: Grain Tag hooks into the History API to track page views and navigation automatically. You do not need a page view tracker component — this works out of the box with Next.js App Router.
// pages/index.tsximport { track } from '@grainql/tag';export default function HomePage() { return ( <div> <h1>Welcome!</h1> <button onClick={() => track('cta_clicked', { location: 'hero' })}> Get Started </button> </div> );}
Automatic page views: Grain Tag automatically tracks navigation via the History API for both App Router and Pages Router. No manual page view tracking is needed.
Vercel deployment: All environment variables starting with NEXT_PUBLIC_ are automatically available in the browser. Keep secret keys (for server-side tracking) private by omitting the NEXT_PUBLIC_ prefix.
Need remote configuration or feature flags? See @grainql/analytics-web for remote config, React hooks (useConfig, useTrack, GrainProvider), and more.