analytics 0.0.1-dev.2 copy "analytics: ^0.0.1-dev.2" to clipboard
analytics: ^0.0.1-dev.2 copied to clipboard

outdated

Interface for working with 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());
38
likes
0
pub points
83%
popularity

Publisher

verified publishersurf.ru

Interface for working with analytic services.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, logger, surf_lint_rules

More

Packages that depend on analytics