There are a few user tracking checks I would like to perform before the site main page gets loaded. I don't really want to have to wait for drupal to load all the modules and start running the theme code before I do this.

Are there any hooks that can be overwritten to perform my checks?

  • 3
    – kalabro
    Jul 25, 2012 at 14:47

1 Answer 1


I don't recommend using hook_init() as it doesn't run on cached pages. Try using hook_boot(). As per the documentation it runs at the beginning of the page request when Drupal is still in the bootstrap. Hope this helps!

  • Okay, This does answer my question, but I now realize... how do I use this hook? If no modules are loaded at this point, where should I overwrite this hook? the docs don't seem to give answers to these questions as far as I can tell.
    – Onema
    Jul 25, 2012 at 16:48
  • 1
    @Onema hook_init() must be implemented in a custom module. The function mymodule_init() would go into a file named mymodule.module in a custom module named mymodule. You would also supply a simple mymodule.info file and put both files in the sites/sitename/modules/mymodule directory. The custom module must be enabled like any other. Also, when creating a hook implementation, it is usually necessary to clear the cache for Drupal to recognize it. Finally, note that mymodule needs to be a unique name different from other modules or themes. Jul 25, 2012 at 16:53
  • 4
    hook_init() and hook_boot() are obviously executed after the modules have been loaded, a hook is by definition something that can be implemented by a module. You can't invoke a hook before the modules are loaded. Also note that if you want to track authenticated users, then hook_init() is the recommended way to do so, pages aren't cached for them anyway.
    – Berdir
    Jul 25, 2012 at 18:54
  • @Berdir: I think you could post it as a separate answer, your comment was really helpful. Not to mention that in fact it IS an answer to the original question, too. :) hanleyhansen: +1, your post was useful too.
    – Sk8erPeter
    Aug 1, 2012 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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