Problem rendering Google Analytics code

Discussion in 'JavaScript' started by knkk, Dec 29, 2008.

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

    <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>
    Code (markup):
    However, the actual blogs are rendering it like this:

    <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>
    Code (markup):
    with this error also displayed:

    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
    Code (markup):
    I'd be quite grateful for any help!
     
    knkk, Dec 29, 2008 IP
  2. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #2
    i think smarty does not like seeing braces { } as they indicate the start of control structure or a variables. to escape them, try:

    {ldelim} instead of { and {rdelim} instead of }.
     
    dimitar christoff, Jan 1, 2009 IP
  3. knkk

    knkk Peon

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks! I put {literal} and {/literal} instead, and they worked too.
     
    knkk, Jan 1, 2009 IP
  4. amasum

    amasum Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    finally found the solution I was looking for..thanks..
     
    amasum, Mar 10, 2009 IP