I am developing a Unity3D game. I want to show in my game:

  1. Total time spent playing all time by all players around the world
  2. Total time spent playing in last 24 hours by all players around the world

I heard that it can be achieved by analytics services like Flurry / Google Analytics. I did some research but I am not getting anywhere by myself. Can anybody guide me to the right path?


2 Answers 2


The best option is to use a database to store your player data. What database to use is ultimately in your court and what seems relevant based on your own research.

Inputting that data into a database should be easy for these two metrics simply because you're only talking about tracking the login date and timestamps of your players. Those timestamps will have to be stored every time they log into the game and when they log out.

Then simply put, you could query your player log data to return a result to Unity that displays in game as the TSQL query example below:

  ,DATEDIFF(MINUTES,[log-on-time],[log-off-time]) AS [Time Difference]
WHERE [player-id] = ...

Then this would result in the time difference between the log on time and log off time. Of course, if the user is currently playing, then you can alter the query to use GETDATE() functions depending on the RDBMS you are using to get the time difference between the log-on-time and the database server time for live players and ETC.

I would recommend this as opposed to trying to find a quick-fix or possibly licensing someone elses analytical reporting system. That's because you may find yourself wanting to store more data about your players that you also want to report on in-game as well out-of-game for your own personal metrics of the games progression.

  • \$\begingroup\$ You forgot to mention that if she's looking for the last day, missing login dates needs to be REPLACED with 24h ago. It is a bit more complicated this way. I highly suggest simply firing an "I'm active for 10 seconds every 10 seconds" record. You can simply count these and it helps prevent strange bugs. \$\endgroup\$
    – AturSams
    Oct 17, 2014 at 6:23
  • \$\begingroup\$ Needing to extend in the future is not a good reason to avoid using someone else's analysis tool. There is nothing wrong in using something that has already been built well to save time. New features can be added outside a specific tool and most tools allow for extension. \$\endgroup\$
    – AturSams
    Oct 17, 2014 at 6:28
  • \$\begingroup\$ Just to be clear, the issue with recording loging and logout dates, is that you need to know the logout date. What if the user exited abnormally? What if the server had a malfunction? Either way you are bound to end up polling for connectivity if you want reliable results. This is why I recommend creating a record every x seconds. \$\endgroup\$
    – AturSams
    Oct 17, 2014 at 6:36

You simply need a database. You store the login time and the logout time. You then simply compute and aggregate the time. This could be done continuously or whenever it is needed.

Another option that is easier to implement but a little bit more resource intensive is to have all players "fire" a http request every 10 seconds (or similar) to the server that creates a record in the database that signifies they have now been playing for 10 seconds straight. Then to sum up the amount of time that has been played you simply do a count on such records from the past day and sum up the total and multiply by 10 seconds. Older records could be aggregated and deleted from the database to free up space.

  • \$\begingroup\$ Is it possible by using the analytics I mentioned here? \$\endgroup\$ Oct 16, 2014 at 20:36
  • \$\begingroup\$ It is a very simple task, there are several ways to go about it. Like I said going the "straight forward" "brute force" way would work here. I don't see the point of bike sheding something like auditing login time and or activity time during gameplay. If you must use the beta: github.com/googleanalytics/google-analytics-plugin-for-unity You can raise an issue there but it's quite straight forward. \$\endgroup\$
    – AturSams
    Oct 16, 2014 at 21:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .