Google analytics in the head.php

Rate this topic: Evaluations: 0, 0.00 on the average.Evaluations: 0, 0.00 on the average.Evaluations: 0, 0.00 on the average.Evaluations: 0, 0.00 on the average.Evaluations: 0, 0.00 on the average.Evaluations: 0, 0.00 on the average.
GK User
Thu Apr 13, 2017 7:22 pm
Reply with quote
Report this post
Hello

I have the same problem like others with the google analytics.
I know I have to put the code in templates/gk_XXXXXXXXXX/layouts/blocks/head.php.
But can you show us a complete code of that file.
I have put the GA code in, but my sites get an error on the frontside. Jus a massage that there is a error in the head.php....
Ans I have deleted the code in the template settings.
Thank you
Lode
User avatar
Fresh Boarder

teitbite
Wed Apr 19, 2017 9:30 am
Reply with quote
Report this post
Hi

What is the error message exactly ? The most common problem users has is that head.php is in PHP mostly so to add a javascript code a PHP tags has to be separated. In short: add Your GA code at very bottom of the file and make sure there is ?> (PHP closing tag) before Your code.
User avatar
Moderator

GK User
Wed Apr 19, 2017 10:52 am
Reply with quote
Report this post
Hi Teitbite

The errror was a blanc page with a error message that stated that there was an error in de head.php on the line where te GA code started.
In het original templates "Steakhouse and Creativity" (in "Hotel" there was a closing tag, in "University" de GA code still works when inserted in the settings of the template) the last php-codes were not closed by a
Code: Select all
?>


So for others with the problem. I put the closing-tag like this:

Code: Select all
...................................
<?php
if(
  JRequest::getCmd('option') == 'com_config' ||
  (
    JRequest::getCmd('option') == 'com_content' &&
    JRequest::getCmd('layout') == 'edit'
  )
) {
  $doc = JFactory::getDocument();
  $doc->addStyleSheet($this->API->URLbase() . '/media/jui/css/bootstrap.min.css');
  $doc->addStyleSheet($this->API->URLbase() . '/media/jui/css/bootstrap-responsive.min.css');
  $doc->addStyleSheet($this->API->URLbase() . '/media/jui/css/bootstrap-extended.css');
  $doc->addStyleSheet($this->API->URLbase() . '/media/jui/css/icomoon.css');
  $doc->addStyleSheet($this->API->URLbase() . '/media/jui/css/chosen.css');
  $doc->addStyleSheet($this->API->URLbase() . '/media/media/css/mediamanager.css');
}

// EOF
?>(was missing)
(and then I put het GA code)
<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-xxxxxxx-x', 'auto');
  ga('send', 'pageview');

</script>


Succes!
User avatar
Fresh Boarder

teitbite
Fri Apr 21, 2017 9:35 am
Reply with quote
Report this post
Hi

It doesn't have to be closed if a following file is a php as well, but for this task was needed to be able to use a different type of scripting. Glad it's solved. Closing this thread now.
User avatar
Moderator


cron
Remember me
Register New Account
If you are old Gavick user, click HERE for steps to retrieve your account.