Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Analytics - Which layer?

Very open architectural question.

I have an Android offline app.
In one of the actions user can change a configuration, in my specific case it is the day of the forecast.
So to do that, the flow is this:

  • Activity on click event;
  • Preferences View Model;
  • Preferences Business;
  • And finally persisted on the persistence layer;

The actual effect will happen in parallel (no important for my question).

My questions are:
Where is the best place to add the analytics track?
What exactly should I be considering when positioning my analytics track events?

Just in case, this is the app I'm talking about: https://play.google.com/store/apps/details?id=pozzo.apps.travelweather

Thank you

like image 481
Pozzo Apps Avatar asked Nov 18 '22 09:11

Pozzo Apps


1 Answers

Analytics is part of the domain layer, so It should ideally be kept in the domain layer. Often projects have analytics in the view layer (ViewControllers, activities or fragments or ViewModels). This leads to inconsistency and analytics calls are often fired from views or view models, controllers etc.

Therefore, it is ideal to keep analytics inside UserCase/interactor classes, these are often re-usable classes, which makes logging easier with less duplication.

like image 171
Himanshu Walia Avatar answered Dec 06 '22 13:12

Himanshu Walia