0

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');
  }
}
0

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
}

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.