There are 100 members in a organisation where permanent employees have alias as test\test user and contractors have test\s@test user
I need to display usage analytics to check whether user is a contractor or permanent employee.I am looking to display data as in the format below,How can i achieve this..In column UserName/Alias can we get if user is permanent test user if not s@test user
Day Hits Hits UniqueUser Username/Alias
2014/10/28 16 3
2014/10/29 26 6
Hi,
As I understand, you want to display usage analytics with user name and user alias in SharePoint 2013.
There is no OOB way to achieve it. You could develop the SharePoint Usage Analysis data with web application according to your requirements.
You could access the information of the site usage data using the public method "GetUsageData" of the SPWeb object as displayed in code example.
GetUsageData(Microsoft.SharePoint.Administration.SPUsageReportType, Microsoft.SharePoint.Administration.SPUsagePeriodType) Method.
The GetUsageData method of the SPWeb class returns a data table that contains information about the usage of a Web site based on the specified type of report and time interval.
For more detailed information, you could refer to the article below.
The article below is about Monitoring SharePoint Usage through an ASP.NET Web Application.
The article below is about SPWeb.GetUsageData method (SPUsageReportType, SPUsagePeriodType).
https://msdn.microsoft.com/en-us/library/office/ms455850.aspx
The article below is about SPUsageReportType Enumeration.
https://msdn.microsoft.com/en-us/library/dd587883(v=office.11).aspx
The article below is about Microsoft.Office.Server.Search.Analytics namespace.
https://msdn.microsoft.com/en-us/library/microsoft.office.server.search.analytics.aspx
The article below is about Get number of hits to a page SharePoint(2013) Analytics.
https://spserengeti.wordpress.com/2014/11/08/get-number-of-hits-to-a-page-sharepoint2013-analytics/
Best regards,
Sara Fan
Using below code i am getting site-name,URL,No.of users and Hit Count.How can i get username?What method needs to be added to achieve username
Site Name | URL | No. of Users | Hits Count |
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
Microsoft.SharePoint;
using
Microsoft.SharePoint.Administration;
using
System.Data;
using
System.IO;
namespace
AdminReports
{
class
GetSiteUsageReport
{
//Method to Get Usage Data
public
static
int
GetUserCount(SPWeb oSPWeb)
{
try
{
//Get the Usage Details
object
userCount =
null
;
//DataTable for users set - Because GetUsageData returns DataTable!
DataTable dtUsers =
new
DataTable();
dtUsers = oSPWeb.GetUsageData(SPUsageReportType.user, SPUsagePeriodType.lastMonth);
if
(dtUsers !=
null
)
{
userCount = dtUsers.Compute(
"Count(user)"
,
string
.Empty);
return
(Convert.ToInt32(userCount));
}
else
{
return
(0);
}
}
catch
(Exception Ex1)
{
return
(0);
}
}
//Method to Get Hits Data
public
static
int
GetHitsCount(SPWeb oSPWeb)
{
try
{
//DataTable for Hits set - Because GetUsageData returns DataTable!
object
totalHits =
null
;
DataTable dtHits =
new
DataTable();
dtHits = oSPWeb.GetUsageData(SPUsageReportType.url, SPUsagePeriodType.lastMonth);
if
(dtHits !=
null
)
{
totalHits = dtHits.Compute(
"Sum([Total Hits])"
,
string
.Empty);
return
(Convert.ToInt32(totalHits));
}
else
{
return
(0);
}
}
catch
(Exception Ex2)
{
return
(0);
}
}
static
void
Main(
string
[] args)
{
string
site;
try
{
if
(args.Length == 0)
{
Console.WriteLine(
"Enter the Web Application URL:"
);
site = Console.ReadLine();
}
else
{
site = args[0];
}
SPSite tmpRoot =
new
SPSite(site);
SPSiteCollection tmpRootColl = tmpRoot.WebApplication.Sites;
//objects for the CSV file generation
StreamWriter SW;
SW = File.AppendText(
"c:\\SiteUsageReport.csv"
);
//Write the CSV Header
SW.WriteLine(
"Site Name, URL, No. of Users, Hits Count"
);
//Enumerate through each site collection
foreach
(SPSite tmpSite
in
tmpRootColl)
{
//Enumerate through each sub-site
foreach
(SPWeb tmpWeb
in
tmpSite.AllWebs)
{
//Get the Site Name
string
siteName;
if
(tmpWeb.IsRootWeb)
{
siteName = tmpWeb.Title +
"
- Root"
;
}
else
{
siteName = tmpSite.RootWeb.Title +
"
- "
+ tmpWeb.Title;
}
//Log the retrieved details to a CSV file
SW.WriteLine(siteName.Replace(
","
,
"
"
) +
","
+ tmpWeb.Url +
","
+ GetUserCount(tmpWeb) +
","
+ GetHitsCount(tmpWeb)
);
}
}
//Dispose of the Root Site Object
SW.Close();
tmpRoot.Dispose();
}
catch
(Exception ex)
{
System.Diagnostics.EventLog.WriteEntry(
"Site Usage Report Report"
, ex.Message);
}
}
}
}
Hi,
As I understand, you want to get user name from usage analytics in SharePoint 2013.
In usage reports created by using one of the GetUsageData methods of the SPWeb class, the SPUsageReportType enumeration is used together with the SPUsagePeriodType enumeration to define the information returned.
There is a member named user Indicating users who visited the site.
For more detailed information, you could refer to the articles below.
The article below is about SPUsageReportType Enumeration
The article below is about SPUsagePeriodType Enumeration.
Best regards,
Sara Fan