This module tracks, by Ajax, how long a registered user took to read a page.

You can configure which content type and role should be tracked and view the report, exhibiting the total hours (or minutes/seconds) a user spent reading a page. The interval between one Ajax call and other can be configurable trough UI also.

There isn't any module dependency.

USE CASE:
You need to track and exhibit a statistic report with the amount of time a registered user took reading a node page.

LIMITATIONS:
- This module only tracks node pages and registered users. Taxonomy or views pages aren't tracked, but can be in later versions.
- If you need to track anonymous visits, consider using Google Analytics (GA can't track registered users by its privacy terms).

RECOMMENDATIONS:
Session Aggregator can track the total time a user has spent on the site.
Automated Logout provides a site administrator the ability to log users out after a specified time of inactivity.
Session Limit allows administrators to limit the number of simultaneous sessions per user.

Obs.: These modules aren't required, but if you need to track the amount of time a user spent, probably you'll like them also.

SANDBOX:
http://drupal.org/sandbox/carvalhar/1255040

CommentFileSizeAuthor
#3 user_time_page.zip4.5 KBcarvalhar
user_time_page.zip3.78 KBcarvalhar

Comments

carvalhar’s picture

Issue summary: View changes

forgot

berkas1’s picture

Status: Needs review » Postponed

You have to post a link to your sandbox project to review

carvalhar’s picture

Status: Postponed » Needs review
carvalhar’s picture

Issue summary: View changes

missing closing tag

carvalhar’s picture

StatusFileSize
new4.5 KB

adding a newer version already.
Now there's a configurable LIMIT variable between the Ajax calls.

carvalhar’s picture

Today, I added a new function (track time spent on the entire site) and uploaded to the sandbox git.
Added some screenshots also:
http://carvalhar.com/componente/drupal/time_spent/index.html
I hope to be approved ;)

attiks’s picture

Status: Needs review » Needs work

I did a quick Coder review to check the Coding Standards, see below.

Severity minor, Drupal Commenting Standards, Drupal Security Checks, Drupal SQL Standards, Drupal Coding Standards, Internationalization

sites/all/modules/time_spent/time_spent.module:
+4: [minor] There should be no trailing spaces
+7: [minor] There should be no trailing spaces
+23: [normal] Menu item titles and descriptions should NOT be enclosed within t().
+24: [normal] Menu item titles and descriptions should NOT be enclosed within t().
+31: [normal] Menu item titles and descriptions should NOT be enclosed within t().
+32: [normal] Menu item titles and descriptions should NOT be enclosed within t().
+50: [normal] Use an indent of 2 spaces, with no tabs
+56: [normal] Use an indent of 2 spaces, with no tabs
+57: [normal] Use an indent of 2 spaces, with no tabs
+58: [normal] Use an indent of 2 spaces, with no tabs
+58: [minor] There should be no trailing spaces
+59: [normal] Use an indent of 2 spaces, with no tabs
+59: [minor] There should be no trailing spaces
+60: [normal] Use an indent of 2 spaces, with no tabs
+61: [normal] Use an indent of 2 spaces, with no tabs
+62: [normal] Use an indent of 2 spaces, with no tabs
+63: [normal] Use an indent of 2 spaces, with no tabs
+63: [minor] There should be no trailing spaces
+64: [normal] Use an indent of 2 spaces, with no tabs
+65: [normal] Use an indent of 2 spaces, with no tabs
+66: [normal] Use an indent of 2 spaces, with no tabs
+66: [normal] use a space between the closing parenthesis and the open bracket
+66: [minor] There should be no trailing spaces
+67: [normal] Use an indent of 2 spaces, with no tabs
+68: [normal] Use an indent of 2 spaces, with no tabs
+69: [normal] Use an indent of 2 spaces, with no tabs
+70: [normal] Use an indent of 2 spaces, with no tabs
+71: [normal] Use an indent of 2 spaces, with no tabs
+71: [normal] missing space after comma
+92: [normal] Use an indent of 2 spaces, with no tabs
+99: [normal] Use an indent of 2 spaces, with no tabs
+105: [normal] Use an indent of 2 spaces, with no tabs
+111: [normal] Use an indent of 2 spaces, with no tabs
+112: [normal] Use an indent of 2 spaces, with no tabs
+113: [normal] Use an indent of 2 spaces, with no tabs
+114: [normal] Use an indent of 2 spaces, with no tabs
+115: [critical] table names should be enclosed in {curly_brackets}
+115: [normal] Use an indent of 2 spaces, with no tabs
+115: [minor] There should be no trailing spaces
+116: [critical] table names should be enclosed in {curly_brackets}
+116: [normal] Use an indent of 2 spaces, with no tabs
+117: [normal] Use an indent of 2 spaces, with no tabs
+117: [minor] There should be no trailing spaces
+118: [normal] Use an indent of 2 spaces, with no tabs
+119: [normal] Use an indent of 2 spaces, with no tabs
+120: [normal] Use an indent of 2 spaces, with no tabs
+121: [normal] Use an indent of 2 spaces, with no tabs
+121: [minor] in most cases, replace the string function with the drupal_ equivalent string functions
+122: [normal] Use an indent of 2 spaces, with no tabs
+122: [normal] Functions should be called with no spaces between the function name and opening parentheses
+123: [normal] Use an indent of 2 spaces, with no tabs
+124: [normal] Use an indent of 2 spaces, with no tabs
+125: [normal] Use an indent of 2 spaces, with no tabs
+126: [normal] Use an indent of 2 spaces, with no tabs
+127: [normal] Use an indent of 2 spaces, with no tabs
+128: [normal] Use an indent of 2 spaces, with no tabs
+128: [minor] There should be no trailing spaces
+129: [normal] Use an indent of 2 spaces, with no tabs
+130: [normal] Use an indent of 2 spaces, with no tabs
+131: [normal] Use an indent of 2 spaces, with no tabs
+132: [critical] table names should be enclosed in {curly_brackets}
+132: [normal] Use an indent of 2 spaces, with no tabs
+132: [minor] There should be no trailing spaces
+133: [critical] table names should be enclosed in {curly_brackets}
+133: [normal] Use an indent of 2 spaces, with no tabs
+134: [normal] Use an indent of 2 spaces, with no tabs
+134: [minor] There should be no trailing spaces
+135: [normal] Use an indent of 2 spaces, with no tabs
+136: [normal] Use an indent of 2 spaces, with no tabs
+137: [normal] Use an indent of 2 spaces, with no tabs
+137: [minor] in most cases, replace the string function with the drupal_ equivalent string functions
+138: [normal] Use an indent of 2 spaces, with no tabs
+138: [normal] Functions should be called with no spaces between the function name and opening parentheses
+139: [normal] Use an indent of 2 spaces, with no tabs
+140: [normal] Use an indent of 2 spaces, with no tabs
+141: [normal] Use an indent of 2 spaces, with no tabs
+142: [normal] Use an indent of 2 spaces, with no tabs
+143: [normal] Use an indent of 2 spaces, with no tabs
+144: [normal] Use an indent of 2 spaces, with no tabs
+144: [minor] There should be no trailing spaces
+145: [normal] Use an indent of 2 spaces, with no tabs
+149: [normal] Use an indent of 2 spaces, with no tabs
+150: [normal] Use an indent of 2 spaces, with no tabs
+151: [normal] Use an indent of 2 spaces, with no tabs
+152: [critical] table names should be enclosed in {curly_brackets}
+152: [normal] Use an indent of 2 spaces, with no tabs
+152: [normal] string concatenation should be formatted with a space separating the operators (dot .) and non-quote terms
+153: [normal] Use an indent of 2 spaces, with no tabs
+154: [normal] Use an indent of 2 spaces, with no tabs
+154: [minor] There should be no trailing spaces
+155: [critical] table names should be enclosed in {curly_brackets}
+155: [normal] Use an indent of 2 spaces, with no tabs
+155: [normal] string concatenation should be formatted with a space separating the operators (dot .) and non-quote terms
+156: [normal] Use an indent of 2 spaces, with no tabs
+157: [normal] Use an indent of 2 spaces, with no tabs
+158: [normal] Use an indent of 2 spaces, with no tabs
+158: [minor] There should be no trailing spaces
+159: [normal] Use an indent of 2 spaces, with no tabs
+160: [normal] Use an indent of 2 spaces, with no tabs
+161: [normal] Use an indent of 2 spaces, with no tabs
+162: [normal] Use an indent of 2 spaces, with no tabs
+163: [normal] Use an indent of 2 spaces, with no tabs
+163: [minor] There should be no trailing spaces
+164: [normal] Use an indent of 2 spaces, with no tabs
+165: [normal] Use an indent of 2 spaces, with no tabs
+166: [normal] Use an indent of 2 spaces, with no tabs
+167: [normal] Use an indent of 2 spaces, with no tabs
+168: [normal] Use an indent of 2 spaces, with no tabs
+169: [critical] table names should be enclosed in {curly_brackets}
+169: [normal] Use an indent of 2 spaces, with no tabs
+169: [normal] string concatenation should be formatted with a space separating the operators (dot .) and non-quote terms
+170: [normal] Use an indent of 2 spaces, with no tabs
+171: [normal] Use an indent of 2 spaces, with no tabs
+172: [critical] table names should be enclosed in {curly_brackets}
+172: [normal] Use an indent of 2 spaces, with no tabs
+172: [normal] string concatenation should be formatted with a space separating the operators (dot .) and non-quote terms
+173: [normal] Use an indent of 2 spaces, with no tabs
+174: [normal] Use an indent of 2 spaces, with no tabs
+175: [normal] Use an indent of 2 spaces, with no tabs
+176: [normal] Use an indent of 2 spaces, with no tabs
+177: [normal] Use an indent of 2 spaces, with no tabs
+178: [normal] Use an indent of 2 spaces, with no tabs
+179: [normal] Use an indent of 2 spaces, with no tabs
+180: [normal] Use an indent of 2 spaces, with no tabs
+181: [normal] Use an indent of 2 spaces, with no tabs
+181: [minor] There should be no trailing spaces
+182: [normal] Use an indent of 2 spaces, with no tabs
+185: [normal] Functions should be called with no spaces between the function name and opening parentheses
+185: [normal] Use uppercase for PHP constants, e.g. NULL, TRUE, FALSE
+186: [minor] There should be no trailing spaces
+187: [minor] There should be no trailing spaces
+188: [minor] There should be no trailing spaces
+189: [normal] string concatenation should be formatted with a space separating the operators (dot .) and non-quote terms
+190: [normal] string concatenation should be formatted with a space separating the operators (dot .) and non-quote terms
+190: [minor] There should be no trailing spaces
+191: [minor] There should be no trailing spaces
+192: [normal] string concatenation should be formatted with a space separating the operators (dot .) and non-quote terms
+193: [minor] There should be no trailing spaces
+195: [minor] There should be no trailing spaces
+201: [normal] Use an indent of 2 spaces, with no tabs
+206: [normal] Use an indent of 2 spaces, with no tabs
+206: [minor] There should be no trailing spaces
+207: [normal] Use an indent of 2 spaces, with no tabs
+207: [minor] There should be no trailing spaces
+210: [normal] Use an indent of 2 spaces, with no tabs
+211: [normal] Use an indent of 2 spaces, with no tabs
+212: [normal] Use an indent of 2 spaces, with no tabs

sites/all/modules/time_spent/time_spent.install:
+-1: [normal] @file block missing
+22: [normal] Use an indent of 2 spaces, with no tabs
+34: [normal] Use an indent of 2 spaces, with no tabs
+49: [normal] Use an indent of 2 spaces, with no tabs
+49: [minor] There should be no trailing spaces
+50: [normal] Use an indent of 2 spaces, with no tabs
+64: [normal] Use an indent of 2 spaces, with no tabs

sites/all/modules/time_spent/time_spent.js:
No Problems Found

Status Messages:
Coder found 1 projects, 3 files, 8 critical warnings, 118 normal warnings, 28 minor warnings, 0 warnings were flagged to be ignored

carvalhar’s picture

Status: Needs review » Needs work

ok, i sent by git the fixed files.

Is everything ok now?

thanks

carvalhar’s picture

Status: Needs work » Needs review

changing status

attiks’s picture

Status: Needs work » Needs review

Good work, I had a closer look at the code

1/ inside time_spent_init you better use menu_get_object, it return you the node if you're on a node page
2/ the comment on line 153 should read //monitors the time user spent on the site
3/ people can fool the system, if a open time_spent/1 and hit refresh a couple of times, the system will think i was on node/1 for a couple of minutes

attiks’s picture

Status: Needs review » Needs work
carvalhar’s picture

Status: Needs work » Needs review

Hi,
I'm using now menu_get_object.

About #3, yes, that's true.
User can fool the system if he discover the ajax url. But at first, he needs to know that he's being monitored and discover how this is happening (someone with javascript knowledge can discover by firebug kind easy although).

I think i can pass to ajax a hash made with session id and drupal key and the time the server send minus the timer settings. But it's not simple...I can't imagine a simple way to do this...Do you have any idea?

Right now, I'll let this as a future thing to fix.

Is everything ok?

thanks

attiks’s picture

Status: Needs review » Needs work

There are some minor trailing white spaces and indentation problems

The following code is 'strange', and the function needs better indentation

//if you do use caching use hook_boot instead
//function time_spent_boot() {
function time_spent_init() {

you can not expect end users to change your module, so I see 2 options:
a/ remove the comment and explain in the readme file
b/ just use hook_init, it normally will fire for each request for non-anon users, so remove the comment

carvalhar’s picture

Status: Needs work » Needs review

ok, removed the comment and edited the README.txt
git done. everything up-to-date.

attiks’s picture

Status: Needs review » Needs work

Last round, almost there

time_spent.install:
lines 48-50: you may remove these, primary key is unique
lines 76-78: you may remove these, primary key is unique
also check the indentation

time_spent.js:
6-9: just remove it, add it later when it's implemented
15-16: better remove all code in comment

time_spent.module:
+4: [minor] There should be no trailing spaces
+7: [minor] There should be no trailing spaces
+61: [minor] There should be no trailing spaces
+113: [minor] There should be no trailing spaces
+115: [minor] There should be no trailing spaces
+127: [minor] There should be no trailing spaces
+131: [minor] There should be no trailing spaces
+133: [minor] There should be no trailing spaces
+143: [minor] There should be no trailing spaces
+145: [critical] Potential problem: "SELECT FROM {node}" statements should probably be wrapped in db_rewrite_sql() and with the alias for {node} table defined (e.g. {node} n)
+153: [minor] There should be no trailing spaces
+157: [minor] There should be no trailing spaces
+162: [minor] There should be no trailing spaces
+180: [minor] There should be no trailing spaces
+185: [minor] There should be no trailing spaces
+186: [minor] There should be no trailing spaces
+187: [minor] There should be no trailing spaces
+189: [minor] There should be no trailing spaces
+190: [minor] There should be no trailing spaces
+192: [minor] There should be no trailing spaces
+194: [minor] There should be no trailing spaces
+205: [minor] There should be no trailing spaces

the remark about line 145, is about

  $sql = 'SELECT node.title as title, node.nid as nid,  users.name as name, time_spent_page.timespent as timespent FROM {time_spent_page} INNER JOIN {users} ON time_spent_page.uid = users.uid INNER JOIN {node} ON node.nid = time_spent_page.nid';  

should be something like this

  $sql = db_rewrite_sql('SELECT n.title as title, n.nid as nid, u.name as name, ts.timespent as timespent FROM {time_spent_page} ts INNER JOIN {users} u ON ts.uid = u.uid INNER JOIN {node} n ON n.nid = ts.nid');

Always try to use ' instead of "

carvalhar’s picture

Status: Needs work » Needs review

ok thanks.
revised and commited to GIT.

attiks’s picture

Status: Needs review » Reviewed & tested by the community

code looks good to me

tim.plunkett’s picture

Status: Reviewed & tested by the community » Closed (duplicate)
Issue tags: -page, -statistics, -time, -user, -timer, -spent
tim.plunkett’s picture

Issue summary: View changes

sandbox

avpaderno’s picture

Title: User's Time spent on page » [D6] User's Time spent on page
Related issues: +#2702713: [D7] Duplicate Images