%3CLINGO-SUB%20id%3D%22lingo-sub-509700%22%20slang%3D%22en-US%22%3EHOW%20TO%3A%20Retrieve%20Web%20Analytics%20report%20data%20using%20API%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-509700%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSTRONG%3E%20First%20published%20on%20TECHNET%20on%20Oct%2004%2C%202012%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EThis%20blog%20post%20is%20a%20contribution%20from%20Aaron%20Miao%2C%20an%20engineer%20with%20the%20SharePoint%20Developer%20Support%20team.%3C%2FP%3E%0A%3CP%3EIn%20a%20scenario%20that%20you%20want%20to%20render%20Web%20Analytics%20report%20data%20to%20your%20favorite%20format%2C%20you%20need%20to%20retrieve%20the%20report%20data.%20There%E2%80%99s%20no%20document%20on%20how%20to%20retrieve%20SharePoint%20built-in%20report%20data.%20Some%20online%20articles%20are%20suggesting%20retrieving%20data%20directly%20from%20Web%20Analytics%20reporting%20database.%20It%E2%80%99s%20not%20recommended.%20Even%20with%20this%20approach%2C%20often%20customer%20faces%20issue%20of%20getting%20AggregationId%20which%20is%20required%20to%20retrieve%20data%20from%20database.%3C%2FP%3E%0A%3CP%3EHere%E2%80%99s%20the%20sample%20code%20that%20can%20be%20used%20to%20retrieve%20Web%20Analytics%20report%20data.%3C%2FP%3E%0A%3CDIV%20id%3D%22codeSnippetWrapper%22%3E%0A%3CDIV%20id%3D%22codeSnippet%22%3E%3CBR%20%2F%3E%3CPRE%3Eusing%20Microsoft.Office.Server.WebAnalytics.Reporting%3B%20%3CBR%20%2F%3E%3CBR%20%2F%3EAnalyticsReportFunction%20ar%20%3D%20new%20AnalyticsReportFunction()%3B%26nbsp%3B%0Aobject%5B%2C%5D%20result%20%3D%20ar.GetWebAnalyticsReportData(%26nbsp%3B%0A%20%20%22http%3A%2F%2Fyoursiteurl%2F%22%2C%26nbsp%3B%0A%20%20%222%22%2C%20%2F%2F%20Report%20level%2C%26nbsp%3B%0A%20%20%22TopPageForPageReport%22%2C%20%2F%2F%20Report%20name%2C%26nbsp%3B%0A%20%20DateTime.Today.AddDays(-30.0)%2C%20%2F%2F%20Start%20date%2C%26nbsp%3B%0A%20%20DateTime.Today)%3B%20%2F%2F%20End%20date%2C%26nbsp%3B%3C%2FPRE%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20the%20above%2C%20the%20Report%20level%20parameter%20is%20shown%20below%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20257px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F111421i11DF0FFEC27F9B12%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAnd%20the%20Report%20name%20parameter%20is%20shown%20below%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20210px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F111422i9F81C05B0501EC61%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHere%E2%80%99s%20what%20is%20returned%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20575px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F111423i0CC5DADDD5C9FAA3%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAnd%20here%E2%80%99s%20what%20you%20see%20from%20UI%20(WA%20report)%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20624px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F111424iBEA30AB58F2EF971%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-509700%22%20slang%3D%22en-US%22%3E%3CP%3EFirst%20published%20on%20TECHNET%20on%20Oct%2004%2C%202012%20This%20blog%20post%20is%20a%20contribution%20from%20Aaron%20Miao%2C%20an%20engineer%20with%20the%20SharePoint%20Developer%20Support%20team.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-509700%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

First published on TECHNET on Oct 04, 2012

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

 

And the Report name parameter is shown below:

 

Here’s what is returned

 

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