Problem rendering Google Analytics code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • knkk
    New Member
    • Jun 2007
    • 49

    Problem rendering Google Analytics code

    I am trying to include this code in the footer.template files of all blog templates:

    Code:
    <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-xxxxxx-x");
    pageTracker._trackPageview();
    } catch(err) {}</script>
    However, the actual blogs are rendering it like this:

    Code:
    <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 catch(err) </script>
    with this error also displayed:

    Code:
    Exception message: Smarty error: [in ./templates//FallingLeaves/footer.template line 16]: syntax error: unrecognized tag 'var' (Smarty_Compiler.class.php, line 590)
    Error code: 256
    -- Backtrace --
    /home/blogs/class/template/smarty/Smarty.class.php(1095): trigger_error
    /home/blogs/class/template/smarty/Smarty.class.php(1817): smarty_compiler.trigger_error
    /home/blogs/class/template/smarty/Smarty_Compiler.class.php(2218): smarty_compiler._trigger_fatal_error
    /home/blogs/class/template/smarty/Smarty_Compiler.class.php(590): smarty_compiler._syntax_error
    /home/blogs/class/template/smarty/Smarty_Compiler.class.php(312): smarty_compiler._compile_tag
    /home/blogs/class/template/smarty/Smarty.class.php(1491): smarty_compiler._compile_file
    /home/blogs/class/template/smarty/Smarty.class.php(1424): cachedtemplate._compile_source
    /home/blogs/class/template/smarty/Smarty.class.php(1869): cachedtemplate._compile_resource
    /home/blogs/class/template/template.class.php(145): smarty._smarty_include
    /home/blogs/tmp/583/%%8B^8B4^8B48D04F%%postandcomments.template.php(192): cachedtemplate._smarty_include
    /home/blogs/class/template/smarty/Smarty.class.php(1265): include
    /home/blogs/class/template/cachedtemplate.class.php(43): smarty.fetch
    /home/blogs/class/view/smartyview.class.php(257): cachedtemplate.fetch
    /home/blogs/class/view/blogview.class.php(286): smartyview.render
    /home/blogs/class/view/viewarticleview.class.php(88): blogview.render
    /home/blogs/class/controller/controller.class.php(399): viewarticleview.render
    /home/blogs/showblog.php(51): blogcontroller.process
    
    Exception message: Smarty error: [in ./templates//FallingLeaves/footer.template line 17]: syntax error: unrecognized tag: (Smarty_Compiler.class.php, line 446)
    Error code: 256
    -- Backtrace --
    /home/blogs/class/template/smarty/Smarty.class.php(1095): trigger_error
    /home/blogs/class/template/smarty/Smarty.class.php(1817): smarty_compiler.trigger_error
    /home/blogs/class/template/smarty/Smarty_Compiler.class.php(2218): smarty_compiler._trigger_fatal_error
    /home/blogs/class/template/smarty/Smarty_Compiler.class.php(446): smarty_compiler._syntax_error
    /home/blogs/class/template/smarty/Smarty_Compiler.class.php(312): smarty_compiler._compile_tag
    /home/blogs/class/template/smarty/Smarty.class.php(1491): smarty_compiler._compile_file
    /home/blogs/class/template/smarty/Smarty.class.php(1424): cachedtemplate._compile_source
    /home/blogs/class/template/smarty/Smarty.class.php(1869): cachedtemplate._compile_resource
    /home/blogs/class/template/template.class.php(145): smarty._smarty_include
    /home/blogs/tmp/583/%%8B^8B4^8B48D04F%%postandcomments.template.php(192): cachedtemplate._smarty_include
    /home/blogs/class/template/smarty/Smarty.class.php(1265): include
    /home/blogs/class/template/cachedtemplate.class.php(43): smarty.fetch
    /home/blogs/class/view/smartyview.class.php(257): cachedtemplate.fetch
    /home/blogs/class/view/blogview.class.php(286): smartyview.render
    /home/blogs/class/view/viewarticleview.class.php(88): blogview.render
    /home/blogs/class/controller/controller.class.php(399): viewarticleview.render
    /home/blogs/showblog.php(51): blogcontroller.process
    
    Exception message: Smarty error: [in ./templates//FallingLeaves/footer.template line 17]: syntax error: unrecognized tag '' (Smarty_Compiler.class.php, line 590)
    Error code: 256
    -- Backtrace --
    /home/blogs/class/template/smarty/Smarty.class.php(1095): trigger_error
    /home/blogs/class/template/smarty/Smarty.class.php(1817): smarty_compiler.trigger_error
    /home/blogs/class/template/smarty/Smarty_Compiler.class.php(2218): smarty_compiler._trigger_fatal_error
    /home/blogs/class/template/smarty/Smarty_Compiler.class.php(590): smarty_compiler._syntax_error
    /home/blogs/class/template/smarty/Smarty_Compiler.class.php(312): smarty_compiler._compile_tag
    /home/blogs/class/template/smarty/Smarty.class.php(1491): smarty_compiler._compile_file
    /home/blogs/class/template/smarty/Smarty.class.php(1424): cachedtemplate._compile_source
    /home/blogs/class/template/smarty/Smarty.class.php(1869): cachedtemplate._compile_resource
    /home/blogs/class/template/template.class.php(145): smarty._smarty_include
    /home/blogs/tmp/583/%%8B^8B4^8B48D04F%%postandcomments.template.php(192): cachedtemplate._smarty_include
    /home/blogs/class/template/smarty/Smarty.class.php(1265): include
    /home/blogs/class/template/cachedtemplate.class.php(43): smarty.fetch
    /home/blogs/class/view/smartyview.class.php(257): cachedtemplate.fetch
    /home/blogs/class/view/blogview.class.php(286): smartyview.render
    /home/blogs/class/view/viewarticleview.class.php(88): blogview.render
    /home/blogs/class/controller/controller.class.php(399): viewarticleview.render
    /home/blogs/showblog.php(51): blogcontroller.process
    I'd be quite grateful for any help!
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    This looks like a PHP (Smarty template) error rather than a JavaScript error. Most likely it's caused by the { which may need to be escaped.

    Comment

    • knkk
      New Member
      • Jun 2007
      • 49

      #3
      Thanks, acoder, I got this. I had to put a {literal} tag before and after the javascript. Have a great day (and a Happy New Year!).

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        And you too! Glad you got it fixed.

        Comment

        Working...