analytics 0.0.1-dev.3

Flutter Android iOS web

Interface for working with analytic services. The library is supposed to unify work with various analytic services.

SurfGear

analytics #

Interface for working with analytic services.

Description #

The library is supposed to unify work with various analytic services. The main actors are:

  • AnalyticAction — any action that is valuable for analytics. Usually it is a "button pressed" or "screen opened" type of event but the main criterion is a possibility to be handled by AnalyticActionPerformer.
  • AnalyticActionPerformer — a performer of specific actions used to incapsulate work with a certain analytics service. Typically implemented by transforming AnalyticAction into a required format as well as calling send() of a third-party library.
  • AnalyticService — a unified entry point for several AnalyticActionPerformers.

Example #

The easiest interaction with the library is as follows:

  1. Determine the actions that ought to be recorded in the analytics service:
class MyAnalyticAction implements AnalyticAction {
    final String key;
    final String value;

    MyAnalyticAction(this.key, this.value);
}

class ButtonPressedAction extends MyAnalyticAction {
    ButtonPressedAction() : super("button_pressed", null);
}

class ScreenOpenedAction extends MyAnalyticAction {
    ScreenOpenedAction({String param}) : super("screen_opened", param);
}
  1. Implement action performer:
class MyAnalyticActionPerformer
    implements AnalyticActionPerformer<MyAnalyticAction> {
  final SomeAnalyticService _service;

  MyAnalyticActionPerformer(this._service);

  @override
  bool canHandle(AnalyticAction action) => action is MyAnalyticAction;

  @override
  void perform(MyAnalyticAction action) {
    _service.send(action.key, action.value);
  }
}
  1. Add performer to the service:
    final analyticService = DefaultAnalyticService();
    analyticService.addActionPerformer(
        MyAnalyticActionPerformer(SomeAnalyticService()),
    );

Use:

    analyticService.performAction(ButtonPressedAction());
2
likes
110
pub points
59%
popularity

Publisher

surf.ru

Interface for working with analytic services. The library is supposed to unify work with various analytic services.

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache 2.0 (LICENSE)

Dependencies

flutter, logger, surf_lint_rules

More

Packages that depend on analytics