Track Custom Events

One of the biggest benefits of using the concrete5 Traffic and Statistics package is that it can track other events beyond full page views.  For example, it can track client side user interactions, like opening a popup window, or interacting with a photo browser.  These examples show you how to integrate this stats package with your own blocks and packages, so you can start tracking your own custom events.  

How to track an event from the frontend, with javascript:

If you'd like to track a user interaction as full page-view, you can fire this event from any javascript: 
$(document).trigger('statsPageView',{'title':'page name','url':'page view url'}); 

You can also call this event for a non-page-view event, such as rating a page or interacting with a widget. Doing so will prevent that even from effecting statistics like pages per visit, and they'll be shown in lighter grey when inspecting user visits. The variables url and eventVal are optional: 

How to track an event from the backend, with php:

Note: This method requires version 2 or above of the stats package. 

//First test to make sure that the user has the stats package installed

$pkg = Package::getByHandle('tony_stats');
if( $pkg ){

     //include the stats helper class

     //here i'm just getting the collection object so that i can get at the page title and URL
     $c = $this->getCollectionObject();

     // put the data into the required format, with a value for "title" and "url"
     // In this example i'm tracking a page view of an RSS feed
     $data = array('title'=> t('Feed:').$c->getCollectionName(), 'url'=>$c->getCollectionPath() );

     //and then save the event
     StatsHelper::quickTrack( $data );  


Like this post?
Tweet This

Enjoy this post?


Add a New Comment
(will not be made public)

Please type the letters and numbers shown in the image.Captcha Code