How can I capture the users username?
If the web application you are monitoring requires a login and you would like to be able to track performance down to an individual user then you can have the webtuna.js capture the username by overriding the JavaScript function with your own function to get it from the application and return it to WebTuna.
The JavaScript function needs to be called wt.user and needs to be declared somewhere in the page so that it exists at the point the where the onload handler is called.
If this function is not present then WebTuna will create its own ‘username’ which is based on the timestamp when the user first connects. This is set in a cookie and is useful to track track unique visitors to the site.
Example for SharePoint
Option 1: Capture SharePoint UserId
This example code will capture the SharePoint userid so it can be seen by WebTuna. Note the userid capture code must come after the line which calls webtuna.js. You may need to modify src to point to the location where you copied the webtuna.js.
<script type="text/javascript" src="/_layouts/15/webtuna.js"></script> <script type="text/javascript"> wt.user = function () { return _spPageContextInfo.userId; }; </script>
Option 2: Capture SharePoint UserName
This example code will capture the SharePoint username so it can be seen by WebTuna.
It requires an additional registration at the top of the master page if it isn’t already in there. The Version =15.0.0.0 below is for SharePoint 2013. This may need to be changed to Version =14.0.0.0 for SharePoint 2010 or Version =16.0.0.0 for Office 365.
<%@ Register Tagprefix="SPSWC" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
This code goes at the bottom of the master page before the closing </body> tag. Note the username capture code must come after the line which calls webtuna.js. You may need to modify src to point to the location where you copied the webtuna.js.
<script type="text/javascript" src="/_layouts/15/webtuna.js"></script> <script type="text/javascript"> var wt_user = '<SPSWC:ProfilePropertyLoader runat="server" /><SPSWC:ProfilePropertyValue PropertyName="UserName" TitleMode="true" runat="server"/>'; wt.user = function () { return wt_user; }; </script>