Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Sacramento State implemented the following steps, which are revisions of the original documentation to work for their environment:

Info
iconfalse

Documentation was provided by Dan Biondi at Sacramento State University

Step 1: Add the following java class file

...

Sacramento State chose not to track parameters such as affiliations so this step was skipped.

Step 3: Add google analytics code

  1. Edit universality.xsl (../uportal-war/src/main/resources/layout/theme/universality/universality.xsl)
  2. 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
titleuniversality.xsl
<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
titlecomponents.xsl
<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>

 

  • The following was then added to content.xsl (uportal-war/src/main/resources/layout/theme/universality/content.xsl)

 

 

Info
iconfalse
titleAdditional References
 

...

iconfalse
titleHaving problems with these instructions?

...

Code Block
titlecontent.xsl
<xsl:if test="not(@hasHelp='false')"> <!-- Help. -->
  <a onclick="_gaq.push(['_trackEvent','gaAcct', '{$PORTLET_TITLE}-Help']);" href="{$BASE_ACTION_URL}?uP_help_target={@ID}#{@ID}"
   title="{$TOKEN[@name='PORTLET_HELP_LONG_LABEL']}" class="up-portlet-control help">
   <span><xsl:value-of select="$TOKEN[@name='PORTLET_HELP_LABEL']"/></span>
  </a>
</xsl:if>

<xsl:if test="not(@hasAbout='false')"> <!-- About. -->
  <a onclick="_gaq.push(['_trackEvent','gaAcct', '{$PORTLET_TITLE}-About']);" href="{$BASE_ACTION_URL}?uP_about_target={@ID}#{@ID}"
   title="{$TOKEN[@name='PORTLET_ABOUT_LONG_LABEL']}" class="up-portlet-control about">
   <span><xsl:value-of select="$TOKEN[@name='PORTLET_ABOUT_LABEL']"/></span>
  </a>
</xsl:if>

<xsl:if test="not(@editable='false')"> <!-- Edit. -->
  <a onclick="_gaq.push(['_trackEvent','gaAcct', '{$PORTLET_TITLE}-Edit']);" href="{$BASE_ACTION_URL}?uP_edit_target={@ID}#{@ID}"
   title="{$TOKEN[@name='PORTLET_EDIT_LONG_LABEL']}" class="up-portlet-control edit">
   <span><xsl:value-of select="$TOKEN[@name='PORTLET_EDIT_LABEL']"/></span>
  </a>
</xsl:if>

<xsl:if test="@printable='true'"> <!-- Print. -->
 <a onclick="_gaq.push(['_trackEvent','gaAcct', '{$PORTLET_TITLE}-Print']);" href="{$BASE_ACTION_URL}?uP_print_target={@ID}#{@ID}"
  title="{$TOKEN[@name='PORTLET_PRINT_LONG_LABEL']}" class="up-portlet-control print">
  <span><xsl:value-of select="$TOKEN[@name='PORTLET_PRINT_LABEL']"/></span>
 </a>
</xsl:if>

<xsl:if test="not(//focused) and @minimized='false'"> <!-- Focus. -->
  <!-- UNCOMMENT FOR MINIMIZE CONTROL -->
  <a onclick="_gaq.push(['_trackEvent','gaAcct', '{$PORTLET_TITLE}-Minimize']);"
   href="{$BASE_ACTION_URL}?uP_root=root&amp;uP_tcattr=minimized&amp;minimized_channelId={@ID}&amp;minimized_{@ID}_value=true&amp;uP_save=all"
   title="{$TOKEN[@name='PORTLET_MINIMIZE_LONG_LABEL']}" class="up-portlet-control minimize">
   <span><xsl:value-of select="$TOKEN[@name='PORTLET_MINIMIZE_LABEL']"/></span>
  </a>

  <a onclick="_gaq.push(['_trackEvent','gaAcct', '{$PORTLET_TITLE}-Maximize']);" href="{$BASE_ACTION_URL}?uP_root={@ID}"
   title="{$TOKEN[@name='PORTLET_MAXIMIZE_LONG_LABEL']}" class="up-portlet-control focus">
   <span><xsl:value-of select="$TOKEN[@name='PORTLET_MAXIMIZE_LABEL']"/></span>
  </a>
</xsl:if>

<xsl:if test="@minimized='true'"> <!-- Return from Minimized. -->
 <!-- UNCOMMENT FOR UNMINIMIZE CONTROL -->
 <a onclick="_gaq.push(['_trackEvent','gaAcct', '{$PORTLET_TITLE}-UnMinimized']);"
   href="{$BASE_ACTION_URL}uP_root=root&amp;uP_tcattr=minimized&amp;minimized_channelId{@ID}&amp;minimized_{@ID}_value=false&amp;uP_save=all"
   title="{$TOKEN[@name='PORTLET_RETURN_LONG_LABEL']}" class="up-portlet-control return">
   <span><xsl:value-of select="$TOKEN[@name='PORTLET_RETURN_LABEL']"/></span>
 </a>
</xsl:if>

<xsl:if test="not(@dlm:deleteAllowed='false') and not(//focused) and /layout/navigation/tab[@activeTab='true']/@immutable='false'"> <!-- Remove. -->
  <a onclick="_gaq.push(['_trackEvent','gaAcct', '{$PORTLET_TITLE}-Removed']);" id="removePortlet_{@ID}"
    title="{$TOKEN[@name='PORTLET_REMOVE_LONG_LABEL']}" href="{$BASE_ACTION_URL}?uP_remove_target={@ID}"
    class="up-portlet-control remove"> <span><xsl:value-of select="$TOKEN[@name='PORTLET_REMOVE_LABEL']"/></span>
  </a>
</xsl:if>

<xsl:if test="//focused"> <!-- Return from Focused. -->
  <a onclick="_gaq.push(['_trackEvent','gaAcct', '{$PORTLET_TITLE}-UnMaximize']);" href="{$HOME_ACTION_URL}"
    title="{$TOKEN[@name='PORTLET_RETURN_LONG_LABEL']}" class="up-portlet-control return">
    <span><xsl:value-of select="$TOKEN[@name='PORTLET_RETURN_LABEL']"/></span>
  </a>
</xsl:if>

<xsl:if test="//focused[@in-user-layout='no'] and upGroup:isChannelDeepMemberOf(//focused/channel/@fname, 'local.1')"> <!-- Add to layout. -->
  <a onclick="_gaq.push(['_trackEvent','gaAcct', '{$PORTLET_TITLE}-Add']);" id="focusedContentDialogLink" href="javascript:;"
    title="{$TOKEN[@name='PORTLET_ADD_LONG_LABEL']}" class="up-portlet-control add">
    <span><xsl:value-of select="$TOKEN[@name='PORTLET_ADD_LABEL']"/></span>
  </a>
</xsl:if>

 

  • The following was finally added to navigation.xsl (uportal-war/src/main/resources/layout/theme/universality/navigation.xsl)

 

Code Block
titlenavigation.xsl
<xsl:for-each select="tabChannel">
    <li>
       <a onclick="_gaq.push(['_trackEvent', 'gaAcct','{@name}']);" href="{$BASE_ACTION_URL}?uP_root={@ID}&amp;uP_sparam=activeTab&amp;activeTab={$TAB_POSITION}"
         title="{@name}">  <!-- Navigation item link. -->
         <span><xsl:value-of select="@name"/></span>
       </a>
     </li>
 </xsl:for-each>

 

Step 5: Rebuild uPortal

After adding all of your tracking code, you should rebuild and redeploy your portal.

Step 6: Restart Tomcat

It will take 24 hours for you tracking code to show up in the portal.


 

Info
titleInterested in Sharing your Implementation?

If you are interested in sharing your Institution's implementation of Google Analytics send a post through the mailing list at: