The Flutter SDK makes it easy to track events from all types of Flutter applications.
Installation
The Flutter SDK is hosted on pub.dev.
You may install the SDK by adding it to your pubspec.yaml file:
Initialization
You should initialize the SDK in the top-level app state and store it in a variable
for use across your application. For example, you may want to initialize it in
your app delegate.
Example:
Configuration options:
Session tracking
Session tracking is enabled by default. The SDK attaches sessionId, sessionStart, and a session object to context on every event so you can group events from the same app session.
Sessions use two timeouts, both in milliseconds:
foregroundSessionTimeout limits inactivity while the app is in the foreground.
backgroundSessionTimeout limits how long the app can stay in the background before the next resume starts a new session.
Both default to 1800000 (30 minutes). Set both to 0 to disable session tracking.
A new session starts when any of these occur:
- First launch, when no session state is persisted.
- Foreground inactivity exceeds
foregroundSessionTimeout.
- Resume after being backgrounded longer than
backgroundSessionTimeout, including after process death.
- Calling
reset().
Session state is persisted across app relaunches. sessionIndex is a per-device lifetime counter. It starts at 0 and resets only when the app is uninstalled, not when you call reset().
You can change the timeouts when you initialize the SDK:
context.session includes:
sessionId and sessionStart are also set on context for parity with the browser SDK. sessionStart is included only when it is true.
API
Identify
The analytics.identify method sends an identify event.
Example usage:
Track
The analytics.track method sends a track event.
Example usage:
Screen
The analytics.screen method sends a screen event.
Example usage:
Group
The analytics.group method sends a group event.
Example usage:
Flush
The Flutter SDK buffers events locally before sending them to Hightouch’s servers.
This minimizes the number of requests made by the SDK and makes the tracking
non-blocking.
To force the local buffer to be sent to Hightouch immediately call the flush()
method.
Reset
The reset method resets the identify and group for the local session.
Specifically, it resets the anonymousId, userId, referrer, and traits.
The reset method should be called when users log out. This way, if the user
logs back in with another account, the userIds and traits from the different
sessions remain separate. Calling reset() also starts a new analytics session.
See Session tracking. Last modified on September 15, 2026