Announcement

Collapse
No announcement yet.

Message: Unterminated string constant with Google Analytics

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Message: Unterminated string constant with Google Analytics

    Hi Everyone

    I am getting Javascript errors in v9 and v10 arising from the Google tracking code.

    The original code from Google is>>
    <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-xxxxxxxx-1");
    pageTracker._trackPageview();
    } catch(err) {}
    </script>
    If I replace the Google analytis code code in the Library with this code with the analytics number in place the error goes.
    If I use this code but use 'GoogleAnalyticsNumber' the error comes back.

    If I use the Actinic version of the code >>
    <actinic:block if="%3cactinic%3avariable%20name%3d%22IsGoogleAnalyticsEnabled%22%20%2f%3e%20%3d%3d%20true" >
    <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">
    var pageTracker = _gat._getTracker("<actinic:variable name="GoogleAnalyticsNumber" />");
    pageTracker._initData();
    pageTracker._trackPageview(<actinic:block if="%3cactinic%3avariable%20name%3d%22PageType%22%20%2f%3e%20%3d%3d%20%22Receipt%22">"/receipt.html"</actinic:block>);
    </script>
    </actinic:block>

    I get the error. If I hard code the number instead of the variable as before, I still get the error. If I hard code the number and replace the two lines>
    pageTracker._initData();
    pageTracker._trackPageview(<actinic:block if="%3cactinic%3avariable%20name%3d%22PageType%22%20%2f%3e%20%3d%3d%20%22Receipt%22">"/receipt.html"</actinic:block>);
    with>
    pageTracker._trackPageview();
    } catch(err) {}
    The error goes.

    Anyone still with me? Any ideas?

    The solution in http://community.actinic.com/showthread.php?t=40048 does not solve the problem.

    Thanks

    Jonathan
    Jonathan Chappell
    Website Designer
    SellerDeck Website Designer
    Actinic to SellerDeck upgrades
    Graphicz Limited - www.graphicz.co.uk

    #2
    Have you tried http://community.actinic.com/showthread.php?t=40396 with Normans solution


    Bikster
    SellerDeck Designs and Responsive Themes

    Comment


      #3
      None of these work.

      The only thing that removes the errors is to use Google's original code with the Analytics Number hard coded. This of course leaves out the reference to the receipt page. Even putting the Variable Analytics Number instead of the hard coded number cause the error.
      Is it asking too much for Actinic to provide an Analytics code that works?????
      Jonathan Chappell
      Website Designer
      SellerDeck Website Designer
      Actinic to SellerDeck upgrades
      Graphicz Limited - www.graphicz.co.uk

      Comment


        #4
        None of these work
        Are you sure.

        I'm pretty sure that editing layout "Google Analytics Tracking Code" and
        changing ga.js to ga%2Ejs does the trick.

        However that is more related to the "_gat is not defined error". Without a link to a problem page on your site it will be hard to comment further.
        Norman - www.drillpine.biz
        Edinburgh, U K / Bitez, Turkey

        Comment


          #5
          Originally posted by graphicz View Post
          Hi Everyone
          If I hard code the number instead of the variable as before, I still get the error. If I hard code the number and replace the two lines>
          pageTracker._initData();
          pageTracker._trackPageview(<actinic:block if="%3cactinic%3avariable%20name%3d%22PageType%22%20%2f%3e%20%3d%3d%20%22Receipt%22">"/receipt.html"</actinic:block>);
          with>
          pageTracker._trackPageview();
          } catch(err) {}
          The error goes.

          Jonathan
          This doesn't actually make any sense as you do not appear to be putting the try{ in front of that part of the code to complete function. I tried just adding the } catch(err) {} into a working version of the analytics code and it threw an error which is what I expected.

          So it looks like you may have a problem earlier in the page layout with a { bracket that does not have a matching } bracket and this is what is causing the problem.

          The software will mismatch the various {} bracket pairs until it comes to the last part of the code (the google analytics) and will now run out of brackets to match.

          Malcolm

          SellerDeck Accredited Partner,
          SellerDeck 2016 Extensions, and
          Custom Packages

          Comment


            #6
            http://www.lindy-lou.co.uk/

            It is heavily customised to get it how the customer wanted it.

            Here is the screen shot of IE's debug:


            Shall I post the page html?
            Jonathan Chappell
            Website Designer
            SellerDeck Website Designer
            Actinic to SellerDeck upgrades
            Graphicz Limited - www.graphicz.co.uk

            Comment


              #7
              To Malbro

              I was just giving the relevant lines.

              This works OK:
              <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-109xxxx-1");
              pageTracker._trackPageview();
              } catch(err) {}
              </script>

              This does not:

              <actinic:block if="%3cactinic%3avariable%20name%3d%22IsGoogleAnalyticsEnabled%22%20%2f%3e%20%3d%3d%20true" >
              <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">
              var pageTracker = _gat._getTracker("<actinic:variable name="GoogleAnalyticsNumber" />");
              pageTracker._initData();
              pageTracker._trackPageview(<actinic:block if="%3cactinic%3avariable%20name%3d%22PageType%22%20%2f%3e%20%3d%3d%20%22Receipt%22">"/receipt.html"</actinic:block>);
              </script>
              </actinic:block>

              Is it the ga.js in google-analytics.com/ga.js that should be replaced with ga%2Ejs? If so I am afraid no go.

              Thanks
              Jonathan Chappell
              Website Designer
              SellerDeck Website Designer
              Actinic to SellerDeck upgrades
              Graphicz Limited - www.graphicz.co.uk

              Comment


                #8
                If I remove the Analytics tracking code altogether I get this:
                Jonathan Chappell
                Website Designer
                SellerDeck Website Designer
                Actinic to SellerDeck upgrades
                Graphicz Limited - www.graphicz.co.uk

                Comment


                  #9
                  An URL of a faulty page would be the most useful. Can't see it - can't fix it!
                  Norman - www.drillpine.biz
                  Edinburgh, U K / Bitez, Turkey

                  Comment


                    #10
                    Thanks Norman - I did give it above but it was probably lost in code, also the error just above is because of a duplicated reference to slimbox now resolved.

                    Analytics code = errors.
                    <!--Analytics code--> = No Errors
                    Jonathan Chappell
                    Website Designer
                    SellerDeck Website Designer
                    Actinic to SellerDeck upgrades
                    Graphicz Limited - www.graphicz.co.uk

                    Comment


                      #11
                      www.lindy-lou.co.uk
                      The live site still has some duplicate slimbox issues - please ignore
                      Jonathan Chappell
                      Website Designer
                      SellerDeck Website Designer
                      Actinic to SellerDeck upgrades
                      Graphicz Limited - www.graphicz.co.uk

                      Comment


                        #12
                        Looking on the source code of your home page I see:
                        Code:
                        var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
                        document.write(unescape("%3Cscript src='" + gaJsHost + "acatalog/google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
                        
                        </script><script type="text/javascript">
                        var pageTracker = _gat._getTracker(" UA-10953590-1
                        ");
                        pageTracker._initData();
                        The first and last lines are fine.

                        The line
                        Code:
                        document.write(unescape("%3Cscript src='" + gaJsHost + "acatalog/google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
                        is wrong. Actinic is inserting a spurious acatalog/ into that line. Fix this by doing as per my post #4 above.

                        Next there is an unterminated string literal error on the pair of lines:
                        Code:
                        var pageTracker = _gat._getTracker(" UA-10953590-1
                        ");
                        This should really be generated as:
                        Code:
                        var pageTracker = _gat._getTracker("UA-10953590-1");
                        You seem to have a spurious newline there that is forcing JavaScript to treat this as two lines of code when it's meant to be a single line. Also, the leading space is wrong. Strangely, I don't see a space or newline in the Actinic layout code you posted:
                        Code:
                        var pageTracker = _gat._getTracker("<actinic:variable name="GoogleAnalyticsNumber" />");
                        Could the space and newline somehow be in the value you've set for variable GoogleAnalyticsNumber?

                        Betcha you've copied / pasted that data from somewhere else and have inadvertently copied in some spurious whitespace characters.
                        Norman - www.drillpine.biz
                        Edinburgh, U K / Bitez, Turkey

                        Comment


                          #13
                          Thanks (as always) Norman. The analytics number in Actinic looked all right but I copied it into notepad and there was a carriage return! I have corrected this. Still got the error.
                          I can't upload the site at present as it is functioning, I will have to send a design snapshot when this is sorted. The code on page preview now looks 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%2Ejs' type='text/javascript'%3E%3C/script%3E"));
                          </script>
                          <script type="text/javascript">
                          	var pageTracker = _gat._getTracker("UA-109xxxxx-1");
                          	pageTracker._initData();
                          	pageTracker._trackPageview();
                          </script>
                          Jonathan Chappell
                          Website Designer
                          SellerDeck Website Designer
                          Actinic to SellerDeck upgrades
                          Graphicz Limited - www.graphicz.co.uk

                          Comment


                            #14
                            Jonatan,

                            The code in your post #13 looks perfect now. Should work fine on the live site.

                            I've posted that ga.js needing to be ga%2Ejs as a bug as I see this is still a problem in the 10.0.2 Beta 2.
                            Norman - www.drillpine.biz
                            Edinburgh, U K / Bitez, Turkey

                            Comment


                              #15
                              I'll let you know when I am able to get the client to install a snapshot. In the meantime, the red box in Actinic is still displaying.
                              Jonathan Chappell
                              Website Designer
                              SellerDeck Website Designer
                              Actinic to SellerDeck upgrades
                              Graphicz Limited - www.graphicz.co.uk

                              Comment

                              Working...
                              X