Basic Usage
Get access to the complete Grain client instance:When to Use
UseuseGrainAnalytics when you need:
- User identification:
setUserId(),identify() - User properties:
setProperty() - Manual flushing:
flush() - Template events:
trackLogin(),trackPurchase(), etc. - Advanced config:
fetchConfig(),preloadConfig() - Client management:
destroy()
useConfigfor configurationsuseTrackfor event trackinguseAllConfigsfor multiple configs
User Identification
Set user ID when users log in:userId to GrainProvider, this happens automatically. Only use this hook if you need manual control.
User Properties
Set attributes for user profiles:Template Events
Use pre-built event methods:Manual Flushing
Force send events immediately:Preload Configurations
Load configs before rendering:Get Current User ID
Check who’s currently identified:Advanced Configuration
Fetch configurations with specific options:Configuration Listeners
Add listeners for config changes:useConfig and useAllConfigs handle updates automatically.