Events

View Count events follow the same pattern as standard Craft events (opens new window).

use doublesecretagency\viewcount\services\View;
use doublesecretagency\viewcount\events\ViewEvent;
use yii\base\Event;

// Do something BEFORE an element is viewed...
Event::on(
    View::class,
    View::EVENT_BEFORE_VIEW,
    function(ViewEvent $event) {

        // Do something before view...

        // Optionally prevent view from being recorded
        // $event->isValid = false;

    }
);
use doublesecretagency\viewcount\services\View;
use doublesecretagency\viewcount\events\ViewEvent;
use yii\base\Event;

// Do something AFTER an element is viewed...
Event::on(
    View::class,
    View::EVENT_AFTER_VIEW,
    function(ViewEvent $event) {

        // Do something after view...

    }
);