My main problem is very similar to How to grant userpoints to users who perform a login 5 days consecutively?. As Mike correctly notices in his answer on that question, his solution will not work for users who leave their browser logged in. Therefore, I do not want to hook into a login, but into "visiting the website" (i.e. accessing any page).

I am fine with both Rules and custom code. In the first case, which Rules event can I use? For performance reasons, it is in both cases desirable that the hooking takes place as few times as possible (in the best case once a day per visiting user). Is restricting the visited page to a particular one, say, the homepage the only way to achieve that?

1 Answer 1


Using Rules Event "Drupal is initializing" (within "System") for sure will do the job:

  • It doesn't depend on login (can be used for any role).
  • It applies to any path (a node, a view, etc).

Should you want to do so, you can also add any desired Rules Conditions (eg to only consider selected paths, eventually using RegEx expression also).

Make it right before you make it better

I'm not sure this is the only way your question can be answered, but I do know that this Rules Event (Drupal is initializing) will do what you're asking for, which is to hook into "visiting the website" (i.e. visiting any page) (as in your question).

But, using this Rules Event also comes with a price: it will case this rule to be triggered on every page request (which is a pretty similar to your visiting any page). However, if this price is too high, maybe you want to consider any (or all?) of these compromises:

  • Add Rules Conditions such as "only for users with selected roles" (eg: authenticated, so that for Anonymous users the Rules Actions are not triggered).
  • Instead of any page, you only take into consideration something like "viewing content" (for which you know there are less expensive Rules Events available).
  • Thank you Pierre, that will certainly do. But I am a bit worried that Drupal is initializing is a bit expensive. I mean, the Rule will run on every page request, although it should actually be fired only once per day per visiting user. Are you sure this is the only way?
    – Jeroen
    Dec 19, 2016 at 20:01
  • Oh, that is your call. I would have deleted it, since it does not really add much value to me; I suppose anyone can find the correct event. But if my edit was rejected, I assume that there must be a good reason for it.
    – Jeroen
    Jan 18, 2017 at 17:26
  • 1
    No problem at all! Your answer is still the correct one and that is what counts. I will delete my comments once you have read this one.
    – Jeroen
    Jan 18, 2017 at 17:34

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.