-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #174 from Floating-Dartists/173-feat-improve-matom…
…oobserver-to-dispense-with-traceableclientmixin 173 feat improve matomoobserver to dispense with traceableclientmixin
- Loading branch information
Showing
8 changed files
with
134 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:matomo_tracker/matomo_tracker.dart'; | ||
|
||
/// {@template matomo_global_observer} | ||
/// A [RouteObserver] that will track all the route navigation events in Matomo. | ||
/// | ||
/// You can specify a custom [MatomoTracker] instance with the `tracker` | ||
/// parameter. (defaults to [MatomoTracker.instance] if not provided) | ||
/// | ||
/// ### Example | ||
/// | ||
/// ```dart | ||
/// MaterialApp( | ||
/// navigatorObservers: [ | ||
/// MatomoGlobalObserver(), | ||
/// ], | ||
/// ); | ||
/// ``` | ||
/// {@endtemplate} | ||
class MatomoGlobalObserver extends RouteObserver<PageRoute<dynamic>> { | ||
/// {@macro matomo_global_observer} | ||
MatomoGlobalObserver({ | ||
MatomoTracker? tracker, | ||
}) : _tracker = tracker ?? MatomoTracker.instance; | ||
|
||
final MatomoTracker _tracker; | ||
|
||
@override | ||
void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) { | ||
super.didPush(route, previousRoute); | ||
_trackPageView(route); | ||
} | ||
|
||
@override | ||
void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) { | ||
super.didPop(route, previousRoute); | ||
_trackPageView(previousRoute); | ||
} | ||
|
||
void _trackPageView(Route<dynamic>? route) { | ||
_tracker.trackPageViewWithName( | ||
actionName: route?.settings.name ?? 'unknown', | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import 'package:flutter/widgets.dart'; | ||
|
||
/// {@macro matomo_local_observer} | ||
@Deprecated( | ||
'Use matomoLocalObserver instead. ' | ||
'This feature was deprecated in v6.0.0-dev.1 and will be removed in the next major version.', | ||
) | ||
final matomoObserver = matomoLocalObserver; | ||
|
||
/// {@template matomo_local_observer} | ||
/// A [RouteObserver] that will track navigation events in Matomo from a widget | ||
/// that uses `TraceableWidgetMixin`. | ||
/// {@endtemplate} | ||
/// | ||
/// ### Example | ||
/// | ||
/// ```dart | ||
/// MaterialApp( | ||
/// navigatorObservers: [ | ||
/// matomoLocalObserver, | ||
/// ], | ||
/// ); | ||
final matomoLocalObserver = RouteObserver<ModalRoute<void>>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters