Have a custom plugin do something on every page load? For an upcoming site build, I'm going to need to capture information on every page load for a number of sections. These will be pages based on standard entries, so I'd prefer to use traditional routing (so not handled through a custom controller). There will probably be three different sections that will each have the same information captured when the page is loaded – basically just a list of categories so we can track the most popular type of content and display it as a dashboard widget.

At first I assumed I could do this with an event, but it doesn't look like there are any events for a page being loaded. I'm currently thinking that I use JavaScript to fire an AJAX request to a plugin and send the data along. This will work, but generate extra page loads. I'm thinking it'd be more efficient if I could keep everything server side.

Is there some way to do this that I'm not seeing?
Add a init() method to your plugin and as long as it's installed and enabled, it'll be called on every request.

public function init()
{
    parent::init();

    /* Do your stuff */
}


If you want it to only happen on front-end requests, you can use:

if (craft()-&gt;request-&gt;isSiteRequest()) { ... }