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

Floating-Dartists / matomo-tracker / 6454971306

09 Oct 2023 09:47AM UTC coverage: 93.108%. First build
6454971306

Pull #122

github

web-flow
Merge 529900ea8 into eec76315c
Pull Request #122: Bump package_info_plus from 4.1.0 to 5.0.0

743 of 798 relevant lines covered (93.11%)

2.87 hits per line

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

78.79
/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.trackPageViewWithName] 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
  /// (recommended).
24
  ///
25
  /// For more information see `pvId` in [MatomoTracker.trackPageViewWithName] and
26
  /// [MatomoTracker.attachLastScreenInfo].
27
  /// {@endtemplate}
28
  @protected
2✔
29
  String get pvId => _pvId;
2✔
30
  String _pvId = randomAlphaNumeric(6);
31

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

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

52
  /// {@template traceableClientMixin.campaign}
53
  /// The campaign that lead to this interaction or `null` for a
54
  /// default entry. Setting this multiple times during an apps
55
  /// lifetime can have some side effects, see the [Campaign] class
56
  /// for more information.
57
  /// {@endtemplate}
58
  @protected
59
  Campaign? campaign;
60

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

72
  /// {@template traceableClientMixin.performanceInfo}
73
  /// Information on how long it took to generate this content.
74
  /// {@endtemplate}
75
  @protected
76
  PerformanceInfo? performanceInfo;
77

78
  /// {@template traceableClientMixin.tracker}
79
  /// Matomo instance used to send actions.
80
  ///
81
  /// By default it uses the global [MatomoTracker.instance].
82
  /// {@endtemplate}
83
  @protected
2✔
84
  MatomoTracker get tracker => MatomoTracker.instance;
2✔
85

86
  @override
2✔
87
  void initState() {
88
    super.initState();
2✔
89
    _track();
2✔
90
  }
91

92
  @override
2✔
93
  void didChangeDependencies() {
94
    super.didChangeDependencies();
2✔
95

96
    final route = ModalRoute.of(context);
4✔
97
    if (route != null) {
98
      matomoObserver.subscribe(this, route);
4✔
99
    }
100
  }
101

102
  @override
2✔
103
  void dispose() {
104
    matomoObserver.unsubscribe(this);
4✔
105
    super.dispose();
2✔
106
  }
107

108
  @override
×
109
  void didPop() {}
110

111
  @override
×
112
  void didPopNext() {
113
    if (updatePvIdAfterPop) {
×
114
      _pvId = randomAlphaNumeric(6);
×
115
    }
116
    _track();
×
117
  }
118

119
  @override
2✔
120
  void didPush() {}
121

122
  @override
×
123
  void didPushNext() {}
124

125
  void _track() {
2✔
126
    tracker.trackPageViewWithName(
4✔
127
      actionName: actionName,
2✔
128
      pvId: pvId,
2✔
129
      path: path,
2✔
130
      campaign: campaign,
2✔
131
      dimensions: dimensions,
2✔
132
      performanceInfo: performanceInfo,
2✔
133
    );
134
  }
135
}
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