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:
flutter pub add hightouch_events
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:
final analytics = createClient(Configuration("WRITE_KEY"));
Configuration options:
Option | Type | Description |
---|---|---|
writeKey | String | Your Hightouch write key. |
apiHost | String | The API host to send the tracked events to. |
trackApplicationLifecycleEvents | Bool | Whether to automatically track application lifecycle events (like opening the application). Defaults to false . |
API
Identify
The analytics.identify
method sends an identify
event.
Example usage:
analytics.identify(userId: "user-123", userTraits: UserTraits(email: "user@example.com"));
Track
The analytics.track
method sends a track
event.
Example usage:
analytics.track("View Product", properties: {"productId": 123});
Screen
The analytics.screen
method sends a screen
event.
Example usage:
analytics.screen("Home");
Group
The analytics.group
method sends a group
event.
Example usage:
analytics.group("group-123", groupTraits: GroupTraits(name: "Group 123"));
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.