Where to put Google Analytics Code in OHs?

hello Sir,
To track my ohs activity , I have added Google Analytics code in /ohs/templates/common/footer.tpl , just above the closing tag as follows:

// GA Code added on July,9 2015
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

ga(‘create’, ‘UA-57745281-14’, ‘auto’);
ga(‘send’, ‘pageview’);

{/if}{* systemNotifications *}

Earlier. i used {ldelim} and {rdelim} for Smarty to understand { and } correctly.
However, it didn’t work.

Now , I have used {literal} {/literal}
Still i don’t get results.

Please sugeest me , how to use google analytics in ohs ?



Note that your code is immediate followed by an end-if {/if}. The start to this conditional is at:

This means your Google Analytics code will only display when there is a System Notification. To work all of the time, your addition would need to be outside of this smarty {if} ... {/if}.

thanks for the reply,
I put the Google Analytics GA code in the common/footer.tpl ,
but the statistitics are not coming in google analytics.
The code for my footer.tpl is as follows:


  • templates/common/footer.tpl
  • Copyright (c) 2005-2012 Alec Smecher and John Willinsky
  • Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
  • Common site footer.
  • $Id$
    {if $pageFooter}

    {call_hook name=“Templates::Common::Footer::PageFooter”}

{if $enableDebugStats}{include file=$pqpTemplate}{/if}

{if !empty($systemNotifications)} {translate|assign:"defaultTitleText" key="notification.notification"}

{/if}{* systemNotifications *}


Should I put this GA code in the common/header.tpl ?

Inserting it in the header vs. the footer should not make a difference technically. You will need the Google Analytics code within <script> tags. I can’t see if you have those in your example. The may be missing, or they may be stripped out by the forum.

If you post your footer.tpl as “pre” or “code” text (use the </> button in the editor, or surrounded the code by triple-backticks), it will preserve the full content and we can get a better look at it.