Gallery:如何向Gallery2添加Google Analytics

来自站长百科
跳转至: 导航、​ 搜索

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. See: Editing Templates

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.

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.

Add Google adsense

http://codex.gallery2.org/Gallery2:How_to_add_adsense