Skip to content

Instantly share code, notes, and snippets.

@MarcStoecker
Created October 1, 2012 14:20
Show Gist options
  • Save MarcStoecker/3812062 to your computer and use it in GitHub Desktop.
Save MarcStoecker/3812062 to your computer and use it in GitHub Desktop.
simple umbraco GA tracking (concept/mockup)
$(function() {
var foo = "";
$("body").find("[data-tracking=='']").each(function(index) {
if ($(this).data("tracking")!='')
{
var trackingTokens = $(this).data("tracking").split(",");
$(this).click(function() {
_gaq.push(["_trackEvent", trackingTokens[0], trackingTokens[1], trackingTokens[2]]);
});
}
});
});
<xsl:for-each select="$linkliste//url-picker">
<li>
<!-- tracking presets for javascript tracking plugin (google analytics) -->
<xsl:attribute name="data-tracking">
<xsl:variable name="trackingContentTitle">
<xsl:choose>
<xsl:when test="link-title!=''"><xsl:value-of select="link-title"/></xsl:when>
<xsl:otherwise><xsl:value-of select="url"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="@mode='Media'">Media,Download,<xsl:value-of select="umbraco.library:HtmlEncode($trackingContentTitle)"/></xsl:when>
<xsl:when test="@mode='URL'">Ausgehende Links,Klick,<xsl:value-of select="umbraco.library:HtmlEncode($trackingContentTitle)"/></xsl:when>
<xsl:when test="@mode='Upload'">Media,Download,<xsl:value-of select="umbraco.library:HtmlEncode($trackingContentTitle)"/></xsl:when>
<!-- do not track (set empty string): 'Content', all others -->
<xsl:otherwise></xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<a>
<xsl:attribute name="href">
<xsl:choose>
<xsl:when test="@mode='Content'"><xsl:value-of select="umbraco.library:NiceUrl(node-id)"/></xsl:when>
<xsl:otherwise><xsl:value-of select="url"/></xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:if test="Exslt.ExsltStrings:lowercase(new-window)='true'">
<xsl:attribute name="target">_blank</xsl:attribute>
</xsl:if>
<xsl:value-of select="link-title"/>
</a>
</li>
</xsl:for-each>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment