SharePoint usage reports using object model

Posted: December 16, 2009 in Object Model, Site Usage

To get the usage details of the site we use the method site.GetUsage(SPUsageReportType , SPUsagePeriodType ).

SPUsageReportType Enumeration

The SPUsageReportType enumeration specifies the type of information returned in a usage report for a SharePoint site.

The following table shows the members of the SPUsageReportType enumeration and a brief description

Name Description
browser The type of Web browser used to visit the SharePoint site. All usage data refers specifically to visits from referring URLs external to the site.
os The operating system used on the client computer. All usage data refers specifically to visits from referring URLs external to the site.
refUr External URLs through which users navigated to the SharePoint site.
url URLs of pages that are visited or of pages for lists that are updated. Discussions about a page are counted as hits on that page.
user Users who visited the site.

SPUsagePeriodType Enumeration

The SPUsagePeriodType enumeration specifies the time interval on which a usage report for a Web site is based.

The following table shows the members of the SPUsagePeriodType enumeration and a brief description

Name Description
day Returns usage information for each day during the past 31 days starting from the previous day
lastMonth Summarizes usage information for the last 31 days relative to the previous day

Below are details how we can access respective data.

Accessing User daily report

//Users who visited the site
DGUsers.DataSource = site.GetUsageData(SPUsageReportType.user, SPUsagePeriodType.day);

Accessing User monthly report

//Users who visited the site
DGUsers.DataSource = site.GetUsageData(SPUsageReportType.user, SPUsagePeriodType.lastMonth);

Accessing Browser daily report

//The type of browsers used to visit the site
DGBrowser.DataSource = site.GetUsageData(SPUsageReportType.browser, SPUsagePeriodType.day);

Accessing Browser monthly report

//The type of browsers used to visit the site
DGBrowser.DataSource = site.GetUsageData(SPUsageReportType.browser, SPUsagePeriodType.lastMonth);

Accessing Operating System daily report

//The Operating System used in client computer
DGOs.DataSource = site.GetUsageData(SPUsageReportType.os, SPUsagePeriodType.day);

Accessing Operating System monthly report

//The Operating System used in client computer
DGOs.DataSource = site.GetUsageData(SPUsageReportType.os, SPUsagePeriodType.lastMonth);

Accessing refUrl daily report

//External URL client used to navigate to SharePoint site
DGRefUrl.DataSource = site.GetUsageData(SPUsageReportType.refUrl, SPUsagePeriodType.day);

Accessing refUrl monthly report

//External URL client used to navigate to SharePoint site
DGRefUrl.DataSource = site.GetUsageData(SPUsageReportType.refUrl, SPUsagePeriodType.lastMonth);

Accessing url daily report

//URL’s of pages visited
UsageGrid.DataSource = site.GetUsageData(SPUsageReportType.url, SPUsagePeriodType.day);

Accessing url monthly report

//URL’s of pages visited
UsageGrid.DataSource = site.GetUsageData(SPUsageReportType.url, SPUsagePeriodType.lastMonth);

Advertisements
Comments
  1. kiran says:

    i have writen object model for usage report its working fine development server how ever its not giving proper data production … do u have any idea.

  2. kiran says:

    i have writen object model for usage report its working fine in development server how ever its not giving proper data in production server… do u have any idea.

  3. @Kiran – Did you checked whether you are having proper permissions for the account you are executing the code??
    Also any error logs u got??

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s