CodeIgniter的Google分析助手
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeIgniter的Google分析助手相关的知识,希望对你有一定的参考价值。
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:
<?php # # Google Analytics Code # { function google_analytics($account) { $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; } }
以上是关于CodeIgniter的Google分析助手的主要内容,如果未能解决你的问题,请参考以下文章