在SharePoint2010中能夠經過Microsoft.Office.Server.WebAnalytics.Reporting.AnalyticsReportFunction類得到Web 分析報告,可是在SharePoint 2013中Web Analytics Service Application被併入了Search Service Application中,因此若是像在SharePoint2010中引入Microsoft.Office.Server.WebAnalytics.dll and Microsoft.Office.Server.WebAnalytics.UI.dll兩個類庫在2013中是沒法得到Web Analytics Report的,在SharPoint 2013中須要引入Microsoft.Office.Server.Search.dll,可用的方法有:數據庫
-GetSearchRePortc#
-GetRollUpAnalyticsItemDataide
Search analytics data 被存儲在名叫AnalyticsReportingStore的數據庫中,GetSearchRePort方法是經過調用名爲ar_procGetTopSearchReport的存儲過程實現的,GetRollupAnalyticsItemData方法 是經過調用 ar_procGetAnalyticsItemData實現的
wordpress
GetSearchReport 有如下參數: 網站
reportType -int:報告的類型,1 表明 top queriesui
tenantId - GUID:SharePoint租戶的ID。若是在SharePoint Farm安裝時沒有具體的設置,則能夠設爲空的Guid
google
siteId – guid : 網站集 id.若要獲取包含網站集則設爲空的GUIDspa
reportDate - DateTime:報告的時間code
bDaily - bool: true 則返回RePortDate設置的當天的結果, false 則返回RePortDate所在整個月的結果
事件
maxRows – uint : 搜索結果的最大條數
下面的例子展現瞭如何得到某個月的Top 搜索關鍵詞
SPSecurity.RunWithElevatedPrivileges(delegate { // You can use SPContext.Current.Site.ID if you have HttpContext using (var site = new SPSite(siteId)) { var context = SPServiceContext.GetContext(site); var searchProxy = context.GetDefaultProxy(typeof(SearchServiceApplicationProxy)) as SearchServiceApplicationProxy; var topQueries = searchProxy.GetSearchReport(1, Guid.Empty, Guid.Empty, startDate, false, maxRows); foreach (var query in topQueries) { //process top search term } } });
GetRollupAnalyticsItemData 有以下參數:
eventType – int :事件類型 e.g. 1 表明 Site Usage Reports
tenantId – guid :和GetSearchReport中參數意義同樣
siteId – guid : 網站集ID
scopeId – guid : 子網站id, 若是須要返回整個網站集下的ID則設爲Guid.Empty
下面的代碼展現瞭如何獲取 the daily and monthly usage reports of Hits and Users count:
SPSecurity.RunWithElevatedPrivileges(delegate { // You can use SPContext.Current.Site.ID if you have HttpContext using (var site = new SPSite(siteId)) { var context = SPServiceContext.GetContext(site); var searchProxy = context.GetDefaultProxy(typeof(SearchServiceApplicationProxy)) as SearchServiceApplicationProxy; var usageData= searchProxy.GetRollupAnalyticsItemData(1,Guid.Empty,site.ID,Guid.Empty); usageData.GetHitCountForDay(date); usageData.GetHitCountForMonth(date); } });原文連接:http://radutut.wordpress.com/2013/01/27/how-to-get-search-analytics-reports-programmatically-in-sharepoint-2013/