• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Floating-Dartists / matomo-tracker / 4956791592

pending completion
4956791592

Pull #74

github

GitHub
Merge cd52548b5 into bd2fedb8c
Pull Request #74: Reentry with RouteAware and extended example

10 of 10 new or added lines in 2 files covered. (100.0%)

488 of 528 relevant lines covered (92.42%)

2.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.42
/lib/src/traceable_widget_mixin.dart
1
import 'package:flutter/material.dart';
2
import 'package:matomo_tracker/matomo_tracker.dart';
3
import 'package:matomo_tracker/utils/random_alpha_numeric.dart';
4

5
final matomoObserver = RouteObserver<ModalRoute<void>>();
6✔
6

7
/// Register a [MatomoTracker.trackScreenWithName] on this widget.
8
@optionalTypeArgs
9
mixin TraceableClientMixin<T extends StatefulWidget> on State<T>
10
    implements RouteAware {
11
  /// {@template traceableClientMixin.actionName}
12
  /// Equivalent to the page name. (e.g. `'HomePage'`).
13
  /// {@endtemplate}
14
  @protected
1✔
15
  String get actionName => 'Created widget ${widget.toStringShort()}';
3✔
16

17
  /// {@template traceableClientMixin.pvId}
18
  /// A 6 character unique page view ID.
19
  ///
20
  /// Each unique ID represents one page view.
21
  ///
22
  /// The default implementation will generate one on widget creation.
23
  /// {@endtemplate}
24
  @protected
2✔
25
  String get pvId => _pvId;
2✔
26
  String _pvId = randomAlphaNumeric(6);
27

28
  /// {@template traceableClientMixin.updatePvIdAfterPop}
29
  /// Used to control if a [Navigator.pop] back to this page is considered
30
  /// a new page view.
31
  ///
32
  /// If you do not consider this a new page view in your apps logic,
33
  /// you should return `false` to tell the widget to keep the old [pvId].
34
  /// If you overworte the [pvId] getter, this has no effect.
35
  /// {@endtemplate}
36
  @protected
×
37
  bool get updatePvIdAfterPop => true;
38

39
  /// {@template traceableClientMixin.path}
40
  /// Path to the widget. (e.g. `'/home'`).
41
  ///
42
  /// This will be combined with [MatomoTracker.contentBase]. The combination
43
  /// corresponds with `url`.
44
  /// {@endtemplate}
45
  @protected
46
  String? path;
47

48
  /// {@template traceableClientMixin.campaign}
49
  /// The campaign that lead to this interaction or `null` for a
50
  /// default entry.
51
  /// {@endtemplate}
52
  @protected
53
  Campaign? campaign;
54

55
  /// {@template traceableClientMixin.dimensions}
56
  /// A Custom Dimension value for a specific Custom Dimension ID.
57
  ///
58
  /// If Custom Dimension ID is 2 use `dimension2=dimensionValue` to send a
59
  /// value for this dimension.
60
  ///
61
  /// For additional remarks see [MatomoTracker.trackDimensions].
62
  /// {@endtemplate}
63
  @protected
64
  Map<String, String>? dimensions;
65

66
  /// {@template traceableClientMixin.tracker}
67
  /// Matomo instance used to send events.
68
  ///
69
  /// By default it uses the global [MatomoTracker.instance].
70
  /// {@endtemplate}
71
  @protected
2✔
72
  MatomoTracker get tracker => MatomoTracker.instance;
2✔
73

74
  @override
2✔
75
  void initState() {
76
    super.initState();
2✔
77
    _track();
2✔
78
  }
79

80
  @override
2✔
81
  void didChangeDependencies() {
82
    super.didChangeDependencies();
2✔
83
    matomoObserver.subscribe(this, ModalRoute.of(context)!);
8✔
84
  }
85

86
  @override
2✔
87
  void dispose() {
88
    matomoObserver.unsubscribe(this);
4✔
89
    super.dispose();
2✔
90
  }
91

92
  @override
×
93
  void didPop() {}
94

95
  @override
×
96
  void didPopNext() {
97
    if (updatePvIdAfterPop) {
×
98
      _pvId = randomAlphaNumeric(6);
×
99
    }
100
    _track();
×
101
  }
102

103
  @override
2✔
104
  void didPush() {}
105

106
  @override
×
107
  void didPushNext() {}
108

109
  void _track() {
2✔
110
    tracker.trackScreenWithName(
4✔
111
      actionName: actionName,
2✔
112
      pvId: pvId,
2✔
113
      path: path,
2✔
114
      campaign: campaign,
2✔
115
      dimensions: dimensions,
2✔
116
    );
117
  }
118
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc