Why this matters
Avoids duplication, keeps event names/properties consistent, and makes it easy to swap providers or add privacy guards.
Route all analytics events through a single service/helper instead of calling the SDK directly from widgets and blocs.
Avoids duplication, keeps event names/properties consistent, and makes it easy to swap providers or add privacy guards.
Side-by-side examples engineers can pattern-match during review.
onPressed: () {
AnalyticsSDK.track('button_tap', {'id': widget.id});
// elsewhere
AnalyticsSDK.track('button_tap', {'id': card.id});
}class Analytics {
const Analytics(this._sdk);
final AnalyticsSDK _sdk;
void buttonTap(String id) => _sdk.track('button_tap', {'id': id});
}
onPressed: () => analytics.buttonTap(widget.id);AnalyticsSDK.track('x'); // scattered across UIanalytics.doSomething(params); // via a single facadeFrom the same buckets as this rule.