Analytics - Which layer? - android

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

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.

In terms of clean architecture analytics it's business layer, so it should be implemented in Interactor/Use case, but I think it's not so bad to keep analytics in a view, because it's simplest way.

Related

Firebase database structure - storing user activity in order to customize views and permission

Working with Firebase for the first time and looking for advice of setting up the right structure for my project which is basically an "offers/coupon" type starter project.
The scenario is this:
I have a node containing a list of all offers available to users
This list of offers is displayed to users after successful Firebase authentication
When a user redeems an offer, I want to be able to count/record that activity in their child node under user and hide that offer so that they cannot see it again once used.
My question is what would be the best way to do this given that offers may be added, may expire, or may change at some point in the future. So, in effect, the user should receive the list of most updated offers, minus the ones he/she have used in the past.
a) would it be more effective to have a master list of offers, and then run a cloud/server function to clone this list for each new user an track that way
Firebase Structure 1
or
b) Keep a master list of offers in one node, then track user specific offer usage
Firebase Structure 2
Appreciate your guidance
The second solution is better because you'll save bandwith. This practice is called denormalization and is a common practice when it comes to Firebase. The first solution is not good becase every time you want to display the users you donwload unnecessary data. If you want to read more details about how you can structure a Firebase database in a efficient way, please read this post, Structuring your Firebase Data correctly for a Complex App. Also, you can take a look a this tutorial, Denormalization is normal with the Firebase Database, for a better understanding.
Second solution is much good. Because in first one we are having redundancy of data in our database. And second one obviously removing that cause.
But instead of using true or false because it is only showing you, "it's available or not", so you can use a string type parameter as "expired", "going to expire" and "updated" or whatever sooo. So it. Will be able to trace all you information related to offer for particular user. I think this is your requirement also.
Happy coding.

In Dagger 2, is it possible to have a component to have multiple parent components

Not sure if this is the right question to ask, but here is the scenario I have with an Android app I am making:
AppComponent, represents the entire app scope
UserComponent, created after a user has logged in and destroyed if user logged out.
FeatureComponent, is a feature that user can access, it has several activities.
The problem I have is that under normal circumstances, FeatureComponent is created from UserComponent as it is part of what authenticated users get to access. However, I have a "try feature" option that allows the user to access all of FeatureComponent without authenticating.
What would be the proper way to handle creation/releasing of FeatureComponent, should I have be creating AuthenticatedFeatureComponent and TryOutFeatureComponent even though almost everything is exactly the same?
thanks.
Could you just break out the components that are different between each other and then create a separate module for each use case that includes the relevant components for each?
This is a lot like your suggestion which I think should work. Is there a reason you are hesitating about it?

Simple Google Analytics for Android

I am using a simple Google Analytics code. When I look the real-time users on Google Analytics, I can see "1 active user now". There is no problem, but I am suspicious that this code will give wrong results on Google Analytics because When I look their guides, their implementations is different. Can this code give wrong result on Google Analytics?
My Code:
Declaration in MainActivity
public static GoogleAnalytics analytics;
public static Tracker tracker;
Implementation in onCreate
analytics = GoogleAnalytics.getInstance(this);
analytics.setLocalDispatchPeriod(1800);
tracker = analytics.newTracker(unitid);
tracker.enableExceptionReporting(true);
tracker.enableAdvertisingIdCollection(true);
tracker.enableAutoActivityTracking(true);
No more code, just 6 lines.
If there is no problem for this code, why their guide is complex?
Note: There is no problem now, but I am suspicious about future.
This is, indeed, close to the simplest implementation possible.
The problems with it, however, is that:
GA library has hardcoded triggers that are qualified to be "screenviews". While it may be sufficient for very simple apps, it poorly handles layered views logic that is commonly used in more complex apps.
GA library has to send screen identifiers. And there's little to none of what it can use for that. So what it does is it tries to pull class names as identifiers for screen names when no explicit name is set (which is the case in automated tracking). This results in the data being hard to read.
Personally I've never seen auto activity tracking being used in production. Maybe it makes sense to be used by the developers to improve exceptions logging in Firebase, but the data is way too inconsistent and hard to decode to be flexibly use for business reporting.
You achieve a lot better tracking quality when you set each screenname explicitly. That is the best practice.

Creating a Appwarp chatroom and issues in a Android game

I was creating an android app (actually a game) with customised Cocos2d and I was planning to add in a chat feature. kind of like a counter-strike where other players can send short IM to each other (I think the clash of clan's clan chat comes closest to what i want to make, you can get an idea from that)
I was trying to use AppWarp API to do this, but am finding it hard to do so. I liked appwarp because it handles server management on its own. I don't wanna get into implementing a XMPP/Smack customised code where scalability becomes an issue later on, because i dont know server management at all! (although i would love the freedom it gives me). Did i mention that its a two man team? Me and a friend :).
In my game in I need one global room (a static room) and an another special-group room (this will be dynamic, since its only created if the user selects to create the room).
But the problem with creating a dynamic group room in Appwarp is that it doesnt stay alive (remain persistent) after all the users in it have disconnected. According to the current implementation in the API, the dynamic group gets deleted if the last member logs out.
Q1) Is there a way for me to create a persistent/static room from client side? Q2) and if that isnt possible is there some way i can make the dynamic rooms persistent? Basically i'm asking anyone who has experience with Appwarp, If it requires some tweaking with the code can you please point me out in the right direction?, or is it not possible at all?
Q3) Also, i wanted to implement a chat history feature on the chat rooms. Is that already available via Appwarp API? or would I have to write a listener, so that each time a room receives a message it maintains a history file? Again this is only possible if the user can re-connect to the room.. Please guide me for this too.
Also,supposing i have to drop Appwarp idea (Gulp!) Q4) Can you please point me in the right direction to create a group-based chat with a similar api that can be integrated with an android app with cocos2D.
Currently creating static rooms through the API is not possible. However providing such flexibility is part of AppWarp's plan.
AppWarp doesn't maintain chat history on the server side currently. This is again something we are looking in to as it has been requested by other developers as well. Keep an eye on our blogs (http://blogs.shephertz.com) where we announce our updates.
We expect to release these features by early October.

Android: can I use Google Analytics inside a Service?

I have an application which most of the time works in the background, as a Service. There is a lot of examples and tutorials online on how you can use Google Analytics API with EasyTracker library to track multiple Activities, but there is not a single one that explains, how to use Google Analytics API in a Service. Is it even possible?
Good news! You can. and it's quite easy.
You'll need the application context let's call it mCtx
When you have this you need an instance of GoogleAnalytics, you can get it by calling
GoogleAnalytics mGaInstance = GoogleAnalytics.getInstance(mCtx);
now you need to set any parameters you want (which you would normaly put in analytics.xml when using EasyTracker).
now you need a Tracker instance:
Tracker mTracker = mGaInstance.getTracker("UA-XXXX-Y"); // your ID here
and that's basically it.. now you can send events with this tracker
mTracker.sendEvent(....);
etc..
Hope this helps. This is the very basics but GoogleAnalytics and Tracker replace the EasyTracker.
You can read more about it here:
Advanced Configuration - Android SDK
Just note that until you'll see the reports on the GA website, it can take up to 24 hours.. so be patient :) or use mGaInstance.setDebug(true) to see in the logcat that it has been sent
I would suggest not to do so unless you are very sure what you are doing.
I implemented GA events in my service but it corrupted a lot of my GA stats such as session duration, daily percentage of new sessions, daily sessions etc.
GA thinks that events are caused after a screen view and so it pushes the GA event with a screen name "(not set)".
Since services ran in the background a lot of times, it ended up corrupting the various stats.
The real-time display of active users also went wrong.

Categories

Resources