Blog
Track your Gallery 2 visitors with Google Analytics

How to add Google Analytics to Gallery 2

Did you know you can add Google Analytics to Gallery 2 to track in detail what albums and photos your website visitors are viewing?

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

The tracking code will look like this:

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

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 </body> 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 </body> 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.

Hosting Photography provides photographer optimized web hosting.  Gallery 2 is fully supported on any web hosting plan.

Leave a Reply

Our Guarantee

Let us get you online knowing we offer a 30 day risk free refund, no hassles no delays!

Get started today!

Plans and Pricing

Consumer Hosting
from $8.95/month
10 GB Disk, 50 GB Bandwidth
Go
Prosumer Hosting
from $11.95/month
20 GB Disk, 100 GB Bandwidth
Go
Professional Hosting
from $14.95/month
40 GB Disk, 150 GB Bandwidth
Go

What our Customers Say

Hosting Photography is an great company which provides excellent connectivity, image compression, customer service, support and shareware! All very affordable!!
GEMSofSouthWest, SW USA

The service provided by Hosting Photography is nothing short of fantastic. Even with our large time difference, Ian and Andy are always very prompt and ready to help with any problem or updates we want to make. We are so thrilled with the quality of our website and all the extra features available to us. Our site is very custom, easy to manage, inexpensive and our customers love the look and feel. If you're considering hosts, don't hesitate to go with Hosting Photography. -Josh Haas www.glancesatnature.com
Josh & Dave Haas, Michigan, United States

Get a Domain Name

Follow Us

Follow Us on Twitter Our Blog