Gallery2:How To Add Google Analytics to my Gallery 2 - Gallery Codex
Personal tools

Gallery2:How To Add Google Analytics to my Gallery 2

From Gallery Codex

Revision as of 15:28, 12 September 2006 by H0bbel (Talk | contribs) (Oops, removed personal tracking code)

How to Enable Google Analytics in Gallery 2

These instructions assume that you are modifying the standard Matrix theme. If you are using a different theme, the code snippets outlined below may not match yours. The most important thing to remember, is to insert the Google Analytics tracker code near the end of the html output. This is also the recommended placement by Google Analytics.

1. Copy /gallery2/themes/matrix/templates/theme.tpl into a new directory under templates/ called local.

The new copy should now reside in /gallery2/themes/matrix/templates/local/theme.tpl
This makes Gallery 2 use the copy in templates/local/ instead of the default one in templates/ and doing this ensures that any changes you have made will survive an update (either via a new Gallery 2 release or a cvs update).

2. Open /gallery2/themes/matrix/templates/local/theme.tpl and find the following:

    {* Put any debugging output here, if debugging is enabled *}

3. Insert the Google Analytics javascript right above the </body> tag like this:

{* Put any debugging output here, if debugging is enabled *}
        {* Google Analytics Code *}
        <script src="" type="text/javascript">
        <script type="text/javascript">
        _uacct = "UA-xxxxx-x";

4. Remember to change the _uacct="UA-xxxx-x"; to your actual Analytics tracker ID.

5. Verify that the code is inserted at the right place, by browsing your Gallery 2 install and view the HTML source.

Google Analytics Help Center

6. Watch Google Analytics give you statistics nirvana

Multisite Gallery2

If you use have multiple Gallery sites using the same theme but only wish to use Analytics for some of them, try code like this in theme.tpl (the code placement in theme.tpl would be the same as the above example):

 {capture assign="site"}{php}print basename(GALLERY_CONFIG_DIR);{/php}{/capture}
 {if $site == "gallery2" or $site == "myphotos"}
   ..code shown above for google analytics..

This uses the directory name for each multisite to identify whether to use analytics.