Sharepoint hit counter web part

On 11th November, 2009 I have published the HitCounter webpart solution on to Codeplex

Hit Counter

Hit Counter

I have made the Hit Counter webpart very compact with minimum lines of code which generates user hits, before adding the webpart to the master page you need to create a Custom List name it as Statistics then create three columns in Statistics list as below:

  1. url Multiple lines of text
  2. date Single line of text
  3. uname Single line of text

Also, you have to give the Contribute – Can view, add, update, and delete permissions for the Visitor and Viewers for the Statistics list, so that visitor/viewers visits also recorded in the list.

To give permissions

  1. Go to Statistics list, Settings > List Settings
  2. Under Permissions and Management click on Permissions for this list
  3. Select Visitors checkbox then click on Actions > Edit User Permissions then select Contribute – Can view, add, update, and delete
  4. Finally click Ok button

Please Note: For applying Contribute – Can view, add, update, and delete permissions for Viewers repeat the above 1, 2, 3 and 4 steps

If a user is new to current page on the day, the code adds a record to Statistics list, if the same user visits the same page the code just returns out from condition and do nothing, because the user already visited the page on the same day, this is all because of to maintain the unique hits

To know the hit count for all pages in site, you have to place the webpart in master page, so that the webpart code runs on every page where the visitor go and makes the unique entry in Statistics list

Statistics List

Statistics List

You can download the Hit Counter webpart from http://hitcounter.codeplex.com/

Comments on this solution are very much appreciated 🙂

Thanks for looking into this