User Time Spent Module

This module helps to monitor authenticated users. Whenever user gets login, how much time the user spent for a single page will get list in this callback /time-spent/all/user with count.

Users List

Particular user details will be in /time-spent/{user_id}/user with date specific.

single user

Configuration:

User Time Spent Module is providing with a configuration for roles wise selection. for whom needs to track and for whom no need to track. This will also have a configuration to track only for particular URL or site wide URL.

Config

Dependencies:

  • Date Module
  • Views Module

Sandbox:
https://www.drupal.org/sandbox/sathish92/2935333

Comments

sathish92 created an issue. See original summary.

sathishkumar.k’s picture

Issue summary: View changes
sathishkumar.k’s picture

Issue summary: View changes
sathishkumar.k’s picture

StatusFileSize
new7.77 KB
new4.59 KB

Please review! working version.

sathishkumar.k’s picture

sathishkumar.k’s picture

Status: Active » Needs review
PA robot’s picture

Status: Needs review » Needs work

Git clone command for the sandbox is missing in the issue summary, please add it.

We are currently quite busy with all the project applications and we prefer projects with a review bonus. Please help reviewing and put yourself on the high priority list, then we will take a look at your project right away :-)

Also, you should get your friends, colleagues or other community members involved to review this application. Let them go through the review checklist and post a comment that sets this issue to "needs work" (they found some problems with the project) or "reviewed & tested by the community" (they found no major flaws).

I'm a robot and this is an automated message from Project Applications Scraper.

sathishkumar.k’s picture

Issue summary: View changes
sathishkumar.k’s picture

Status: Needs work » Needs review
PA robot’s picture

Status: Needs review » Needs work

There are some errors reported by automated review tools, did you already check them? See http://pareview.sh/pareview/httpgitdrupalorgsandboxsathish922935333git

I'm a robot and this is an automated message from Project Applications Scraper.

markusd1984’s picture

@sathish92 How does this compare to https://www.drupal.org/project/time_spent ?

sathishkumar.k’s picture

Hi @markusd1984 this module https://www.drupal.org/project/time_spent track only node page not custom page but our module track site overall pages (include custom page).

markusd1984’s picture

@sathish92 tried the user time spent with count module but couldn't access the user stats with /time-spent/USERNAME/user.

Besides having these stats accessible in a tab within user profile is handy, better even if there is a page for reporting :)

sathishkumar.k’s picture

@markusd1984 use /time-spent/{user_id}/user instead of /time-spent/USERNAME/user.

Thanks for your suggestion for handy tab in an user profile. We add this feature in next version.

sathishkumar.k’s picture

Status: Needs work » Needs review
rajveergangwar’s picture

@sathish92

Please add git clone url to issue.

rajveergangwar’s picture

@sathish92,

I have reviewed your module, Reviews are below:

Reviews are given below:

README.txt File is missing.

user_time_custom.js file doc is missing.

user_time_spent.js file doc is missing.

Review of .install file

1) File doc comment is missing
2) Why function user_time_spent_uninstall() {} is blank
3) Table name should start with your module name prefix, So mysql table will be user_time_spent_time_spent and user_time_spent_time_spent_day
4)

'created' => array(
			'description' => 'created time', // created timestemp will be good
			'type' => 'int',
			'not null' => TRUE,
		),
		'updated' => array(
			'description' => 'updated time', // Updated timestemp will be good
			'type' => 'int',
			'not null' => TRUE,
		),

5) Why the description for both tables are same ?

Review of .module file

1) Please write hook_help for module
2) Move below code to hook_preprocess_page

  if (arg(0) == 'admin' && arg(1) == 'config' && arg(2) == 'people' && arg(3) == 'user' && arg(4) == 'time_spent_count') {
			drupal_add_js(drupal_get_path('module', 'user_time_spent') . '/js/user_time_custom.js');
		  }

3) Functionality you have written in hook_init, you can move to hook_preprocess_page.
You can take reference from this url: https://www.drupal.org/forum/support/module-development-and-code-questio...
4) In hook_permission your permission name should contain module name.
5) In function time_spent_data() there is below mistakes

db_query("select count,time from {time_spent} where uid = '".$user->uid."' and session_url = '".$pathname."'")->fetchAll();

$day_is_empty = db_query("select count,time from {time_spent_day} where uid = '".$user->uid."' and session_url = '".$pathname."' and FROM_UNIXTIME(created, '%d-%m-%Y') = '".date('d-m-Y')."'")->fetchAll();

$update = db_query("update {time_spent_day} set count = $cnt, time = $update_time where uid = '".$user->uid."' and session_url = '".$pathname."' and FROM_UNIXTIME(created, '%d-%m-%Y') = '".date('d-m-Y')."'")->execute();

Use placeholder for all above queries.
6)

 if (empty($chck_is_empty)) {
	db_insert('time_spent')->fields(array(
		  'uid' => $user->uid,
		  'session_url' => $pathname,
		  'count' => 1,
		  'time' => $time_diff,
		  'created' => REQUEST_TIME,
		  'updated' => REQUEST_TIME,
		))->execute();
  }
else { 
	db_update('time_spent')->fields(array(
         'count' => $chck_is_empty[0]->count + 1,
	 'time' => $chck_is_empty[0]->time + $time_diff,
	  'updated' => REQUEST_TIME,
	))
	->condition('uid', $user->uid, '=')
	->condition('session_url', $pathname, '=')
	->execute();
}

Use db_merge for above logic.
7) The file must end with an empty line.

rajveergangwar’s picture

Assigned: sathishkumar.k » Unassigned
Status: Needs review » Needs work

Issues are found, So marking this issue to needs work.

avpaderno’s picture

Status: Needs work » Closed (won't fix)

If you are still working on this application, you should fix all known problems and set the status to Needs review. (See also the project application workflow.)
Please don't change status of this application if you aren't sure you have time to dedicate to this application, or it will be closed again as won't fix.

I am closing this application due to lack of activity.