How to add Google Analytics to Gallery 2

 

Adding Google Analytics is straight forward with a little HTML skill and can be done in a few easy steps.  Of course, if you website is hosted with Hosting Photography then we can do it for you free of charge.

Steps to add Google Analytics to Gallery 2

1. Create a Google Analytics Account

If you do not have a Google Analytics account sign up for free at http://www.google.com/analytics/

2. Obtain the tracking code for your website profile

Setup a site profile in Google Analytics and obtain the tracking code which will be added to Gallery 2 to track  visitors.  Check the online help to see how to do this at http://www.google.com/support/googleanalytics/bin/static.py?page=guide.cs&guide=19779&topic=19782

3. Create a local Gallery 2 theme.tpl file

In order to keep your changes to your Gallery during upgrades of themes, a local theme.tpl file needs creating.  To do this use cPanel file manager to navigate to the theme folder that your Gallery 2 website is using.  This example will assume we are using the ICE theme.

  1. Navigate to /public_html/themes/ice/templates/.
  2. Create a folder here named 'local' (without quotes).
  3. Copy the theme.tpl file from /public_html/themes/ice/templates/ to /public_html/themes/ice/templates/local/

Now we have a version of theme.tpl which can be modified and the changes will not be overwritten when the theme is upgraded.

4. Add tracking code to theme.tpl

Next the theme.tpl file created in local needs modifying to add the Google tracking code.

  1. Using cPanel File Manager select theme.tpl and click the 'Code Editor' button on the cPanel File Manager.  A new window will open with displaying the theme.tpl code.
  2. Scroll to the bottom of the file.  The Google tracking code will be put between the {g->debug} and tags.
  3. Add {literal} on a new line after {g-debug} then paste your tracking code in.  Close the literal tag with {/literal} immediately after the Google tracking code, this should be before but not necessarily immediately in front of the tag.
  4. Save and close the file.

5. Delete the Gallery 2 cache and check your change

If you are using the Gallery 2 cache, then you need to delete it and refresh your website.

  1. Within your Gallery 2 Site Admin click on 'Maintenance' and run 'Delete template cache'
  2. Visit your website and refresh the page
  3. View the page source using the option in the web browser.  Scroll to the bottom of the source and check you can see the tracking code you have just added.
  4. If you do not see it, deleting your web browsers temporary internet files may help.
  5. If you have made a mistake and your website does not load, just rename the copy of theme.tpl to theme.bak and your Gallery 2 website will revert to using the original untouched version of the file.  Contact support for assistance.

6. Validate tracking code at Google Analytics

Log back into Google Analytics and check the status of tracking.  It may take a few hours for this to update and confirm it is tracking visitors.

That's it.  If at any point you have any issues or are totally confused how to do this, existing customers can contact us and we will add the tracking code for you.

  • 0 Users Found This Useful
Was this answer helpful?