umbracoStats is not only about fancy 3d reports, it's also a tool that can be used to display information on your website. The Standard and Premium versions offers a nice and simple api (in the umbraco.stats.Businesslogic.Library namespace) to get stat information:
- public static SortedList GetMostPopular(int NumberOfItems, DateTime StartDate, DateTime EndDate)
- public static SortedList GetMostPopular(int ParentId, int NumberOfItems, DateTime StartDate, DateTime EndDate)
- public static SortedList GetMostPopular(umbraco.cms.businesslogic.web.DocumentType DocumentType, int NumberOfItems, DateTime StartDate, DateTime EndDate)
- public static SortedList GetMostPopular(int[] DocumentTypes, int NumberOfItems, DateTime StartDate, DateTime EndDate)
- public static SortedList GetMostPopular(int[] DocumentTypes, int ParentId, bool Deep, int NumberOfItems, DateTime StartDate, DateTime EndDate)
All of these methods returns a SortedList of StatItem objects containing info on id, name and number of visits. As you can see you can filter these lists by parentids, document types and dates.
Here's a simple sample (requires a reference made to the umbraco.stat dll):
// Get the ten most popular pages from the whole website last week as an ordered html list and append it to a literal control SortedList results;
results = umbracoStat.Businesslogic.Library.GetMostPopular(-1, 10, DateTime.Now.AddWeeks(-1), DateTime.Now);
// Loop through results and display as an orderedList
IDictionaryEnumerator ide = results.GetEnumerator();
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<ol>");
while (ide.MoveNext())
{
umbracoStat.Businesslogic.StatItem statItem = (umbracoStat.Businesslogic.StatItem) ide.Value;
sb.Append("<li><a href=\"" + umbraco.library.NiceUrl(statItem.Id) + "\">" + statItem.Name + "</a>: " + statItem.Hits + "</li>\n\r");
}
sb.Append("</ol>");
LiteralStatList.Text = sb.ToString();