Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate time spent in Facebook application?

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.

like image 940
xainee khan Avatar asked Dec 28 '10 18:12

xainee khan


1 Answers

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.

like image 141
Sebastian Avatar answered Oct 24 '22 00:10

Sebastian