Pages

Wednesday, August 12, 2009

How to put google analytics code in SMF

Hi,

If you wanna track your website stats with google analytics you have put the code before , which is a piece of cake usually in any html website. But in SMF you have to put it inside the echo '' of php. I have done the tough part, just follow these steps:

Find:

     echo '  
  
  
</body></html>';

Replace it with:

echo '
    <div id="ajax_in_progress" style="display: none;', $context['browser']['is_ie'] && !$context['browser']['is_ie7'] ? 'position: absolute;' : '', '">', $txt['ajax_in_progress'], '</div>'
    //Begin Google Analytics
        ?><script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-#######-#");
pageTracker._trackPageview();
} catch(err) {}</script><?php echo '
</body></html>';

Put your code here in place of UA-#######-#.

Let me know if you have issues.

No comments:

Post a Comment