On 11th November, 2009 I have published the HitCounter webpart solution on to Codeplex
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:
- url Multiple lines of text
- date Single line of text
- 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
- Go to Statistics list, Settings > List Settings
- Under Permissions and Management click on Permissions for this list
- Select Visitors checkbox then click on Actions > Edit User Permissions then select Contribute β Can view, add, update, and delete
- 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
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
Hello Vijay,
iβm interested with your web part,
i have a need to create Hit Counter web Part, but it will be attached to a Button.
my needs :
in sharepoint page, i have a button.
if the button got clicked, it will be adding to a custom list, whichis contain : currentDate (date), clickedCounter (int),
than, the button will open new IE /redirect the user to another page, eq : http://www.fiveNumber.com
so, from that custom list data, i can make a report :
for this month, xx user has been click the button
and also i can create a daily report.
01.01.2010 – 11 clicked
02.01.2010 – 21 clicked
…..
….
i already try to download your sharing code,
but i can not open it with VS 2005 or VS 2008. (the project type is not supported).
can you help me..
gladly if you want to help / give hint how to create webpart that fullfill my needs.
thanks…
@ Jusufjk: You can place the entire code in button eg:
void Button_Click(object sender, EventArgs e)
{
//Place the entire code here what ever is in the render method
}
But, why you want to place the hit counter code in a button, if you place the entire code in a button then how you are going to count the user hits, because if you place the entire code in a button the code will execute only when the button is click event is fired hence you cannot get the actual user hits for the pages, so I to get the actual user visit counts you have to run the code when the every time when the page gets loaded instead of in a button click, I am not sure how is your requirement, but consider this as my suggestion, let me know more clearer in case if you are looking for any thing.
Since you are unable to open the solution in VS 2005/2008, better you download a fresh copy from source code from http://hitcounter.codeplex.com/ then open visual studio 2005 Start > Programs > Microsoft Visual Studio 2005 then click on Microsoft Visual Studio 2005
Then, click on File > Open > Project/Solution
browse to HitCounter.sln file select and click Open
If I place the webpart on a new “web part page” I get this error
The “HitCounter” Web Part appears to be causing a problem. Value does not fall within the expected range.
It works fine on http://web/subsite/default.aspx
It fails on http://web/subsite/webpartpage.aspx
I have not altered the default.master
I just realized that the failing page was in fact in http://web/subsite/subsite2/webpartpage.aspx so after creating another “Statistics” list in that /subsite/subsite2 it worked fine.
Vijay – I’ve deployed your web part solution and it seems to be working just fine. However, i am looking for something that counts the clicks when a link is clicked. For example, i have an Announcement that has some message followed by a link. I ‘d like to be able to count the hits on that link.
Any suggestion? Thanks for your help in advance.
Thank you so much for this… π
Hi Vijay,
the purpose i’m willing to put the code into the button is :
i can count, how many user will be redirect from my Sharepoint system to another url http page.
and those url http page, wasn’t on sharepoint.
is there any way to check, how much user go from my sharepoint page ?
Hi
Does hit counter web part can be used to count the hits on the document library items ?
Thanks
Mej
hi vijay,can i able to access ur web part in sharepoint 2010. i need to get the number of views per item in asset library of sharepoint 2010. can ur web part help me?
@ Revathy: Since SP2010 requires 64 bit assembly, it is always recommended that to re-compile the WSS/MOSS custom solutions for SP 2010.
Hit counter webpart doesn’t show item visit count, to know about the list/library item count you have to query using SPAuditQuery then you will get the item collection in SPAuditEntryCollection loop through each SPAuditEntry in the SPAuditEntryCollection where you can meet your requirement to know the item view, Good Luck
@Mej: Hit counter webpart doesnβt show item visit count, to know about the list/library item count you have to query using SPAuditQuery then you will get the item collection in SPAuditEntryCollection loop through each SPAuditEntry in the SPAuditEntryCollection where you can meet your requirement to know the item view
@ Raj mehta:To know about the list/library item count you have to query using SPAuditQuery then you will get the item collection in SPAuditEntryCollection loop through each SPAuditEntry in the SPAuditEntryCollection where you can meet your requirement to know the item view
Hi Vijay,
Its a superb code, Thanks.
Is it possible to change the look and feel of this webpart?
Thanks in advance.
@ Rizwan: Yes, you can apply your own styles for change the look and feel.
Vijai – Thanks for your reply. But, i am looking to count hits on a link that points to an audio clip. As i explained previously, that link would be part of an announcement. So, users read it and then click on the link to listen to the audio.
Any thoughts?
Thanks!
Vijay, I have SharePoint 2007 in a BPOS (hosted environment). I am trying to use your webpart but I do not have stsadm. Do you have explicit instructions on how to install it using SP Designer or VS Studio 2007? I have created the custom list “Statistics” and added the three columns. I downloaded the .wsp file but could not do anything with it.
@ Tim Raines: Thanks for looking into the post and showing interest on the Hit Counter WebPart.
A .dwp file is a simple XML file which contains property settings for a single Web Part, we can upload the .dwp if we have, but before we have make sure that the webpart assembly is under site bin directory or installed in GAC, then after necessary safe control entries should be registered in web.config file, so only .dwp file won’t helps for ALL the custom webparts.
Let me know if you need more information.
Could you please help with a step by step procedure on how to add the webpart in sharepoint designer
hi vijay
its good thanks a lot
can u pls create hitcounter which works for anonymous user for publishing websites
@ Yusuf: Open SharePoint in SharePoint designer, open up the appropriate master page from _catalogs click into the code view to select where exactly you want to place the webpart, then go to Insert > SharePoint Controls and click on Webpart… then you can see the WebPart pane on the right side select the Hit Counter webpart and click on Insert Selected WebPart button
Let me know if you need more information, Good Luck π
@ Vijaidev: If you set the permissions to the Statistics list for anonymous users then it is solved.
Hello Sir,
Thank for the reply.
Can u please tell me how to attach survey to paticular document library in sharepoint 2007.
Thanks In Advance.
Thanks for your kind response, i have done exactly what you said it worked, but when i navigate to a different site i get error on the site
Hi vijai kumar
this is koti i have a proublem with no of hits count
in download.aspx page i have a field .i.e.total download,another page downloadspecificpage.aspx there is a button .i.e.click to download .so when user clicks on that click to download button the count will be display in Download.aspx page.please send me the solution
Hi vijay,
please help me
i want no of hits count,in download.aspx page i have a field i.e.Total Download ,in another Page Downloadspecificpage.aspx there is a button i.e. Click to Download,when user click the TITLE in Download.aspx page it navigates to Downloadspecificpage.aspx then he clicks the Click to Download button then the count will be display in the Total Download Field in Download.aspx page
please its very need full for me
Hello Vijai,
Thank you for this free hit counter – this is exactly what I need for my current project. But I’m having an error message when trying to add the hit counter web part (see below) – wondering whether you would be able to suggest me how I can get around this?
“One or more field types are not installed properly. Go to the list settings page to delete these fields” (I’ve posted detailed error message in the Codeplex issue tracker page http://hitcounter.codeplex.com/workitem/19295).
I really appreciate you looking into this. Many thanks in advanced!
@ Koti: I have add the new post on download count of document, please have a look into the post http://www.fivenumber.com/sharepoint-document-counter-counts-the-document-downloads/ and let me know if you require anything else, good luck π
@ BrightSky: Seems that there is some problem with the fields in the list, can you re-create the Statistics list as per the instructed here http://hitcounter.codeplex.com/ and let me know if you need anything else, Good Luck π
@Srishaila: Sorry for the late reponse, I believe this is not the right place to post a question, but I can suggest you to put the same question on MSDN forums
Pre-SharePoint question go here http://social.technet.microsoft.com/Forums/en-US/category/sharepoint
SharePoint 2010 question go here http://social.technet.microsoft.com/Forums/en-US/category/sharepoint2010
Thanks for contacting
Hi Vijai,
Great post,thank you for sharing.
I’m unable to modify your project, and I believe it’s because of my Visual Studio version, which is Premium.
Do you know if this is a problem?
Thanks,
Regards.
Hi vijay,
Can i get this webpart work for anonymous users. My requirment is very specific with anonymous users .
i hav to count the no of times the page is opened by users.
Please help me out.
Regards,
Subha
@ Subha: Yes, you can execute the code with anonymous users too before that you have to put the code in Runwithelevatedprivileges block, let me know if you need more info.
Hi Vijay!
Your Webpart is exactly what Ive been searching for!
I havent been able to get it to work properly in the Masterpage though. Am I to add the list to the masterpage too? I cant seem to figure out how to make that (adding a list to a MP) work…
Hi Vijai,
If we put the web part in the home page, will the subsite statistics be shown in the statistics page? . Also, the “Statistics” list is to be created only in the Home page,right?
Also if the user sign in to the page on different sessions,the count will not be increased,correct me if iam wrong.How can we handle the hit count.I intend to get the traffic in all the pages including subsites.Say the same user may use the page in the morning and at night,which should make a change in the hit count.I used the normal hit count control from sharepoint designer,but it increases the count for even a simple refresh.
Please help me out Vijai.
Thanks
Charles
Thank you for this excellent hit counter solution! However, i encounter this error when I try to add the webpart to the master page: “Unable to add selected web part. A web part or web form control on this page cannot be displayed or imported. The type is not registered as safe.”
What am I missing? Thanks for your help!
Great idea. Wish I could get it to work. We deployed it in our 2007 Moss. All looked good. But when we try to use we get an “unsafe code” error. I install using stsadm addsolution (calling the WPS file from a tmp folder on C). We enabled in Cent Admin for specific application and activated in specific site collection …. still get this Error. Can you please suggest a solution for us. I read that this is an issue wi CAS or something. Our sever is a 64 bit 2003.
Looking forward to getting this working π
Hi VijaiKumar..
Thanks a lot for providing with this free solution. I believe this webpart is exactly what i am looking for, but am unable to make it work.
My portal is on Sharepoint 2010, and the client’s requirements is to view the number of anonymous / logged in users- hits.
I created the Statistics list as mentioned and also deployed the webpart, but am getting the error βOne or more field types are not installed properly. Go to the list settings page to delete these fieldsβ .. Is this due to 2007/2010 incompatibility ??
Can you please provide for this webpart for SP2010 as well ? please please.
Much appreciate your help.
Hi Vijai,
Thanks for all help provided. Please guide me. i need to add visible hit counter on an internal portal of my company. that site is made in sharepoint 2010. i am not able to get my hands on visual studio 2010. is it possible to directly upload HitCounter.wsp in solutions and activate it?? Please help..
What is stsadm? This feature is not available with us as sharepoint server is installed under the admin of our companies IT. My website is under companies workspace.
How to get hit counter webpart in my website weparts meuns without IT help? Is it possitble? Please reply here and to my email also.
Hi,
I had one Query,the wepart we deployed will only gve data from the date deployed,Can we had some create some logic so that we had data for past 30 days.
Thanx In Advance..!!!
Regards
Yatharth
The Hit Counter webpart is not limited for any no. of days, it gives the history and visit count for unlimited days.
Hi,
I dont have much experience in programming. Right now I need a hit counter to internal web site, do you know any solution that only need to run an installer to stay with the web hit counter?
The counter should count each visit each user makes to the page. Right now with your solution appears to me a visit per day. If I switch a other user than the administrator give me error. Users page the vast majority can only have permissions to view.
Thanks, DM.
Thank you Vijai.
Worked very well.