Which is better, putting google analytics code in the presenter or keeping them in the activity?
1 Answers
I think it should be put in presenter because View shouldn't know nothing about sending GAnalytics. View should be passive as much as it can be, meaning it should only have setter methods to update it's state upon presenter calls.
On the other hand, I had to wire one big project with GAnalytics with every possible action you could imagine and my experience is that it's easier to send GAnalytics from View because you can easily jump to button/textView definition and see it's role in UI which is not possible from presenter because it don't(shouldn't) have reference to any buttons/labels in UI(Activity). But that project was old monolithic view-controler(fat actvity) architecture. This days am working on MVP(clean architecture) and would like to hear other opinions on this topic. Regards

- 399
- 3
- 10
-
yes, I was having the same dilemma, The right answer is to send analytics events/data from the presenter, but its hard to get hooks to these events and data in the presenter, I was thinking by using RxJava and making the Activity/Fragment an Observable, we should be able to publish state changes to the subscribers – Bhargav Sep 03 '16 at 12:14