Difference between revisions of "Gallery2:How To Add Google Analytics to my Gallery 2" - Gallery Codex
Personal tools

Difference between revisions of "Gallery2:How To Add Google Analytics to my Gallery 2"

From Gallery Codex

(Removed redundant text)
(Oops, removed personal tracking code)
Line 25: Line 25:
 
         </script>
 
         </script>
 
         <script type="text/javascript">
 
         <script type="text/javascript">
         _uacct = "UA-52843-1";
+
         _uacct = "UA-xxxxx-x";
 
         urchinTracker();
 
         urchinTracker();
 
         </script>
 
         </script>

Revision as of 15:28, 12 September 2006

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 *}
    {g->debug}
  </body>
</html>

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

{* Put any debugging output here, if debugging is enabled *}
    {g->debug}
        {* Google Analytics Code *}
        <script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
        </script>
        <script type="text/javascript">
        _uacct = "UA-xxxxx-x";
        urchinTracker();
        </script>
  </body>
</html>

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..
 {/if}

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

advertisements