/ Published in: PHP
Below are two functions I've been using to make event tracking a little easier in CodeIgniter.
Two functions are available, google_analytics() & track_event().
google_analytics() takes one argument and uses it as the UA code for your tracking profile. track_event has two required parameters, $category and $event. The other two items are optional and won't be inserted unless specified.
Usage is pretty straight-forward:
Two functions are available, google_analytics() & track_event().
google_analytics() takes one argument and uses it as the UA code for your tracking profile. track_event has two required parameters, $category and $event. The other two items are optional and won't be inserted unless specified.
Usage is pretty straight-forward:
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php # # Google Analytics Code # { function google_analytics($account) { $code = "<script src='http://www.google-analytics.com/ga.js' type='text/javascript'>"; $code .= '<script type="text/javascript">'; $code .= ' try{ '; $code .= ' var pageTracker = _gat._getTracker("'.$account.'"); '; $code .= ' pageTracker._trackPageview(); '; $code .= ' } catch(err) {} '; $code .= '</script>'; return $code; } } # # Event Tracking # { function track_event($category, $action, $label = '', $value = '') { $code = 'pageTracker._trackEvent('; $code .= "category = '$category' "; $code .= "action = '$action' "; $code .= ( $label == '' ) ? '' : "label ='$label'"; $code .= ( $value == '' ) ? '' : "value ='$value'"; $code .= ');'; return $code; } }