Hi i have a script of google analytics which i need to place in every and every page in the site,and site is developed in code ignatior,am confused how to place the script,can i place the the below sript in every page(view) of codeignatior,or should i place the script in some php file so that i can include the file in codeignatior view,please guide me as am new to codeignatior and google analytics Will the google analytics script works if i place it in header or footer file of codeignatior..please guide me on this
(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>
Create Core Class and extend it with CI_Controller application/core/
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
And Create view file which would automatically include to every request.
application/views/
<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
And Finally when you create your controller extend to this core class like
application/controllers
class Contact extends TEST_Controller {
function __construct() {
parent::__construct();
}
function index(){
echo "bla bla";
}
}