Google Search Appliance - How to add Omniture's SiteCatalyst code

Published on January 31, 2009

I originally posted this on Google's Search Appliance Group for work, however, there was an issue with Google's HTML editor that kept messing up and refusing to display it. One of the group admins was finally able to post it but they had to leave out some code in order to do it. It's presented here in its entirety.

In order to add Omniture's SiteCatalyst code to a Google Search Appliance you need to modify the raw XSLT stylesheet. The following customizations will insert the tracking code after the opening <body> tag on the search results page. As per the implementation requirements by Omniture, the code will also dynamically set s.prop1 to the search terms and s.prop2 to the number of results returned. If zero results are returned we populate s.prop2 with "zero" and not 0.

Before you implement these changes be sure to make a backup of your existing stylesheet.

Implementation

Step 1:

Add the following code to the end of the section where Google recommends you make customizations. Replace the "INSERT-DOMAIN-AND-PATH-TO-CODE" with the location where you uploaded the s_code.js file:

<!-- **********************************************************************
 Add Omniture SiteCatalyst code (can be customized)
     ********************************************************************** -->

<xsl:template name="sitecatalyst">
  <xsl:param name="query"/>
  <xsl:param name="matches"/>
  <xsl:comment>
    SiteCatalyst code version: H.16.
    Copyright 1997-2008 Omniture, Inc. More info available at
    http://www.omniture.com
  </xsl:comment>
  <script language="JavaScript" type="text/javascript" src="INSERT-DOMAIN-AND-PATH-TO-CODE/s_code.js"></script>

  <script language="JavaScript" type="text/javascript">
    <xsl:comment>
      s.prop1="<xsl:value-of select='$query'/>"
      s.prop2="<xsl:value-of select='$matches'/>"
      var s_code=s.t();if(s_code)document.write(s_code)
  //</xsl:comment>
  </script>

  <script language="JavaScript" type="text/javascript">
    <xsl:comment>
      if(navigator.appVersion.indexOf('MSIE')>=0)document.write(unescape('%3C')+'\!-'+'-')
  //</xsl:comment>
  </script>
  <xsl:comment>

    End SiteCatalyst code version: H.16.
  </xsl:comment>
</xsl:template>


Step 2:

Next, locate the XSL template named, search_results and place the following code after the opening <body> tag:


<!-- *** Add Omniture SiteCatalyst code *** -->
<xsl:choose>

  <xsl:when test="RES">
    <xsl:call-template name="sitecatalyst">
      <xsl:with-param name="query" select="Q"/>
      <xsl:with-param name="matches" select="RES/M"/>
    </xsl:call-template>
  </xsl:when>

  <xsl:otherwise>
    <xsl:call-template name="sitecatalyst">
      <xsl:with-param name="query" select="Q"/>
      <xsl:with-param name="matches" select="'zero'"/>
    </xsl:call-template>
  </xsl:otherwise>

</xsl:choose>
    

Conclusion

Save your changes and you should be in business. The Google Search Protocol Reference states the XSL stylesheet cache is updated approximately every 15 minutes. I have found it can take a lot longer. In order to force it to refresh the stylesheet currently being requested simply add &proxyreload=1 to the end of your search URL.

Comments are closed.

Comments have been closed for this post.