Adding Google Analytics Code Problem

Permalink 3 users found helpful
Hi,

I added the tracking code under "Sitewide Settings > Tracking Code", but in Google Analytics it's showing offline/not installed status for my tracking code. What am I doing wrong?

Here is my tacking code:

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("***********");
pageTracker._trackPageview();
} catch(err) {}</script>

View Replies:
frz replied on at Permalink Reply
frz
what theme are you using, and have you changed it much? There's a call to include it in that which needs to stay.
Hulkd replied on at Permalink Reply
I had a programmer develop my site, so its a custom theme. I just add and maintaine content through dashboard tools. I guess I will have to ask him to do the google analytics integration. Thank you.
frz replied on at Permalink Reply
frz
i think in footer.php there is a call to grab whatever is set in dashboard for the google code.. if they look at the example Plain Yogurt theme they should be able to put that back and you can edit your code through the dashboard again.
0pius replied on at Permalink Reply
0pius
the google analytics needs to be in the <head></head> area

You can manually insert it if you are using a header/footer.php type setup as frz mentioned.
frz replied on at Permalink Reply
frz
I dont think thats correct. I think its actually just fine, if not better, right before the </body> tag
0pius replied on at Permalink Reply
0pius
Just checked now Frz and it appears you are right, odd it said in the <head> area when I installed it.

my bad
0pius replied on at Permalink Reply
0pius
although the text states before </body>, strange
frz replied on at Permalink Reply
frz
i know they recently changed out the old urchin code with a new approach - maybe thats part of the forkin of documentation.. its an issue here. ;)
nolmscheid replied on at Permalink Reply
nolmscheid
This same thing happened to me. There is a line of code that calls 'footer_required.php' which is stored in the core files "concrete/elements/" and contains the code to pull in what ever you put in your dashboard in the site wide "Tracking Code" area.

<?php  require(DIR_FILES_ELEMENTS_CORE . '/footer_required.php'); ?>
arimaka replied on at Permalink Reply
The tracking code field should work for google analytics but it doesn't ... This should be fixes guys, to make it easier for non-developers.
frz replied on at Permalink Reply
frz
more information please. Probably depends on your theme's honoring the best practices.
baltho replied on at Permalink Reply
Hi folks: got it working (I think!) ... Sorry, no joy, it wasn't working after all - will update this when I fix it!
baltho replied on at Permalink Reply
In Sitewide Settings, I put this (grabbed from the GA website)
------------------
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-XXXXXXXX-X");
pageTracker._trackPageview();
} catch(err) {}</script>
-----------
!!right at the end !! - I think that makes a difference. And of course replace the XXX-X's with your GA ID.
Up it came, no problem, when I checked my status, although I think I forgot to hit that Save button the first time I tried it!

Hope this helps: it worked for me, concrete v5.3.2, ubuntu 9.04, latest GA.
everydaycoder replied on at Permalink Reply
everydaycoder
I hate bumping old threads, but since I ended up at this thread trying to find a solution, I thought I'd post my results.

Just before the theme outputs the </body> tag, the following line needs to appear:
<?php  Loader::element('footer_required'); ?>

Some themes have a footer.php, but others do not, so you should really look at every .php file in your theme directory for the </body> tag and put it just above. This is the same fix that nolmscheid suggested, but this is the recommended call according to the default concrete5 theme. I think the main underlying issue is that the tutorials/best practices for theme writing are incomplete, old, or just too dumbed down. I suggest every developer starting a theme to carefully review the default theme to be sure you get the required calls put in place.
Shotster replied on at Permalink Reply
Shotster
Hi everydaycoder,

Google recently changed things a bit with regard to where the code should go. It should now appear inside the document head - i.e. just before the closing </head> tag.

You can therefore either move the code you posted to that spot (which would appear a bit odd - outputting footer stuff in the head), or you can take a more semantically correct approach and put the following code in the head instead...

echo Config::get('SITE_TRACKING_CODE');

-Steve
primewaydesign replied on at Permalink Reply
primewaydesign
Hi Shotster,

now something confusing here,
Iam not getting it in my head:

In which head should I put this
echo config::get('SITE_TRACKING_CODE');
?

I have already placed my GA Code in the
default/elements/footer
directory and in Tracking Code field in Dashboard >> Sidewide Settings. Is that wrong?

Regards
OAFreelancer
pixel8 replied on at Permalink Reply
pixel8
you should only add your tracking code to the dashboard like you did, and then move the footer_required.php in your theme up in the header.php just before the </head> tag...

hope this helps you!
Shotster replied on at Permalink Reply
Shotster
> I have already placed my GA Code in the
> default/elements/footer directory and in
> Tracking Code field in Dashboard >> Sidewide Settings.
> Is that wrong?

You should enter the GA code ONLY into the dashboard. The following line...

echo Config::get('SITE_TRACKING_CODE');

...simply pulls your GA code from the C5 database and inserts it at that point.

To comply with Google's recommendation and have the code appear in the document head, you can either:

* Reference the footer_required.php file from your header.php file (which doesn't make intuitive sense to me - i.e. it's not semantically correct)

OR

* Simply output the GA code directly in your header.php just before the closing </head> tag as I have suggested.


If you take my suggestion, you must take further action to ensure that it isn't also output in your footer - i.e. you don't want it output twice. You should either:

* Remove the line that reads <? Loader::element('footer_required'); ?> from your footer.php file.

OR

* Override the footer_required.php file by copying it from /concrete/elements directory to the /elements directory and then commenting out the line that outputs the tracking code.

Hope that makes sense,

-Steve
primewaydesign replied on at Permalink Reply
primewaydesign
to make it easy for, because I am a newbie to C5:

Can I put my GA Code only in the Dashboard without further coding actions?

by the way:
should i put this code between <head>GA Code</head> of my default/elements/header.php?

echo Config::get('SITE_TRACKING_CODE');
ideasponge replied on at Permalink Reply
ideasponge
Either
1. add the GA code directly in your <head>...</head>

or

2. add the line of code suggested by Shotster AND ad your GA code to the dashboard.

Don't do both.
tatulici replied on at Permalink Reply
You have to "Update Cache" or "Clear Cache" after you make changes to work, I had the same problem. I've put the:
<?php  Loader::element('footer_required'); ?>
in the header.php just before just before </head> (in the teheme you use if is other then default) and it works. Or you can use the:
<?php echo Config::get('SITE_TRACKING_CODE'); ?>
it works the same.
Hope it help for others too, but don't forget to "Update Cache" or "Clear Cache" to work.
Good luck and let us know if is working for you to.
zoinks replied on at Permalink Reply
This doesn't seem to work very great.

I put <?php echo Config::get('SITE_TRACKING_CODE'); ?> before the closing </head> tag and it just spits the code out at the footer.

Am I supposed to delete the footer::loader code or something? Jeez,what a mess!
Adreco replied on at Permalink Reply
Adreco
wow... makes my head spin.
GA will work without being called up in the header (but maybe it won't catch the bounce / non page views that occur before your page is loaded?... that count I've normally attributed to accidental clicks from people with fat thumbs and touch screen phones)
Have you just tried using the "add to header" custom attribute from the front end Properties tab? I've had no trouble with Google pulling from there without having to touch site code at all.
zoinks replied on at Permalink Reply
Thanks, no I haven't tried that because I didn't know it was an option. Is this something I have to do for every page? If so, I won't be using this method.
Adreco replied on at Permalink Reply
Adreco
I'm 99% sure just adding on the home page will do it (haven't double checked lately though)(most recently have been using it to connect to G webmaster tools)
zoinks replied on at Permalink Reply
Thanks, I'll try. You mean just in the meta area if you click "properties" on the home page?
Adreco replied on at Permalink Reply
Adreco
Yep. See if you have it listed in the drop-down of custom attributes
zoinks replied on at Permalink Reply
Yep, it only did the homepage, though. I can't do that on every single page of the site.
Scafidi454 replied on at Permalink Reply
Scafidi454
Here's the easiest thing I've found, in the site header, in the CMS (not the backend PHP code), place your unique script tracking code somewhere in an HTML block:

<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', 'YOUR ANALYTICS TRACKING CODE', 'auto');
ga('send', 'pageview');

</script>



And it will report for each page accessed within the site automatically.
zoinks replied on at Permalink Reply
makes sense, just doesn't work. I put your config::get() code in and deleted the footer code. Nothing. I put the footer code in front of the closing </head> and we're back to square one: footer code spits out GA code at the bottom. Apparently, it doesn't matter where you place the footer code because the footer code is designed to spit out GA before the </body>... but your echo config::get('SITE_TRACKING_CODE'); does absolutely nothing whatsoever. I have cleared and updated cache. It simply doesn't do anything. Probably obsolete now in 5.4.2.1, I suppose. Gotta love that bs.