Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 25064

Get page Views Programmatically in share point 2013

$
0
0

In my project i need to get page views programmatically,

I have done in Sharepoint2010 using analyticreport,but in sharepoint2013 we don't have analyticreport same we need to get it using search service application class.\

SP2010

using (SPSite spsite = new SPSite(nodevalue))
                {
                    using (currentWeb = spsite.OpenWeb())
                    {
                        AnalyticsReportFunction AnalyticReport = new AnalyticsReportFunction(); //create object of analyticsReport
                        Thread.CurrentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());//this is used only in timer job if not used then GetWebAnalyticsReportData will not work
                        object[,] result = null;                       
                       result = AnalyticReport.GetWebAnalyticsReportData(
                  spsite.Url, "2","TopPageForPageReport",
                  DateTime.Today.AddDays(-30.0),
                  DateTime.Today);
                                               for (int counter = 0; counter < (result.Length)/4; counter++) //show top ten pages
                        {
         string pageurl = result[counter, 0].ToString();                       
                            }
                        }
SP2013
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);
        }
 });

But i dont know how to get page views using searchserviceapplication class, because it gives only hits counts and unique users count..

i need to get page views(page name + view count),Please do let me know if any way i can get page views in sp2013 programmatically

Thanks in advance.

 

Viewing all articles
Browse latest Browse all 25064

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>