I don't have a complete answer for you, as I'm trying to work out some glitches myself. But maybe this will help suggest approaches.
I'm using version 6.8.0.G.30 of the search appliance.
I can insert my Google Analytics account number in the Analytics Account field under the "Global Attributes" section of the Page Layout Helper for the desired Appliance Front End.
That GUI approach has the effect of inserting the account number into the XSLT for that Front End:
<!-- *** analytics information *** -->
<xsl:variable name="analytics_account">UA-1234567-1</xsl:variable>
When the transformation is processed and the page is rendered, if a value is found for the account, then this JavaScript is generated in the search results page:
<script type="text/javascript" src="http://www.google-analytics.com/ga.js"></script><script type="text/javascript">
var pageTracker = _gat._getTracker("UA-1234567-1");
pageTracker._trackPageview();
</script>
As an alternative to using the Page Layout Helper, you can "Edit underlying XSLT code" to manually edit the stylesheet and insert the analytics account.
The Google Analytics code produced by the default XSLT may not be what you want (probably isn't based on your post). For example, the snippet above is the synchronous version.
So, you'll probably want to edit the XSLT anyway to modify the snippet. I wanted to use the asynchronous snippet, so I changed the template named "analytics" used in the XSLT (that specifies to not customize):
<!-- **********************************************************************
Analytics script (do not customize)
********************************************************************** -->
<xsl:template name="analytics">
<xsl:if test="string-length($analytics_account) != 0">
<script type="text/javascript" src="{$analytics_script_url}"></script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("<xsl:value-of select='$analytics_account'/>");
pageTracker._trackPageview();
</script>
</xsl:if>
</xsl:template>
That template is where the account information you've previously entered in the XSLT (via GUI or XSLT) gets substituted in. It's called at various locations in the Front End XSLT.
It's also possible to change the URL for the analytics script (you see that variable used in the "analytics" template).
What I did was to substitute the "analytics" template above with my own asynchronous version. So now when I look at the rendered search results, I see the async snippet there.
In my _setDomainName method, I have a leading period before the domain: .mysite.com which is consistent with the other Google Analytics-enabled pages on the rest of our site.
The "best practice" for this seems to be an area of some discussion: http://www.roirevolution.com/blog/2011/01/google_analytics_subdomain_tracking.php
Many of the comments on that post refer to self-referrals.
On the appliance search results page, the Google Analytics snippet appears immediately following the <body> tag.
The discussion of where to locate the asynchronous snippet (or "parts" if it's being split) has been raised in repeated forum posts:
http://www.google.com/support/forum/p/Google%20Analytics/thread?tid=71ba44443f0bfbc3&hl=en
http://www.google.com/support/forum/p/Google%20Analytics/thread?tid=22ac794d8f26a2f4&hl=en
This has been a pretty good reference for me on the asynchronous snippet:
Asynchronous Tracking Usage Guide:
http://code.google.com/apis/analytics/docs/tracking/asyncUsageGuide.html
Moving the snippet to <head> would take me some thinking and a more thorough look at the XSLT (and probably tweaking that would be jeopardized with future appliance versions and potential XSLT changes)
In terms of debugging Analytics, I've started to focus on investigating the values of GA-specific cookies and the __utm.gif using Firebug and other similar browser tools.
This post:
http://blog.vkistudios.com/index.cfm/2008/12/17/Slicing-and-Dicing-Cookies--Part-2--Body-Parts
as well as its followup, and other pages at that site have really helped suggest an approach to troubleshooting.