Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Track time spent in application

What should I use to track how long is user using my application on iOS devices?

I think I can do it like this:

  1. Log time on App startup (application:didFinishLaunchingWithOptions:)
  2. Log time on App ending (applicationWillTerminate:)
  3. List item

Send report (pairs of start/exit time) to server and count time spent in app

Do you have any better ideas?

Important is to be network and resources effective
(not to send big amount of data or consume iOS resources on complex computing operations.)

like image 560
Marek Sebera Avatar asked Jul 20 '11 17:07

Marek Sebera


3 Answers

Notice that applicationWillTerminate: is not necessarily called when the home button is pressed (this changed from iOS 3.X to iOS 4.0).

Take a look at applicationDidEnterBackground: and applicationWillEnterForeground:

More here.

like image 66
Monolo Avatar answered Oct 17 '22 10:10

Monolo


I believe that calculating the time on the device itself would be best, considering you want this to be network and resource effective. The calculation of endTime - starTime will be very very fast (depending on your time implementation), and then you would only need to send one piece of data (the time it took) over a network instead of two (the start and end times).

Hope this helps! N.S.

like image 41
Jonathan Pitre Avatar answered Oct 17 '22 11:10

Jonathan Pitre


Seems like a reasonable way to do it. It's efficient enough, and depending on how you see the data, it shouldn't be more than a kilobyte or two, if that. Be wary of privacy issues though—users are really against being logged.

like image 1
FeifanZ Avatar answered Oct 17 '22 10:10

FeifanZ