what is the best way to include analytics on prese...
# android-architecture
r
what is the best way to include analytics on presentation layer or data layer ,if I have to send a comprehensive information with each event i will log
a
Logging might be like the eyes of your system. It shouldn’t be an issue where (layer) to use it. I would suggest to use it wherever you need. But also, I would suggest create a library or a module where you'll implement the details of how sending the information to Analytics.
1
r
yes, definitely there is a module for it(that creates the params for the events), but mostly analytics on front ends are used to measure user actions, sometimes it require info that resides in the presentation layer and data layer,this is where i have confusion
s
TLDR: I use a unique key shared between UI models and DTOs to reference and retrieve necessary data needed for analytics. Longer version: I think I understand what you mean, I had the same doubt at one point. I keep my analytics trigger point in the ViewModel (Presentation Layer), as these analytics are usually based on user actions on the UI, which are passed to the ViewModel to execute business logic. Often, our analytics require details that are not part of the UI but of data layer objects (DTOs). I used to dump such data into the UI model and retrieve it in the ViewModel when the user triggered an action. However, this approach made my UI models unnecessarily bloated. Nowadays, I keep a unique key in both my UI model and DTO. This way, I can reference the UI model when an event is triggered. In the ViewModel, I populate my analytics with relevant details from the UI model and use the key to get the corresponding data from the DTO. This approach keeps my UI models clean, and maintaining a key is straightforward. Still trying to find a better approach though 😅.
r
@sankalp yes, i am also following same idea, but that defeats the purpose of SRP of those models and can cause confusions, i am looking for better solutions