Piwigo.org

You are not logged in. (Register / Login)

Announcement

#1 2009-05-19 12:28:39

Joe
Guest

HowTo insert Google Analytics code in footer/header?

Hello,
i´m still exploring piwigo and its working fine for me, except the following damn issue i cant solve on my own since 2h. I want to use Google Analytics to track my visitors and therefor i need to paste a javascript code into every page of my Piwigo Gallery. I thought of pasting it into the footer or header so it should work fine also?

I also tried out the extension for google analytics code, but its not working! After activating it in admin plugin menu, i get this error message: "Parse error: syntax error, unexpected T_EXIT in /users/my_username_of_webspace/www/plugins/Statistics/admin/stat_admin.php on line 1". So i want to get this solved manually to just get it working!

Does anyknow know: How and Where I have to insert my code to get this thing working? :-/

Google Analytics 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-XXXXXXX-X");
pageTracker._trackPageview();
} catch(err) {}</script>


Best Regards,
Joe

#2 2009-05-19 12:39:15

Joe
Guest

Re: HowTo insert Google Analytics code in footer/header?

Hello,
i just modifidied the old stat_admin.php uploaded than got a screen "Hacking attemt!" then i modified it back to original, uploaded it and voila its working! *,* I got no idea what or where there was the issue, but anyways its working now.

Sorry for this topic and double post, but i was unable to delete it. :S

- Joe

#3 2009-05-19 16:22:09

VDigital
Former Piwigo Team
Location: Paris (FR)
Registered: 2005-05-04
Posts: 17680
Website

Re: HowTo insert Google Analytics code in footer/header?


Piwigo.com: Start and run your own photo gallery. Signup and get 30 days to try for free, no commitment.
8-)

Offline

#4 2009-07-09 09:53:12

saqwild
Member
Registered: 2009-06-13
Posts: 64

Re: HowTo insert Google Analytics code in footer/header?

i am also having some kind of similar problem,
i am using plugin Statistic. when i insert the code into the header, my page really gets messed up,
when i try putting in footer , it doesnt work. i cant see the code from view source

any clue

Offline

#5 2009-07-09 10:38:34

VDigital
Former Piwigo Team
Location: Paris (FR)
Registered: 2005-05-04
Posts: 17680
Website

Re: HowTo insert Google Analytics code in footer/header?

If you already understood the template extensions logic, make a in a new copy of footer.tpl
add:

<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-2xxxxxxx-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>

Associate the new template to the default footer.tpl
And that's it!

Enjoy!

See Smarty documentaion, for more.

And some additional function are avaliable like
{known_script id="jquery.ui.sortable" src=$ROOT_URL|@cat:"template-common/lib/ui/ui.sortable.packed.js" } if you yan the library being described once.


Piwigo.com: Start and run your own photo gallery. Signup and get 30 days to try for free, no commitment.
8-)

Offline

#6 2010-06-18 00:12:24

Ericnet
Translation Team
Location: Italy
Registered: 2010-04-02
Posts: 18
Website

Re: HowTo insert Google Analytics code in footer/header?

Sorry if I insert google code in footer.tpl have:

Fatal error: Smarty error: [in footer.tpl line 37]: syntax error: unrecognized tag 'var' (Smarty_Compiler.class.php, line 590)


Fulvio
forum Piwigo italiano it.piwigo.org/forum

Offline

#7 2010-06-18 02:04:38

tosca
Former Piwigo Team
Location: Cévennes (France)
Registered: 2006-09-23
Posts: 567
Website

Re: HowTo insert Google Analytics code in footer/header?

Did you use [extension by sakkhho] Statistics?
Have you checked the code generated in the source of your page? I saw a couple of times a copy/paste that didn't work properly, and part of the code was lost.

If possible, give us a link (by MP if you prefer).


My galleries : Photos, Watercolours, Recipes

Offline

#8 2010-06-18 22:51:50

tosca
Former Piwigo Team
Location: Cévennes (France)
Registered: 2006-09-23
Posts: 567
Website

Re: HowTo insert Google Analytics code in footer/header?

MP received.

[extension by sakkhho] Statistics was installed manually (the provider doesn't allow the automatic installation) and didn't work; Piwigo crashes when clicking on the Statistics plugin link.


My galleries : Photos, Watercolours, Recipes

Offline

#9 2010-06-19 18:33:23

Ericnet
Translation Team
Location: Italy
Registered: 2010-04-02
Posts: 18
Website

Re: HowTo insert Google Analytics code in footer/header?

Hi,

my provider fixed error and I installed this plugins with admin panel, then I copy and paste Analytics code. But if I view html code in piwigo home page not view Analytics code.
In admin panel if I manage statistic plugin, I view incomplete Analytics code.

Last edited by Ericnet (2010-06-19 21:54:05)


Fulvio
forum Piwigo italiano it.piwigo.org/forum

Offline

#10 2010-06-20 12:44:56

saimon
Member
Registered: 2006-12-04
Posts: 181
Website

Re: HowTo insert Google Analytics code in footer/header?

Hi,

Statistics plugin doesn't work for me, it "eats" the bottom part of my stats code (piwik) : I put the code and check the footer / header case, the code doesn't appear in the page after reload, and if I go to another admin page and come back to Statistics admin page, the last part of the code is then missing ...

→ I now use a footer.tpl extension, but to avoid smarty error the stats code must be put inside {literal} ... {/literal}

Offline

#11 2010-06-26 21:50:29

tosca
Former Piwigo Team
Location: Cévennes (France)
Registered: 2006-09-23
Posts: 567
Website

Re: HowTo insert Google Analytics code in footer/header?

saimon wrote:

but to avoid smarty error the stats code must be put inside {literal} ... {/literal}

Shouldn't the plugin be fixed so the webmaster don't have to add {literal} ... {/literal} ?


My galleries : Photos, Watercolours, Recipes

Offline

#12 2010-06-28 19:58:41

rarebit_
Member
Registered: 2010-06-08
Posts: 2

Re: HowTo insert Google Analytics code in footer/header?

the issue here is that Google has two types of code - html and php.  the html version gives the errors described above.  I inserted the php variant of the google analytics code, and all runs perfectly (statistics plug in and all).

Helpful - here is the dynamic (good for php and Piwigo) google analytics code to insert into the footer before the </body> tag:


<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-xxxxxx-x");
pageTracker._trackPageview();
</script> <?php
// End Analytics tracking code
?>


(the standard (i.e. html) google analytics code gave me a php error, but the (php) code above works perfectly)

To insert the code into the footer, follow tehse instructions (given in another thread by LucMorizur):

"
However to change the footer, use LocalFiles Editor (Admin > Specials > Plugins), to create a my_footer.tpl template file based on footer.tpl for the template you use. To apply the file you created, you go to Admin > Configuration >  Templates, and there you activate the file you created (which is listed here once you saved it) to replace footer.tpl.
"

Offline

#13 2010-06-28 20:12:21

VDigital
Former Piwigo Team
Location: Paris (FR)
Registered: 2005-05-04
Posts: 17680
Website

Re: HowTo insert Google Analytics code in footer/header?

tosca wrote:

saimon wrote:

but to avoid smarty error the stats code must be put inside {literal} ... {/literal}

Shouldn't the plugin be fixed so the webmaster don't have to add {literal} ... {/literal} ?

Smarty 3 (still in Release Candidate) will offer a new property 'auto_literal'.
By default  '{ ' and ' }' with spaces will be interpreted as literal, and no longer as Smarty delimiter.
;-)


Piwigo.com: Start and run your own photo gallery. Signup and get 30 days to try for free, no commitment.
8-)

Offline

#14 2010-06-28 20:20:39

VDigital
Former Piwigo Team
Location: Paris (FR)
Registered: 2005-05-04
Posts: 17680
Website

Re: HowTo insert Google Analytics code in footer/header?

rarebit_, please try:

<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-xxxxxx-x");
pageTracker._trackPageview();
</script>


Piwigo.com: Start and run your own photo gallery. Signup and get 30 days to try for free, no commitment.
8-)

Offline

#15 2010-06-28 20:22:36

tosca
Former Piwigo Team
Location: Cévennes (France)
Registered: 2006-09-23
Posts: 567
Website

Re: HowTo insert Google Analytics code in footer/header?

VDigital wrote:

tosca wrote:

saimon wrote:

but to avoid smarty error the stats code must be put inside {literal} ... {/literal}

Shouldn't the plugin be fixed so the webmaster don't have to add {literal} ... {/literal} ?

Smarty 3 (still in Release Candidate) will offer ...

The purpose of my remark was to say that the webmaster should not have to be bothered with 'something' to add/modify/suppress in order to comply with Smarty requirements.
He/she should have only to copy/paste the code provided by Google or any other statistics script provider, the plugin itself taking care of whatever Smarty will need in order to 'swallow the foreign code'.

My own 0.02 ;-)


My galleries : Photos, Watercolours, Recipes

Offline

Board footer

Powered by FluxBB

twitter facebook google+ newsletter Donate Piwigo.org © 2002-2014 · Contact