Skip to main content
The React hooks come from Analytics Web, under @grainql/analytics-web/react. Grain Tag has no hooks. A component reads a configuration value with useConfig and sends an event with useTrack, and the provider owns the client. When this page and the TypeScript types of @grainql/analytics-web disagree, the types win.

Install

React 16.8.0 or later is a peer dependency. The package does not bundle React.

The provider

Wrap the application in GrainProvider one time. Every component inside the provider can call the hooks. A hook called outside the provider throws an error.
Read GrainProvider.

Exports

@grainql/analytics-web/react exports these values. The first six have a page each. The types GrainProviderProps, UseConfigOptions, UseConfigResult, UseAllConfigsOptions, UseAllConfigsResult, TrackFunction, ConsentBannerProps, PrivacyPreferenceCenterProps, CookieNoticeProps, PrivacyPreferences, and DataDeletionOptions are exported too. The consent hooks and components follow the consent mode of the client. Read Privacy and consent.

Grain Tag or Analytics Web in React

Both packages send custom events, page views, and heatmap clicks. Only Grain Tag takes DOM snapshots and runs dashboard trackers. Only Analytics Web reads remote configuration and has hooks. Read Install Grain.