HOW TO: Retrieve Web Analytics report data using API

This blog post is a contribution from Aaron Miao, an engineer with the SharePoint Developer Support team.

In a scenario that you want to render Web Analytics report data to your favorite format, you need to retrieve the report data. There’s no document on how to retrieve SharePoint built-in report data. Some online articles are suggesting retrieving data directly from Web Analytics reporting database. It’s not recommended. Even with this approach, often customer faces issue of getting AggregationId which is required to retrieve data from database.

Here’s the sample code that can be used to retrieve Web Analytics report data.

 using Microsoft.Office.Server.WebAnalytics.Reporting;
  
 AnalyticsReportFunction ar = new AnalyticsReportFunction();  
 object[,] result = ar.GetWebAnalyticsReportData(
                 "https://yoursiteurl/",
                 "2",                            // Report level,
                 "TopPageForPageReport",         // Report name, 
                 DateTime.Today.AddDays(-30.0),  // Start date,
                 DateTime.Today);                // End date,

In the above, the Report level parameter is shown below:

image

And the Report name parameter is shown below:

image

Here’s what is returned

image

And here’s what you see from UI (WA report)

image