Search code examples
sitecoresitecore6sitecore-dms

Get the page count


I am developing a website using Sitecore 6.5

One of the requirements is to display 5 most popular pages at the right corner.

For that, I think of using the function that Analytic reports used for Page count.

I would like to know whether it is possible to do so by using Analytics API Sitecore.Analytics

If so, can I have some code snippets to do it as I am totally lost.


Solution

  • Here's how you can do it in DMS:

    private const string CommandText = "\r\nSELECT \r\ncount(distinct {0}VisitId{1})\r\n FROM {0}Pages{1}\r\n WHERE {0}ItemId{1} = {2}YourItemId{3}";
    
    public static int GetPageViews(ID pageId)
    {
      return DataAdapterManager.Provider.Sql.ReadOne<int>(CommandText, ReadPageViews, new object[] { "YourItemId", pageId.ToString() });
    }
    
    private static int ReadPageViews(DataProviderReader reader)
    {
      return DataAdapterManager.Provider.Sql.GetInt(0, reader);
    }