0 purchases
prodstats
Flutter Analytics Tracking Library #
A simple yet powerful Flutter analytics tracking library, specially designed to automatically track clicks and route changes. The library supports both NavigatorObserver and RouterDelegate based routing.
Library Setup #
To use the library, first import the library file to your Dart code file.
import 'package:prodstats/prodstats.dart';
copied to clipboard
Send Events
Sending events is as simple as calling the sendEvent method.
ProdStatsEvent event = ProdStatsEvent(event: 'page-view', path: '/home');
ProdStats.instance?.sendEvent(event);
copied to clipboard
The sendEvent method requires a ProdStatsEvent instance. ProdStatsEvent constructor requires an event type, and optionally a path if the event type is a 'page-view'.
Usage of ProdStatsRouteObserver with MaterialApp(): #
final routeObserver = ProdStatsRouteObserver();
void main() {
runApp(
ProdStats(
app: MaterialApp(
home: HomePage(),
navigatorObservers: [routeObserver],
domain: 'your_tracking_domain',
),
),
);
}
copied to clipboard
In the above example, the ProdStatsRouteObserver instance is added to the navigatorObservers of MaterialApp. Thus, it automatically tracks page navigation events.
Usage of ProdStats.trackRoute with MaterialApp.router(): #
First, extend RouterDelegate with a class, let's call it AppRouterDelegate.
class AppRouterDelegate extends RouterDelegate with ChangeNotifier {
String? _path;
// get and set methods for _path
@override
Future<bool> popRoute() {
...
}
@override
Widget build(BuildContext context) {
...
}
@override
Future<void> setNewRoutePath(configuration) {
...
}
@override
get currentConfiguration {
...
}
}
copied to clipboard
Then use trackRoute inside AppRouterDelegate.
class AppRouterDelegate extends RouterDelegate with ChangeNotifier {
...
AppRouterDelegate() {
ProdStats.trackRoute(this, selector: (state) => state.path);
}
...
}
copied to clipboard
Finally, use AppRouterDelegate with MaterialApp.router().
final appRouterDelegate = AppRouterDelegate();
void main() {
runApp(
ProdStats(
app: MaterialApp.router(
routerDelegate: appRouterDelegate,
routeInformationParser: AppRouteInformationParser(),
domain: 'your_tracking_domain',
),
),
);
}
copied to clipboard
In the above examples, ProdStats.trackRoute is used with RouterDelegate derived class AppRouterDelegate. It tracks and sends route events to the provided domain.
Display Logs (Optional) #
The library also has an optional debug feature which lets you see the logs. To enable debug mode, just set the debug property to true as shown below.
ProdStats(
app: MaterialApp(...),
domain: 'your_tracking_domain',
debug: true
)
copied to clipboard
Error Handling #
The library also offers built-in error handling. You can catch unhandled errors in your Flutter app and send them as an analytics event using the sendEvent method in your error handling process.
Conclusion #
With this library, you can easily implement analytics tracking in your Flutter app without hassling for intricate setup process. Your feedbacks and suggestions to improve the library are most welcome.
Happy coding!
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.