Problem with adding Google Analytics code

Author Message

Christer Jakobsen

Wednesday 29 April 2009 3:55:16 am

Hello!

I have added the java script code to pagelayout.tpl as suggested in a few posts here, but some of the code gets lost on the way.

I have addede the following code to this file
extension/sitename/design/our_name/templates/pagelayout.tpl

<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-xxxxxxx-x");
pageTracker._trackPageview();
} catch(err) {}</script>

But when I try to view the source code of the resulting web page this is what comes out:

<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

The rest of the script, and other closing tags are gone.

Could anybody tell me what I'm doing wrong?

Regards, Christer

André R.

Wednesday 29 April 2009 4:11:05 am

Tak a look at the documentation for {literal}, {rdelim} and {rdelim} to be able to use '{' and '}' in templates withouth getting parser error (since these are reserved to the template language).

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Marco Zinn

Wednesday 29 April 2009 11:38:33 am

Hi Christer,

if you want, you may want to try this:
Instead of modifying your pagelayout.tpl, you can just use yet-another-cool feature of ez:
Insert the JS block into the "Footer Javascript" field of your "Template Look".

For this, log in to your admin site, go to "Design" and there, click on "Look & Feel".
In that screen, scroll down a lot and just copy and paste the Google Analystics code into that text area.

This will put it at the bottom of your pages automatically..
For us, this worked very well.

Note: If your site is multilingual, you may need to put the code on all translations of this "Look&Feel"-Object.

Marco
http://www.hyperroad-design.com

Christer Jakobsen

Thursday 30 April 2009 4:55:21 am

Thanks to both of you!
If I had my head at the right place I probably should have known about having to use the {literal} tag. They did the trick fine it seems.
The other option might be good to know about in other situations.

Regards,
Christer

Mik Kali

Wednesday 23 September 2009 1:24:54 am

And how to insert statcounter code into footer js ?

It looks like this:

<!-- Start of StatCounter Code -->
<script type="text/javascript">
var sc_project=xxxxxx;
var sc_invisible=0;
var sc_partition=33;
var sc_security="yyyyyyy";
</script>

<script type="text/javascript" src="http://www.statcounter.com/counter/counter_xhtml.js"></script><noscript><div class="statcounter"><a class="statcounter" href="http://www.statcounter.com/"><img class="statcounter" src="http://c34.statcounter.com/xxxxxxx/0/yyyyyy/" alt="invisible hit counter" /></a></div></noscript>
<!-- End of StatCounter Code -->

Those x's and y's are actually numbers referencing to my account. All I get after publishing is the text on the bottom of window:

"Code corrupted. Insert fresh copy. --> "

Probably because to me it looks like a HTML wit javascript calls, not javascript. I'm not a programmer, instead of that I'm an user who wants to put mys site out and concentrate on WORKING,

So: Where to I need to put that code ? Does it have to be formatted ? How ?

Same goes with my Google Analytics code, I actually do not know whether it works, but i leaves a text "-->" on the bottom of the window when published:

<!-- Google 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">
var pageTracker = _gat._getTracker("UA-xxxxx-y");
pageTracker._initData();
pageTracker._trackPageview();
</script>
<!-- End Google code -->

In both cases, Google and Statcounter, I have removed those HTML comment lines (like <!--- xxxx --->" ).

In both cases, these pieces of code need to be in every page and in both cases the code is ment to be injected into HTML.

The question, again, is: How do I put these into my Ez Publish Site ?

Gaetano Giunta

Wednesday 23 September 2009 5:19:51 am

@Mik: those pieces of code are in fact html, not javascript.

That means that you need to add them not in one of the javascript files included in your page, but directly in your page's html code.

The standard way to do that is to find out which template files are used by eZPublish to render your pages into html and add your bits there - you should enable debug output and the list of used templates (you can do it using the checkboxes in the right hand column of the admin interface), navigate back to the website and look at the list of templates used, displayed at the bottom of the page. Look out for a line reading "pagelayout.tpl": it should report the exact name of the template you need to modify.

Principal Consultant International Business
Member of the Community Project Board

Mik Kali

Wednesday 23 September 2009 6:06:38 am

Thanks Gaetano,

I did like you told, but did not actually modify pagelayout.tpl. Instead of that I created an override as acopy of original and added my lines there.

To my great astonishment it seems to work :-)

To be honest, Ez Publish is not very user friendly system. In small companies I think it is not a good idea to even consider this, because if heavy customizing needed, there needs to be one pro resource allocated to this for the time needed and it will cost, whether the resource is from inside or outside of the company.

In case of individuals and big companies it maybe is not a problem, because individuals have the time to learn it and big companies have the resources /money. But if you are in between.... :-)

Thanks !

Johnny Clingham

Sunday 27 February 2011 12:45:21 pm

Hi all i am having issue with my google Analytics code below

I have tried putting this code in the bottom of my pagelayout.tpl

I have also tried adding it in the footer javascript

google analytics shows it has been successfully installed and data is being gathered now

but nothing appears can any one assist thank you i am not a developer but have a but of knowlodge on the file layout

here is my 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("UA-*******-2 ");
pageTracker._trackPageview();
} catch(err) {}</script>

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.