2014-09-24 43 views
0

嗨,我有一個谷歌分析腳本,我需要在網站的每一個頁面放置,並且網站是在代碼ignatior中開發的,我很困惑如何放置腳本,我可以在codeignatior的每個頁面(view)中放置下面的sript,還是應該將腳本放在一些php文件中,以便我可以在codeignatior視圖中包含該文件,請指導我作爲codeignatior和google analytics的新手 請問谷歌分析腳本工作,如果我把它的頁眉或頁腳文件codeignatior..please指導我這個 將谷歌分析腳本放在codeignatior的每一頁中

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ 
some code 

    ga('send', 'pageview'); 
//$trackingCode = file_get_contents('yourFile'); 
</script> 

回答

0

創建核心類,並與CI_擴展它控制器 應用/核心/

class TEST_Controller extends CI_Controller { 
    protected $footer_view; 
    protected $footer_data; 
    public function __construct() { 
     parent::__construct(); 
     $this->footer_data = array(); 
    $this->footer_view = 'footer'; 

    } 
    public function _output($output) { 
    echo $this->load->view($this->footer_view, $this->footer_data, true); 
} 
}//TEST_Controller.php 

,並創建視圖文件,該文件會自動包含每一個要求。
應用程序/視圖/

<script> 
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ 
some code 

    ga('send', 'pageview'); 
//$trackingCode = file_get_contents('yourFile'); 
</script> 
//footer.php 

最後當你創建你的控制器擴展到這個核心類像
應用/控制器

class Contact extends TEST_Controller { 

    function __construct() { 
     parent::__construct(); 
    } 
    function index(){ 
     echo "bla bla"; 
    } 
}