3

Is there any hook_function/code in Drupal where I can track user activity, like:

  1. User core logged in time / or third party login
  2. User log out time
  3. Login-Logout session length (active time)
  4. registration submit core or / third party submit.

Please share event for these activity.

3
  • Try hook_user_login and hook_user_logout for 1 and 2
    – user15837
    May 6 '16 at 11:56
  • thanks, but same will work if I logged in using 3rd party apps like fb/G+ May 6 '16 at 11:57
  • I think it will work
    – user15837
    May 6 '16 at 11:59
3

For standard login, and 3rd-party login modules that are properly integrated with core, you can use:

For 3rd-party login modules that aren't properly integrated with core (i.e. don't fire those hooks), you'll need to approach each on a case-by-case basis, and find out what hooks they provide.

You could measure the duration of the session in hook_user_logout, by checking the account object's login property against the current time - there's no hook for such a thing as it's not an event, just a value which needs some context to give it meaning.

1

Have a look at the Event log module (a module also consists of "Drupal code", right?). Some details about it, from its project page:

This module logs specific events. The events are saved in the database and can be viewed on the page admin/reports/events. Furthermore, a views integration is provided in which you can relate for instance a node to its events. You could use this to display the total number of views, or the number of times that the node has been modified and by which users.

Currently, the following events are supported:

  • User authentication (login/logout/request password)
  • Node operations (CRUD)
  • User operations (CRUD)
  • Menu operations (custom menu's and menu items CUD operations)
  • Taxonomy operations (vocabulary and term CUD operations)

The event log can be easily extended with custom events. For more information please have a look at the API documentation and the available sub modules.

You are probably going to be interested in these specific events and facilities of it:

  • User authentication.
  • User operations (CRUD).
  • ... log can be easily extended with custom events.
  • Views integration.
  • API documentation.
  • The available sub modules.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.