1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Tracking_lib
{
private $CI;
private $tracking;
public function __construct()
{
$this->CI =& get_instance();
$clientId = $this->CI->Appconfig->get('client_id');
if(!empty($clientId) && strlen($clientId) < 30)
{
$clientId = NULL;
}
$options = array(
'client_create_random_id' => TRUE,
'client_fallback_id' => 555,
'client_id' => $clientId,
'user_id' => NULL,
'adapter' => array(
'async' => TRUE,
'ssl' => FALSE
)
);
$this->tracking = new \Racecore\GATracking\GATracking('UA-82359828-2', $options);
if(empty($clientId))
{
$clientId = $this->tracking->getClientId();
$this->CI->Appconfig->batch_save(array('client_id' => $clientId));
}
}
public function track_event($category, $action, $label = NULL, $value = NULL)
{
try
{
$event = $this->tracking->createTracking('Event');
$event->setAsNonInteractionHit(TRUE);
$event->setEventCategory($category);
$event->setEventAction($action);
$event->setEventLabel($label);
$event->setEventValue($value);
return $this->tracking->sendTracking($event);
}
catch(Exception $e)
{
error_log($e->getMessage());
}
}
public function track_page($path, $title, $description = ' ')
{
try
{
$event = $this->tracking->createTracking('Factory', array(
'an' => 'OSPOS',
'av' => $this->CI->config->item('application_version') . ' - ' . substr($this->CI->config->item('commit_sha1'), 5, 12),
'ul' => current_language_code(),
'dp' => $path,
'dt' => $title,
'cd' => $description
));
return $this->tracking->sendTracking($event);
}
catch(Exception $e)
{
error_log($e->getMessage());
}
}
}
?>