It’s very common to track the user behaviour in an app and if you are not doing that in your app, you should definitely use some analytics tool to do that. You can not make improvements to your app unless you know what exactly is happening with your users.
If you are using some Standard analytics tool like Flurry or Google Analytics, don’t bother reading this post. But if you are tracking some data without the help of these tools, then the curious question arises when do i send the data from app to server.
If you are implementing some real time analytics, then you might have to send data immediately back to the server with a very minimum delay of lets say around 5-10 secs, anything more than that will not add the value to the term real time.
On the other hand, if the analytics are digested in the real time, then there is no need to hurry, Do i send the data every time the user switches from screen to other screen?, it is a good way but not optimum if you want less pings to your server, considering the data can be coming from a lot of users.
The objective is to reduce the server load and also to maintain no data loss that is being sent to server.
My approach would be to first store the data in the local database and at every screen exit start a timer to send the data to the server, the key is to find the optimum delay for the timer.
1. If the user exits another screen before the you send the data, cancel the existing timer and start a new one. This way we are sending the data back to the server only when there is a long interval between the user actions and being postponed if there isn’t much time difference between user actions.
2. If there isn’t any other screen exit then the first timer will send the data back to the server.
You can also implement an ACK mechanism to make sure there is no loss of data, and you wipe the data from the local database only if you receive an ACK. If your backend is reliable enough to process all the data received there is no need to wait for an ACK.