Score:0

Time spent with custom module

us flag

Can anyone help me with this, I want to activate time spent module on my custom form module, and store the time spent on a field on my form. I think that I could do it on the file timespent.module here.

function time_spent_init() {
  //if user has a role who is going to be tracked, add javascript code
  if (time_spent_user_has_role()) {
    $timer = variable_get('time_spent_timer', TIME_SPENT_TIMER);
    $limit = variable_get('time_spent_limit', TIME_SPENT_LIMIT);
    $mynide = -1; //false value
    //checks if this is a node page. taxonomy or views pages won't be counted.
    //confirm if this node type and user role will be tracked
    $nodetypes = variable_get('time_spent_node_types', 'all');
    if ($node = menu_get_object()) {
      if (($nodetypes == 'all' || $nodetypes[$node->type] === $node->type )) {
        $mynide = $node->nid;
      }
    }
    drupal_add_js(drupal_get_path('module', 'time_spent') . '/time_spent.js');
    drupal_add_js(array('time_spent' => array('timer' => check_plain($timer), 'limit' => check_plain($limit), 'nid' => $mynide, 'sectoken' => drupal_get_token())), 'setting');
  }
}
Score:0
us flag

Maybe this can help someone, I found how to do it.

I have a custom module to create a form and I want to make "timespent" work and track user time spend on this page.

I use URL to get it work.

$nodetypes = variable_get('time_spent_node_types', 'all');
if ($node = menu_get_object()) {
  if (($nodetypes == 'all' || $nodetypes[$node->type] === $node->type )) {
    $mynide = $node->nid;
  }
}

This code searches the id of the node, for my purposes I replace this like that

if (arg(0) == 'module' && arg(1) == 'form') {
  $mynide = arg(3); // for me arg(3) is the nid i want to track
}
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.