Google Analytics Javascript error with smarty

While working on a website running a smarty based script I encountered an error.

The error was received when i tried entering Google Analytics code to the footer.tpl file of the template for the script I was working on.

I received an error saying something like:

Fatal error: Smarty: [in footer.tpl line **]: syntax error: invalid attribute name: ‘pageTracker._trackPageview();’ (Smarty_Compiler.class.php, line 1433) in /************/libs/Smarty_Compiler.class.php on line 2062

If you have received the similar fatal error while trying to add Google Analytics code to smarty based template.

What’s the reason for this error? well smarty system takes everything inside the curly bracket { } as variable. So when it comes across them in the analytics code that we added in footer, it gives error due to obvious reasons.

How to fix it? Simple enough, Just add {literal} and {/literal} around the code. By wrapping the analytics code by the literal variable tag, it will let all the content inside the tags without processing them or looking for variables in it.

Leave a Reply

Your email address will not be published.