[Yanel-commits] rev 44459 - in public/yanel/trunk/src: realms/yanel-website/res-configs-repo/data webapp/htdocs webapp/htdocs/Google-Analytics webapp/htdocs/commons

guillaume at wyona.com guillaume at wyona.com
Fri Aug 28 09:07:17 CEST 2009


Author: guillaume
Date: 2009-08-28 09:07:17 +0200 (Fri, 28 Aug 2009)
New Revision: 44459

Added:
   public/yanel/trunk/src/webapp/htdocs/Google-Analytics/
   public/yanel/trunk/src/webapp/htdocs/Google-Analytics/GA.xslt
   public/yanel/trunk/src/webapp/htdocs/Google-Analytics/page-GA.xslt
   public/yanel/trunk/src/webapp/htdocs/commons/
   public/yanel/trunk/src/webapp/htdocs/commons/Id.xslt
Modified:
   public/yanel/trunk/src/realms/yanel-website/res-configs-repo/data/english-yanel-rc.xml
Log:
Initial Google Analytics support (disabled).

Issue: 7169


Modified: public/yanel/trunk/src/realms/yanel-website/res-configs-repo/data/english-yanel-rc.xml
===================================================================
--- public/yanel/trunk/src/realms/yanel-website/res-configs-repo/data/english-yanel-rc.xml	2009-08-28 07:05:23 UTC (rev 44458)
+++ public/yanel/trunk/src/realms/yanel-website/res-configs-repo/data/english-yanel-rc.xml	2009-08-28 07:07:17 UTC (rev 44459)
@@ -4,6 +4,9 @@
   <yanel:rti name="xml" namespace="http://www.wyona.org/yanel/resource/1.0"/>
 
   <yanel:property name="mime-type" value="application/xhtml+xml"/>
+
   <yanel:property name="xslt" value="/xslt/global.xsl"/>
+  <!--yanel:property name="xslt" value="yanelhtdocs:/Google-Analytics/page-GA.xslt"/-->
+
   <yanel:property name="workflow-schema" value="/workflow/workflow-with-review.xml"/>
 </yanel:resource-config>

Added: public/yanel/trunk/src/webapp/htdocs/Google-Analytics/GA.xslt
===================================================================
--- public/yanel/trunk/src/webapp/htdocs/Google-Analytics/GA.xslt	                        (rev 0)
+++ public/yanel/trunk/src/webapp/htdocs/Google-Analytics/GA.xslt	2009-08-28 07:07:17 UTC (rev 44459)
@@ -0,0 +1,68 @@
+<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:yanel-xsl="http://www.wyona.org/yanel/xsl/1.0"
+ xmlns:xhtml="http://www.w3.org/1999/xhtml"
+>
+
+<xsl:param name="GA-key" select="'UA-xxxxxx-x'"/>
+
+
+<xsl:variable name="non-asset-URL-suffix" select="'.html'"/>
+
+
+<xsl:template match="xhtml:a">
+  <xsl:param name="URL" select="@href"/>
+  <xsl:choose>
+    <!--FIXME HACK: find a better method to differentiate document assets from pages: -->
+    <xsl:when test="substring($URL, string-length($URL) - string-length($non-asset-URL-suffix)) != $non-asset-URL-suffix"><!--ends-with($URL, $non-asset-URL-suffix)...-->
+      <xsl:call-template name="yanel-xsl:put-GA-asset-onclick-handler">
+        <xsl:with-param name="URL" select="$URL"/>
+      </xsl:call-template>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:apply-imports/>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+
+<xsl:template name="yanel-xsl:insert-GA-code">
+  <xsl:call-template name="yanel-xsl:insert-new-GA-code"/>
+</xsl:template>
+
+
+<xsl:template name="yanel-xsl:insert-new-GA-code">
+<script type="text/javascript"><xsl:text>
+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"));
+</xsl:text></script>
+<script type="text/javascript"><xsl:text>
+var pageTracker = _gat._getTracker("</xsl:text><xsl:value-of select="$GA-key"/><xsl:text>");
+pageTracker._trackPageview();
+</xsl:text></script>
+</xsl:template>
+
+
+<xsl:template name="yanel-xsl:put-GA-asset-onclick-handler">
+  <xsl:param name="URL"/>
+  <xsl:copy>
+    <xsl:apply-templates select="@*[name()='onclick']"/>
+    <xsl:attribute name="onclick">
+      <xsl:text>pageTracker._trackPageview('</xsl:text>
+      <xsl:call-template name="yanel-xsl:GA-asset-filename-from-URL">
+        <xsl:with-param name="URL" select="$URL"/>
+      </xsl:call-template>
+      <xsl:text>');</xsl:text>
+      <xsl:value-of select="@onclick"/>
+    </xsl:attribute>
+    <xsl:apply-templates select="node()"/>
+  </xsl:copy>
+</xsl:template>
+
+
+<xsl:template name="yanel-xsl:GA-asset-filename-from-URL">
+  <xsl:param name="URL"/>
+  <xsl:value-of select="substring-after($URL, '://')"/><!--TODO: make it works with relative URLs as well!!! -->
+</xsl:template>
+
+
+</xsl:transform>

Added: public/yanel/trunk/src/webapp/htdocs/Google-Analytics/page-GA.xslt
===================================================================
--- public/yanel/trunk/src/webapp/htdocs/Google-Analytics/page-GA.xslt	                        (rev 0)
+++ public/yanel/trunk/src/webapp/htdocs/Google-Analytics/page-GA.xslt	2009-08-28 07:07:17 UTC (rev 44459)
@@ -0,0 +1,22 @@
+<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:yanel-xsl="http://www.wyona.org/yanel/xsl/1.0"
+ xmlns:xhtml="http://www.w3.org/1999/xhtml"
+>
+
+
+<xsl:import href="../commons/Id.xslt"/>
+
+
+<xsl:include href="GA.xslt"/>
+
+
+<xsl:template match="xhtml:body">
+  <xsl:copy>
+    <xsl:apply-templates select="@*"/>
+    <xsl:call-template name="yanel-xsl:insert-GA-code"/>
+    <xsl:apply-templates select="node()"/>
+  </xsl:copy>
+</xsl:template>
+
+
+</xsl:transform>

Added: public/yanel/trunk/src/webapp/htdocs/commons/Id.xslt
===================================================================
--- public/yanel/trunk/src/webapp/htdocs/commons/Id.xslt	                        (rev 0)
+++ public/yanel/trunk/src/webapp/htdocs/commons/Id.xslt	2009-08-28 07:07:17 UTC (rev 44459)
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+XSLT identity transformation:
+ handy as a starting point for decorating stylesheets.
+
+ IMPORTANT: It has to be imported and not included,
+  so use it for example like this:
+  <xsl:import href="yanelhtdocs:/commons/Id.xslt"/>
+-->
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+>
+
+
+<xsl:template match="@*|node()" priority="-1">
+  <xsl:copy>
+    <xsl:apply-templates select="@*|node()"/>
+  </xsl:copy>
+</xsl:template>
+
+
+</xsl:stylesheet>



More information about the Yanel-commits mailing list