SharePoint Developer Support Team Blog

The Official blog of the SharePoint Developer Support Team

HOW TO: Retrieve Web Analytics report data using API

HOW TO: Retrieve Web Analytics report data using API

  • Comments 22
  • Likes

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(
                "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:


And the Report name parameter is shown below:


Here’s what is returned


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


  • Nice post, I'll need to try this out!

  • your post is very good .

    i have a question, how to get FAST Search Connector Crawl Log  or History?

    however the  CrawlLog Class methods is obsoleted , please help if you have any answer .

  • Nice post

  • Nice Post. Do you know the client side API for Usage Analytic report data in SharePoint 2013 ?  I have a requirement to show the page views in custom developed apps. let me know your views if you can.

  • Hi raam,

    Web Analytics has been changed in SharePoint 2013 significantly. Please check out the followings articles for details. Haven't got chance to research how you can bring those limited reports in an app.

  • nice post,
    i need to get same in sharepoint2013,if u have code pls share.
    i know this feature is removed in Sp2013,it is merged with search service application.
    but i m not knowing how to get in SP2013.
    i tried below linked post but no use

  • Here's an example for SharePoint 2013:

    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Administration;
    using Microsoft.Office.Server.Search.Administration;
    using Microsoft.Office.Server.Search.Analytics;
    SPSite site = new SPSite("http://yourserver/sites/testsite/");
    SPUserToken userToken = site.UserToken;

    using (SPSite site1 = new SPSite(site.ID, userToken))
    SPServiceContext context = SPServiceContext.GetContext(site1);
    SearchServiceApplicationProxy searchProxy = context.GetDefaultProxy(typeof(SearchServiceApplicationProxy)) as SearchServiceApplicationProxy;
    AnalyticsItemData usageData = searchProxy.GetRollupAnalyticsItemData((int)SearchReportTypeId.TopQuery, Guid.Empty, Guid.Empty, Guid.Empty);

    int dailyHits = usageData.GetHitCountForDay(DateTime.Today);
    int monthlyHits = usageData.GetHitCountForMonth(DateTime.Today);
    Console.WriteLine(String.Format("Report Daily Hits={0}; Monthly Hits={1}", dailyHits, monthlyHits));

    uint maxRows = 1000;
    DateTime startDate = new DateTime(2014, 1, 24);
    IList searchResults = searchProxy.GetSearchReport((int)SearchReportTypeId.TopQuery, Guid.Empty, Guid.Empty, startDate.Date, true, maxRows);
    if (searchResults.Count > 0)
    foreach (QueryReportData rptData in searchResults)
    int hitsCnt = rptData.Count;
    string qry = rptData.Query;
    Guid scope = rptData.Scope;
    Console.WriteLine(String.Format("Report Count={0}; Query={1}; Scope={2}", hitsCnt, qry, scope.ToString()));

    SearchReportTypeId enumeration details are here:

  • Unfortunately, wasn't able to get this working with SummaryReport on 2010. Always got the "viewName" error. Anyone had success?

  • I also get the "viewName" error when accessing the SummaryReport. I'm tried the fixes described above

  • "Viewname" exception is always thrown when the report level and the report name is not compatible to each other.

  • Hello

    i am trying to find that index of each report where we can find exactly value.
    for example: as you described in above example about this report name "TopPageForPageReport" . so you can see in quick watch of result array that:
    [0,0] index of array shows the page url.
    [0,1] index of array shows the Site collection name.
    [0,2] index of array shows the exact value of number of page views
    [0,3] index of array -- i dont have any idea about this index value.

    so i want the complete information of all the reports that which field is showing what data.

  • I am trying to use the code above as mentioned, I am getting "the site not found at url http://urlofthesite" for result[0,0].. has anyone faced this issue?

  • Hi, i can´t get data. All the time return in first parameter object[0,0] => "Value cannot be null.\r\nParameter name: identityName". What did i wrong?

  • I have a question, is it possible to retrieve the same data as the "GetSearchReport" method, only via the client side? Im working on an office 365 instance of sharepoint 2013 - using Napa as my remote dev environment and trying to pull a list of the most searched terms by month.

  • same as MM I am trying to use the code above as mentioned, I am getting "the site not found at url http://urlofthesite" for result[0,0].. has anyone faced this issue?

    Anyone found a solution?

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment