...
Sacramento State chose not to track parameters such as affiliations so this step was skipped.
Step 3: Add google analytics code
- Edit universality.xsl (../uportal-war/src/main/resources/layout/theme/universality/universality.xsl)
- Add the two following template code snippets, "page.js" and page-bottom.js"tracking-action", to universality.xsl
This section sets up asynchronous google analytics tracking. It is located in the The "page.js" template which puts the script at the top of every generated page in the head element.
...
Code Block | ||
---|---|---|
| ||
<xsl:template name="page.js"> <script type="text/javascript"> <xsl:choose> <xsl:when test="$serverEnv='my.uchicago.edu'"> var env = "<xsl:value-of select="$serverEnv" />"; var gaAcct = "*************"; </xsl:when> <xsl:when test="$serverEnv='mystage.uchicago.edu'"> var env = "<xsl:value-of select="$serverEnv" />"; var gaAcct = "*************"; </xsl:when> <xsl:otherwise> var env = "<xsl:value-of select="$serverEnv" />"; var gaAcct = "*************"; </xsl:otherwise> </xsl:choose> var _gaq = _gaq || []; _gaq.push(['_setAccount', gaAcct]); _gaq.push(['_setDomainName', env]); _gaq.push(['_trackPageview']); </script> </xsl:template> <xsl:template name="tracking-action"> <script type="text/javascript"> (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga); })(); </script> </xsl:template> |
Step 4: Add tracking
Once the tracking api is loaded, we place tracking code on any of the user initiated events we want to track during their session.
For example, in the sections below we are tracking these events: portlet minimize, portlet maximize, portlet removed, change portlet tab, add content, add tab and customize tab layout.
The following was added to components.xsl (uportal-war/src/main/resources/layout/theme/universality/components.xsl)
Code Block | ||
---|---|---|
| ||
<a id="contentDialogLink" onclick="_gaq.push(['_trackEvent', 'gaAcct','ADD CONTENT']);" href="javascript:;"
title="{$TOKEN[@name='PREFERENCES_LINK_ADD_CONTENT_LONG_LABEL']}">
<span><xsl:value-of select="$TOKEN[@name='PREFERENCES_LINK_ADD_CONTENT_LABEL']"/></span>
</a>
...
<a id="layoutDialogLink" onclick="_gaq.push(['_trackEvent', 'gaAcct','TAB LAYOUT']);" href="javascript:;"
title="{$TOKEN[@name='PREFERENCES_LINK_LAYOUT_LONG_LABEL']}">
<span><xsl:value-of select="$TOKEN[@name='PREFERENCES_LINK_LAYOUT_LABEL']"/></span>
</a>
...
<a id="addTabLink" onclick="_gaq.push(['_trackEvent', 'gaAcct','ADD TAB']);" href="javascript:;"
title="{$TOKEN[@name='PREFERENCES_LINK_ADD_TAB_LONG_LABEL']}">
<span><xsl:value-of select="$TOKEN[@name='PREFERENCES_LINK_ADD_TAB_LABEL']"/></span>
</a> |
Info | ||||
---|---|---|---|---|
| ||||
...