I want to trace each user time spent in my Facebook application.
I really don't have any idea how to code this, help me out. If someone has any ideas or hints, that will be enough.
I am using Graph API.
Either: Google Analytics
The easiest solution of course is using Google Analytics - FBML (Facebook Markup Language) has a tag specifically for that: http://developers.facebook.com/docs/reference/fbml/google-analytics
That of course doesn't give you data on what a specific user did, but it is pretty good at telling you the time spent on various pages in your Facebook app. And morally its much nicer not to store what a specific user did exactly on your site.
Or: Self-coded solution
If you do want to track everything specifically, you'll first need to store when a page was accessed using PHP when loading the site and then storing in 10-seconds-intervals (or so) that the user is still present, using an AJAX call. To do that, I'd give the page view an ID and send a request to a page like this *i_am_still_here.php?p={page_view_id}* which takes the current timestamp and updates a database entry for that page view.
This solution has one problem: When a user opens a tab in the background and doesn't look at it for 30 minutes, you don't really want to store that 30 minutes as "the user being on the site". Also, make sure that with whatever self-coded solution you choose, you have to take into consideration that people might have your Facebook app opened in more than one tab.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With