I'm a bit late to this thread, but found it really useful.

In case this is of any use to future explorers of the thread, I
thought I'd contribute what we ended up doing: we put
<lift:Analytics.google /> (snippet below) before </body> in our
template.  I guess this may have been all over-taken by the lift:tail
work.

--
import scala.xml.NodeSeq

import net.liftweb._
import http._
import S._
import util._
import Props.RunModes._

class Analytics {

  // To avoid non-XHTML compliant JavaScript we decide if we're https
or not here.
  // See e.g., 
http://happygiraffe.net/blog/2009/06/06/google-analytics-in-xhtml/
  def google_script_url = S.request match {
    case Full(req) if req.request.scheme == "https" =>
"https://ssl.google-analytics.com/ga.js";
    case _ => "http://www.google-analytics.com/ga.js";
  }

  // Output the Google Analytics JavaScript
  def google(xhtml: NodeSeq) = Props.mode match {
    case Production | Pilot | Staging =>
      <script type="text/javascript" src={google_script_url}></script> ++
      <script type="text/javascript">
      <![CDATA[try {
      var pageTracker = _gat._getTracker('UA-nnnnnnnn-1');
      pageTracker._trackPageview();
      } catch(err) {}
      ]]>
      </script>
    case _ => Nil
  }

}
---

...but replacing 'UA-nnnnnnnn-1' with your tracking code.

Warning: I've not tested with a https site yet.

Richard


On Wed, Jul 15, 2009 at 3:25 AM, Xavi Ramirez <xavi....@gmail.com> wrote:
>
> Sorry, I didn't replay earlier, but it turns out that the "operation
> is not supported code: 9" error is related to the fact that the
> default Google Analytics snippet uses document.write().  It turns out
> that XHTML does not support document.write(), which causes Firefox to
> chock.
>
> Ultimately, I replaced the default Google Analytics snippet with this one:
> <script src="http://www.google-analytics.com/ga.js"; type="text/javascript" />
> <script type="text/javascript">
> //<![CDATA[
>    try { var pageTracker = _gat._getTracker("UA-4384857-1");
> pageTracker._trackPageview(); } catch(err) {}
> //]]>
> </script>
>
> A full write up of my experiences with Google Analytics and Lift can
> be found here:
> http://www.the-xavi.com/articles/operation-is-not-supported-code-9
>
> ~Xavi
>
> On Tue, Jul 7, 2009 at 4:34 PM, Xavi Ramirez<xavi....@gmail.com> wrote:
>> Thanks!  I ran into this exact problem.  Is there any way to get rid
>> of it?  Is there a <lift:production> tag?
>>
>> Thanks,
>> Xavi
>>
>> On Tue, Mar 17, 2009 at 5:22 PM, Charles F. Munat<c...@munat.com> wrote:
>>>
>>> OK, I have to stop posting this crap when it's 5:30 AM, I've been
>>> working for 18 hours straight, and my brain is fried.
>>>
>>> The problem was that I was looking at it on my development machine, not
>>> the production server. The Google Analytics code is tied to the URL. If
>>> the URL is wrong, it doesn't serve the script, so Firebug reports the
>>> error. I are dumb.
>>>
>>> Hopefully, though, my posting this will save some other person a hassle
>>> and a little public embarrassment.
>>>
>>> Chas.
>>>
>>> Derek Chen-Becker wrote:
>>>> Can you send the beginning of the XHTML output, up to and including the
>>>> GA script?
>>>>
>>>> Derek
>>>>
>>>> On Tue, Mar 17, 2009 at 6:31 AM, Charles F. Munat <c...@munat.com
>>>> <mailto:c...@munat.com>> wrote:
>>>>
>>>>
>>>>     Is anyone else using Google Analytics? I am getting this strange
>>>>     JavaScript error:
>>>>
>>>>     operation is not supported" code: "9
>>>>      var pageTracker = _gat._getTracker("UA-5774043-2");
>>>>
>>>>     The Google scripts are supposed to be placed right before the closing
>>>>     body tag, but Lift inserts its own script in there. I can't imagine how
>>>>     that would make a difference, but it is the only thing different from
>>>>     what Google recommends.
>>>>
>>>>     Also, the analytics are not working.
>>>>
>>>>     Any ideas?
>>>>
>>>>     Chas.
>>>>
>>>>
>>>>
>>>>
>>>> >
>>>
>>> >>
>>>
>>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to