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.

eZ debug

Timing: Jan 18 2025 02:46:17
Script start
Timing: Jan 18 2025 02:46:17
Module start 'layout'
Timing: Jan 18 2025 02:46:17
Module start 'content'
Timing: Jan 18 2025 02:46:19
Module end 'content'
Timing: Jan 18 2025 02:46:19
Script end

Main resources:

Total runtime1.1078 sec
Peak memory usage4,096.0000 KB
Database Queries81

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0077 588.1484152.6406
Module start 'layout' 0.00770.0030 740.789139.4766
Module start 'content' 0.01071.0954 780.2656780.5469
Module end 'content' 1.10620.0016 1,560.812524.1250
Script end 1.1077  1,584.9375 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00420.3783160.0003
Check MTime0.00170.1557160.0001
Mysql Total
Database connection0.00090.079510.0009
Mysqli_queries1.010591.2165810.0125
Looping result0.00130.1208790.0000
Template Total1.055995.320.5280
Template load0.00230.210620.0012
Template processing1.053695.105720.5268
Template load and register function0.00020.018410.0002
states
state_id_array0.00580.526410.0058
state_identifier_array0.00370.334820.0019
Override
Cache load0.00220.20081090.0000
Sytem overhead
Fetch class attribute can translate value0.00090.080760.0001
Fetch class attribute name0.00130.1177110.0001
XML
Image XML parsing0.00190.172460.0003
class_abstraction
Instantiating content class attribute0.00000.0014110.0000
General
dbfile0.00120.1090290.0000
String conversion0.00000.000940.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
8content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
20content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
12content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1content/datatype/view/ezxmltags/emphasize.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/emphasize.tplEdit templateOverride template
1content/datatype/view/ezxmltags/strong.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/strong.tplEdit templateOverride template
1content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 48
 Number of unique templates used: 9

Time used to render debug report: 0.0003 secs