The useAnalytics hook provides access to usage analytics and reporting data. It’s the client-side equivalent of the /query endpoint, allowing you to fetch and display usage data directly in your React components.
To use Autumn’s React hooks, you should set up the autumnHandler in your backend and the <AutumnProvider /> in your frontend, as described in the quickstart guide. This gives the hooks access to the customerId making the request.

Parameters

featureId
string | string[]
required
The feature ID or array of feature IDs to query usage data for.
range
string
Time range for the analytics query. Available options: “24h”, “7d”, “30d”, “90d”, “last_cycle”. Defaults to “30d” if not provided.

Return Values

data

Array of usage data points for each time period. Each item includes:
  • period: Unix timestamp in milliseconds representing the start of the time period
  • Dynamic properties for each queried featureId with their usage amounts

isLoading

Boolean indicating whether the analytics data is currently being fetched.

error

Any error that occurred while fetching analytics data.

refetch

Function to manually refetch the analytics data.