Create "visitorCreate" event

This commit is contained in:
Dmitriy Simushev 2014-10-17 14:37:01 +00:00
parent e61b91dd5e
commit de1d5d6d51
2 changed files with 27 additions and 0 deletions

View File

@ -156,6 +156,18 @@ final class Events
*/
const RESOURCE_NOT_FOUND = 'resourceNotFound';
/**
* Visitor is created.
*
* This event is triggered when a visitor is tracked by the widget for the
* first time. An associative array with the following items is passed to
* the event handlers:
* - "visitor": array, list of visitor's info. See returned value of
* {@link track_get_visitor_by_id()} function for details of its
* structure.
*/
const VISITOR_CREATE = 'visitorCreate';
/**
* Visitor is tracked by the system.
*

View File

@ -18,6 +18,8 @@
*/
// Import namespaces and classes of the core
use Mibew\EventDispatcher\EventDispatcher;
use Mibew\EventDispatcher\Events;
use Mibew\Database;
use Mibew\Settings;
use Mibew\Thread;
@ -45,6 +47,16 @@ function track_visitor($visitor_id, $entry, $referer)
}
}
/**
* Initialize visitor tracknig.
*
* Triggers {@link \Mibew\EventDispatcher\Events::VISITOR_CREATE} event.
*
* @param string $entry The page the visitor came from to the page with
* tracking code.
* @param string $referer The page where tracking code is placed.
* @return int ID of the visitor.
*/
function track_visitor_start($entry, $referer)
{
$visitor = visitor_from_request();
@ -71,6 +83,9 @@ function track_visitor_start($entry, $referer)
track_visit_page($id, $referer);
}
$args = array('visitor' => track_get_visitor_by_id($id));
EventDispatcher::getInstance()->triggerEvent('visitorCreate', $args);
return $id ? $id : 0;
}