A straightforward and efficient first party analytics and visit tracking library, designed to seamlessly integrate with your Rails Ahoy backend highly inspired by Ahoy iOS Library.
- ๐ Comprehensive user visit tracking
- ๐ฅ Attribution of visits through UTM & referrer parameters
- ๐ Easy-to-use, in-house event tracking
To integrate Flutter Ahoy into your project, add the following dependency to your pubspec.yaml
file:
dependencies:
flutter_ahoy: ^latest_version
Replace latest_version
with the most recent version of the package.
To begin using Flutter Ahoy, you'll need to create an instance of the Ahoy client. This requires a configuration object that includes a baseUrl
and an ApplicationEnvironment
object.
import 'package:flutter_ahoy/flutter_ahoy.dart';
final ahoy = Ahoy(
configuration: AhoyConfiguration(
environment: ApplicationEnvironment(
platform: Platform.operatingSystem,
appVersion: "1.0.2",
osVersion: Platform.operatingSystemVersion,
),
baseUrl: "https://your-server.com",
),
);
The configuration object offers sensible defaults, but you can customize various settings:
- visitDuration (30 minutes)
- urlRequestHandler (
Client()
) - Routing
- ahoyPath ("ahoy")
- visitsPath ("visits")
- eventsPath ("events")
For additional customization, you can provide your own AhoyTokenManager
and RequestInterceptor
s during initialization.
To track a visit, initialize your Ahoy client and then call the trackVisit
method. This is typically done at the application's startup.
ahoy.trackVisit().then((visit) => print(visit));
Once a visit is successfully tracked, you can start sending events to your server.
// For batch event tracking, use the `trackEvents` function
var eventsToSend = [
Event(name: "ride_details.update_driver_rating", properties: {"driver_id": 4}),
Event(name: "ride_details.increase_tip", properties: {"driver_id": 4}),
];
ahoy.trackEvents(eventsToSend).then((_) => eventsToSend.clear());
// For individual event tracking, use the `trackEvent` method
ahoy.trackEvent("ride_details.update_driver_rating", properties: {"driver_id": 4});
// If an event doesn't require properties, you can omit them
ahoy.trackEvent("ride_details.update_driver_rating");
You can access the current visit directly through the currentVisit
property of your Ahoy client. Additionally, the headers
property allows you to include Ahoy-Visitor
and Ahoy-Visit
tokens in your requests as needed.