Matomo tracking for flutter
Works on both Android and/or iOS. Version 1.1.4 supports AndroidX.
await FlutterMatomo.initializeTracker('https://YOUR_URL/piwik.php', SITE_ID);
Important: It does not matter if you are using piwik or matomo, you need to append piwik.php and not matomo.php
If you have the BuildContext this will automatically add the widget name
await FlutterMatomo.trackScreen(context, "Screen opened")
If not or you want to enter a custom name then use this
await FlutterMatomo.trackScreenWithName("SomeWidgetName", "Screen opened");
You can also use TraceableStatefulWidget
, TraceableStatelessWidget
& TraceableInheritedWidget
Where you get a screen open event with the name of the widget out of the box
Replace
class HomeWidget extends StatefulWidget {
...
with this
class HomeWidget extends TraceableStatefulWidget {
...
Or you can override the tracking name of the widget by overriding the name
attribute
class HomeWidget extends TraceableStatefulWidget {
HomeWidget({Key key}) : super(key: key, name: 'ONLY_IF_YOU_WANT_TO_OVERRIDE_THE_WIDGET_NAME');
@override
_HomeWidgetState createState() => _HomeWidgetState();
}
If you have the BuildContext this will automatically add the widget name
await FlutterMatomo.trackEvent(context, "Sign up button", "Clicked");
If not or you want to enter a custom name then use this
await FlutterMatomo.trackEventWithName("SomeWidgetName", "Sign up button", "Clicked");
await FlutterMatomo.trackDownload();
await FlutterMatomo.goal(GOAL_ID);
Future<void> initPlatformState() async {
_matomoStatus = await FlutterMatomo.initializeTracker('https://YOUR_URL/piwik.php', SITE_ID);
setState(() {});
Future.delayed(Duration(seconds: 2), () async {
_matomoStatus = await FlutterMatomo.trackScreen(context, "Screen opened");
setState(() {});
});
Future.delayed(Duration(seconds: 4), () async {
_matomoStatus = await FlutterMatomo.trackScreenWithName("This uses a name MyAppWidget", "Screen opened");
setState(() {});
});
Future.delayed(Duration(seconds: 6), () async {
_matomoStatus = await FlutterMatomo.trackEvent(context, "Sign up button", "Clicked");
setState(() {});
});
Future.delayed(Duration(seconds: 8), () async {
_matomoStatus = await FlutterMatomo.trackEventWithName("LoginWidget", "Login button", "Clicked");
setState(() {});
});
Future.delayed(Duration(seconds: 10), () async {
_matomoStatus = await FlutterMatomo.trackDownload();
setState(() {});
});
Future.delayed(Duration(seconds: 12), () async {
_matomoStatus = await FlutterMatomo.trackGoal(1);
setState(() {});
});
if (!mounted) return;
}