Geeks With Blogs

News invisible hit counter View My Stats
Technical Speaking

How to create a custom hit counter webpart for SharePoint internal web portal.

This is a common requirement sometimes from the client to integrate hit counter for their internal enterprise web portal. For example hit counter will show total visitor in the site as well as what are the pages accessed by IP/user/date/etc. i.e.

Total Hit Count: Hit_CounterI also got the similar type of request both from the community and the clients as there is no built-in feature to enable this feature in SharePoint 2010. Recently I also got the following question in my blog post.


I replied him in short summary how to do this but now I am trying to describe with more details about it.

How to:

There is already a Hit Counter Web Part Developed by G Vijai Kumar for MOSS (SP 2007). You can download this form codeplex

For SharePoint 2010: “Create Custom hit counter in SharePoint2010 using Sandbox Solution” is also available at MSDN code by Ravishankar Singh which works for single site without any issues. But if you want to use this for all sites through out the farm then build Visual web part to do this using same code and place it in all Master Pages. Let me explain you step by step how to use and customize it.

Step 1: Create a Visual Web Part and copy the code inside Page_Load(object sender, EventArgs e) as same as they did inside Render() Method.

Step 2(Optional): Add the following code if you want to record Client IP address with User, Data & URL.



Step 3: Deploy Hit counter using command (Powershell or STSADM) or VS 2010 to this site

Step 4: Create a Custom List, name it as Statistics or Record List also create three or four columns in Statistics list as like as below:

1.Url    -                    Multiple lines of text
2.Date -                    Single line of text
3.Username -            Single line of text
4.IP -                      Single line of text
(This can be create also form Feature Event receiver. In that case list will be created automatically when Deploy the web part. Skip it if you do not use the downloaded code)

Step: 5: Add this web part in home page or the page that you want to count. To count the hit  for all pages in site, you have to place the webpart in all master page, so that the webpart code runs on every page where the visitor go and makes the unique entry in Statistics list.

Finally, You will get a view something like the following in the custom created statistics list:



I am not including my code here as basic code is already given by Ravishankar Singh at

Anyway, If you need by source code then email me or you can customize the above code as per as my given instructions.


Hope this will help!

Posted on Friday, February 15, 2013 2:05 PM SharePoint 2010 | Back to top

Comments on this post: Hit counter for SharePoint Internal Site

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © MJ Ferdous | Powered by: