useTrackUsage hook returns a function for writing usage events for tracked limit features.
- Typed
- Untyped
Parameters
none
useTrackUsage does not accept an options argument.Returns
(featureKey | body) => Promise<TrackUsageResponse>
Tracks usage and revalidates customer and feature-access caches.
trackUsage("team_seats") (defaults amount to 1) or pass a full body object.
trackUsage body object
string
required
Feature key to track usage for (typed to your tracked limit feature keys when using generated types).
number
Usage amount to record. Defaults to
1.string
Stable event key for retries and deduplication.
number
Unix timestamp in milliseconds for when the event happened.
Record<string, string>
Optional string key/value metadata attached to the usage event.
If the action happens on your backend (for example in a server action, webhook, or background job), it usually makes more sense to track usage on the backend.
Examples
- Typed Example
- Untyped Example