Installation
Install the@formo/analytics-node package:
Quick Start
Initialize the SDK with your project’s write key:Identify users
Callidentify() when a user signs in or connects their wallet to associate them with their actions.
Track events
To track custom events (actions, conversions, or backend states) use thetrack function.
Configuration
Options
Customize the SDK behavior during initialization by passing an optional configuration object:| Option | Type | Default | Description |
|---|---|---|---|
flushAt | number | 20 events | Flush the queue once it contains N events. |
flushInterval | number | 30000 ms | Flush the queue every N milliseconds. |
maxQueueSize | number | 500000 bytes | Flush when the queue exceeds N bytes (approx. 500KB). |
retryCount | number | 3 retries | Number of times to retry failed requests. |
Manual flushing
To ensure all pending events are sent before a process exits (useful for serverless functions), callflush():
Data validation
The SDK throws aValidationError when required fields are missing or invalid:
Verification
To verify that your integration is working correctly:- Send a test event: Trigger an action in your application that calls
track()oridentify(). - Check the Dashboard: Go to the Activity page in the Formo dashboard.
- Confirm Ingestion: Your events should appear in the activity stream within a few seconds after a flush occurs.
await analytics.flush() if your script exits immediately, and check for any ValidationError in your server logs.
Graceful shutdown
The SDK automatically attempts to flush pending events before the process closes by listening to the following Node.js process events:beforeExit: Flushes events when the process is about to exit naturally.SIGTERM: Flushes events when the process receives a termination signal (common in Docker/Kubernetes).SIGINT: Flushes events when the process is interrupted (e.g.,Ctrl+C).
Important caveats
- Manual
process.exit(): If your code callsprocess.exit()directly, thebeforeExitevent will not fire, and the queue will not be flushed. - Serverless Environments: In platforms like AWS Lambda or Vercel, the environment may be frozen immediately after your handler returns. You must call
await analytics.flush()manually at the end of your function. - Forceful Shutdowns: A
SIGKILL(kill -9) or sudden crash will prevent any automatic flushing.
await analytics.flush() explicitly: