Hi All!

Currently trigger tracks all visits of a user, so there could be a statistic of visits as it's shown below:

admin
1 sec ago
admin
13 sec ago
admin
54 min 30 sec ago
admin
56 min 27 sec ago
admin
58 min 24 sec ago
admin
58 min 36 sec ago
admin
1 hour 1 min ago
admin
1 hour 16 min ago
admin
1 hour 16 min ago

So, user may reload page, for example, 5 times (e.g. because it's loading too long) and all these reloads will be tracked as visits -- this work as a spam for users, who are interesting in such statistic.

It could be great to have an option which sets a time delay between points when system tracks visits of a user.

PS: I created a custom module for tracking of visits, but then found that Activity can do this too. Now I don't want to use my own modle, because I really like how the Activity works :)

CommentFileSizeAuthor
#5 expand_activity_record-1255090.patch4.78 KBss81

Comments

sirkitree’s picture

In the DEVELOPER.txt there are some hooks defined that you can utilize for this. One allows you to do something before activity is recorded. I would suggest utilizing that hook, do you checking, and only record based on your time sensitivity.

ss81’s picture

Category: feature » support
Priority: Normal » Minor

Hello Jerad Bitner,

Thank you for suggetion! I will try to use these hooks. Could we leave this post, so I will be able to add an example of code here?

--
Best regards,
Sergei

ss81’s picture

Component: Code » Documentation
Category: support » bug

There is a mistake in DEVELOPER.txt, as well as on http://drupal.org/node/626914:

Example:
/**
* Implementation of hook_activity_records_alter().
*/
function example_activity_records_alter(&$record, $context) {
// If we have a story node rather than another type, we can change the
// token pattern.
if ($object->type == 'story') {
$author_pattern = $context['author-pattern'] .' - [node-type]';
$record->author_message = token_replace($author_pattern, $record->type, $context[$record->type]);
}
}

The name of function should be example_activity_record_alter() instead of example_activity_recordS_alter()

ss81’s picture

Unfortunately, record is always recorded to DB. There is the code:

  // allow other modules to manipulate the record before insertion
  drupal_alter('activity_record', $record, $context);
  drupal_write_record('activity', $record);

Even if I unset the $record in my hook, the empty record would be recorded by drupal_write_record().

It could be great to add a condition and verify the $record after the call of drupal_alter():

  // allow other modules to manipulate the record before insertion
  drupal_alter('activity_record', $record, $context);

  // record could be cleared by other modules to avoid tracking.
  if (!isset($record)) {
    return;
  }

  drupal_write_record('activity', $record);
ss81’s picture

StatusFileSize
new4.78 KB

I've tried to use the hook_activity_message_recorded(). Unfortunately I can't avoid tracking from this hook because the table {activity_access} is filled after it:

  // after this is recorded, another module might want the aid
  module_invoke_all('activity_message_recorded', $record, $context);

  $grants = activity_get_grants($record);

  foreach ($grants as $realm => $values) {
    foreach ($values as $value) {
      // insert one by one. In D7 we can use the DBTNG to insert multiple
      $perm = new stdClass();
      $perm->aid = $record->aid;
      $perm->realm = $realm;
      $perm->value = $value;
      drupal_write_record('activity_access', $perm);
    }
  }

So, in hook_activity_message_recorded() I can verify a tracked activity (by $record->aid) and remove it, but I can't remove records from {activity_access}.

I added the condition which checks if $record is empty after the call of hook_activity_record_alter(). Now it works well.

The patch is attached. It could be great if you can check and test it.

PS: Eclipse cleared whitespaces, so patch is a bit long :( The changes, which I made, are located in lines 78-81.

ss81’s picture

Assigned: Unassigned » ss81
Status: Active » Needs review
_shy’s picture

Issue summary: View changes
Status: Needs review » Closed (outdated)

D6 reached its EOL back in February 2016, and there is no active release for D6 for this module anymore.
Development or support is not planned for D6. All D6-related issues are marked as outdated in a bunch.

If the issue remains relevant for D10+ versions, merge requests with proposed solutions for a new module version (D10+) are welcome in a new follow-up issue.

Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.