28.05.2011 I have redone this solution to use a star-rating in stead of the simple “like” button. You find the new version here
01.11.2010 Redone the scripts and added support for rating individual items in a list – for example in “Dispform” in a blog:
The solution counts “Hits” and “Likes”.
Create a document library to hold your scripts
Or a folder on the root created in SharePoint Designer). In this example i have made a document library with a relative URL of “/test/English/Blog/Scripts” (a sub site named “test” with a sub site named “English” with a subsite named “Blog” and a document library named “Scripts”).
When you refer the scripts in the CEWP, ensure that you point to the correct location of your scripts.
The jQuery-library is found here. The CEWP code refers to jquery-1.4.2.min. If you download another version, be sure to update the script reference in the CEWP.
The sessvars.js is created by Thomas Frank and can be found here
The sourcecode for the file “HitCounterForSharePoint.js” is found here
Create a list with the name “HitCounter”, and add these fields:
- URL: Multiline plain text
- User: Person or Group
- ReferringURL: Multiline plain text
- Like: Single line of text
You have to give all users write access to the list “HitCounter”.
Add a CEWP where you want this counter to appear, and add this code:
<script type="text/javascript" src="/test/English/Blog/Scripts/jquery-1.4.2.min.js"></script> <script type="text/javascript" src="/test/English/Blog/Scripts/sessvars.js"></script> <script type="text/javascript" src="/test/English/Blog/Scripts/HitCounterForSharePoint.js"></script> <script type="text/javascript"> hitCounter(true,true); </script>
Parameters:
- oncePerSession: True to allow one “hit-count” per unique item per browser session.
- isDispForm: If true, includes the ID of the item to allow individual counting of each item in a list.
Ask if something is unclear!
Regards
Alexander
wish I had half the talent you had. Perfect!
Hi ,After adding files into doc libray and creating list … CEWP showing undefinedHit undefinedLike . How to fix this issue
Hi,
Do you have the list that counts the hits in the same site as you are using it? You will need a small change in the script to have the counter list in for example the root site and then use it in a subsite.
Alexander
Can you please clarify this statement?
Do you have the list that counts the hits in the same site as you are using it? You will need a small change in the script to have the counter list in for example the root site and then use it in a subsite.
The list “HitCounter” that you create to hold the comments: is it in the same site (look under “All site contents”) as the list or page where you have the ratings?
Alexander
Hi;
Thank you for the reply and for your assistance. This is how I have the files organized:
Home site
->Documents (all scripts located here)
->Lists
->HitCounter
I put the CEWP on the Home Page with the following (on the homepage):
Corrections:
Hi;
Thank you for the reply and for your assistance. This is how I have the files organized:
Home site
->Documents->Scripts (folder) (all scripts located here)
->Lists
->HitCounter
I put the CEWP on the Home Page with the following (on the homepage):
Look here on how to post code in comments
I’m not sure what your problem with the code is, but do you get any errors in the developer console (hit F12 > Console)?
Alexander
this was real easy to implement. I made some changes and will try to document. Starting with the fields
» URL: Singleline text – just to start, will make Multipleline later
» User: Person or Group
» ReferringURL: Singleline text – just to start, will make Multipleline later
» Page: Calculated Field = to URL
once this field is created Change URL to Multipleline. The reason for this is a calculated field will not read multipleline field by default. This method tricks SP into reading it. This also give us the ability to group by Page
» Day: calculated field =TEXT(WEEKDAY([Modified],”ddd”)) this allows me to start seeing trends by day of the week.
with this configuration I can now create a group view by Page, then User. With this I implemented your script for counting groups here:
https://spjsblog.com/2009/11/25/count-groups-in-grouped-list-view/
of course there are many different techniques this script was very helpful becaue of the data is supplied and setting up the views
The formula for the “Day” field should be =TEXT(WEEKDAY([Modified]),”ddd”) to call the WEEKDAY function correctly.
I need it to count ‘hits’ and not groups or anything alse. I can not give anyone ‘write’ access because I work in a military hospital. Any suggestions?
Thanks
Hi,
Are your visitors anonymous or do they have to sign in? If they are anonymous, do they have restricted read access?
If you want to count hits (without using the built-in Site usage report) the visitor must have write access to the counter.
You may use some server side code to do this with elevated privileges, but there i cannot help you.
Alexander
Hi Alex,
Is there by any chance this to be used to let you know how many users are online at the moment on a particular page? Like who’s or how many people are online on this page at the moment or to be checked on an interval of time?
That is not possible, sorry.
Alexander
Hey I was wondering why in the “Title” part of my “HitCounter” list, it just displays “Site:” and not the actual title of the page ?
Any help would be great, thanks Alex!
– Alex F
Hi,
The script pulls the title from
This is the title of the site displayed in the “title area”. Is the page with the counter script attached to a master page?
Alexander
No it’s a document library, I haven’t added any code to the mastr page.
No need to put anything in the master page. I just wanted to know if the page was a standard SharePoint page.
Does your page have a title? – it’s not just a logo? – check it under “Site settings” > “Title, Description, and Icon”.
Alexander
Yes, the document library does have a title. is it possible it’s because I’ve added this to the document library folder?
It’s not the document library title, but the site title.
To use the Document library title, use this:
Alexander
Still didn’t work…. Any other suggestions? Want me to paste the partial code here?
Try to alert
What do the alert say?
Do you require the site title or the document library title? – the URL is recorded in the “URL” column….
Are all the other values there?
Alexander
It just showed a popup box with “ms-pagetitle a”
Like this:
Alexander
Hi Alex,
I misled you a bit here, to get the list or library title:
There is no “a” in the pagetitle.
Alexander
Also how can I add the date? Thanks!
You have the date in the column “Created”.
Alexander
Hi Alex,
I am new to Shartepoint. Please help me to create a webpart which has
•The ability to historically track number of users (visitors) on a site prior to and after the current month
•The ability to historically track number of users (visitors) on a library prior to and after the current month
•The ability to historically track number of users (visitors) on a list prior to and after the current month
i tried the above example and nothing is showing in the CEW. Do i need to do any other settings (like publish,etc..)
Thanks,
Satheesh
Hi,
I think you should look at the built in “Site usage report” in SharePoint.
Alexander
Is there a way to only show the visits from one person on a day, for some reason its showing the same user twice if the user refreshes the page?
The code is updated, please read trough the post as it is modified and requires another script referred.
Alexander
Hi, i implement yourt solution, but ia cant get any data.
List hitcounter is empty..
Hi,
Do you receive any errors?
Look at this to get started with the troubleshooting How to troubleshoot when the scripts does not work
Alexander
hi, i solved that.
turns out i my interaction.js and stringBuffer.js was corupted.
I think if it was available in your site my life will be longer about 2 hours 🙂
PS. My eng is bad..
I have one more question.
With this code additem() function adds items only in the list in this site.
Is it posible what to add items in the same list from other site/site collection?
I must be missing something. I updated all the paths to point to my script library and I have all the scripts in there, but my CEWP is blank. Is there someplace that I’m supposed to point to my hit counter list? I know I must be overlooking something obvious.
Hi,
As long as your list is named “HitCounter” and is in the same site all is OK.
Please ensure that the scripts are not corrupted.
How to troubleshoot when the scripts does not work
Alexander
Fantastic work Alex. Thanks a bunch!
I was about to respond a few minutes ago that I couldn’t get this to work but it now works and I think it is FANTASTIC! Alex, thanks for making this available for free.
Just to help others who might run into the same problem as I did – make sure you download the right script from the links above.
Alex, thanks once again.
First of all, thanks for this fantastic tool. It’s very useful, works very good and I easily personalized it to extract data I need to populate my HitCounter list.
I would like to ask to you what do you think about scalability: what, for example, if 200 users try to access to a page in the same time?
Hi,
This would be equivalent to 200 user submitting a new item to a list using NewForm.aspx. I do not think this would be a problem, but i have not “stress tested” it.
Alexander
Hi Alexander,
*sigh* I can’t get this to work. I’ve updated the paths, checked with alert, the function is called, though nothing is written to the HitCounter List. “Public” has r/w access to the list and it’s on the same site. Can you think of anything else that might be wrong? I even re-downloaded the other three .js files from their orginial location, nothing changed though.
Chris
Hi,
Hard to tell… Have you tested it in another location/page?
Double check that you use the right DisplayName for the “HitCounter” list as it is addressed using the DisplayName.
Alexander
Hi Alex,
Is it possible to use this counter in a site where CKS EBE (Community Kit for Sharepoint Enchanced Blog Edition) is enabled as a site feature. I’ve tried messing with the theme.master file found in one of the themes folder but to no avail.
Hi,
I do not know the CKS EBE and cannot tell for sure, but i cannot think of any reasons why it shouldn’t?
Alexander
Hi this article helped me a lot .. Thanks for that.
I implemented your code and worked fine and i like to ask couple of questions regarding that..
1)Can we have like “Update Item” also so we no need to store when each time the user hit the page .?
Here is my scenario.. I have blog and i am sure everyday at least 100 users will hit article pages.. If we store the way we are storing now that’s going to be huge data on “Hit Counter” list.. is that the right scenario? is there anything we can update the current values to increment?
Hi,
To achieve this you would have to write a logic that overcomes the possible version conflict if multiple users write to the same object at the same time.
It is not supported at the moment, but i do not think this will be a problem. Your “counter list” can hold 5 million items…
Alexander
Hello,
This article is really useful! But I have a problem with the implementation: it works fine for an authenticated user but for an anonymous user the function returns -1 hits… Can you help me on that?
Bianca
Hi, You must allow for anonymous access/contribution to the “counter list”.
Alexander
I did that… I gave anonymous full control on the counter list… As I was saying… It works fine for an authenticated user but not for anonymous… I’ve tryed to access the list from the browser with anonymous and I managed to add a new item to it… any other ideas?
Thanks,
Bianca
Hi,
I’m not so familiar with anonymous access, but you might get it working if you remove the “setRequestHeader” in the ajax query. You find this in the function “innerPost” in interaction.js. Copy this function into your code and modify it by commenting out the line
Alexander
Thank you very much! That was the problem for anonymous users:).
hi,
How to solved anonymous users problem?
thanks.
hamidreza
I don’t think this is not possible with this solution.
Alexander
I don’t think this is not possible with this solution.
Alexander
Hi all,
The code is updated.
Alexander
Thanks Alexander,
Just tried the updated Hits & Like feature for Blog Posts, perfect, works great!
Server-side web-part installs? Who needs ’em eh 😉
I bask in your awesomeness.
Much appreciated, Brett.
Glad you liked it!
Alexander
I have used Gostats.com Hit counters on many of my sites and blogs and it offers comprehensive and real time tracking.I also want to try this for my new blog.Is it require to give write access to all users to count all hits.
The code is working fine for adding records to the HitCounter list. However, I’m getting a -1 hits and -1 likes. My other sites are fine, but my main site isn’t working properly. Again, the list is being updated, just not displaying the counts.
Much appreciated.
Jim
I am getting this as well, has anyone found a solution?
Thanks,
Dave
Try using jquery-1.6.2.min.js
Hope it works
Hi Alexander,
I’ve got your Hit Counter working great on my Blog Site, Loving it.
Are you able to add this “Most Viewed” feature for this Hit Counter?
http://community.zevenseas.com/Blogs/Daniel/Lists/Posts/Post.aspx?ID=103
It shows each blog post Title and the Count next to it.
This would go well as a Web Part on the front page.
Thanks,
Brett
Hi,
The hit counter stores each “hit” or “like” in a separate line in the “hit counter list”. To retrieve this you would have to write a script to pull them in and count the hits and likes on the individual items. This might take a few seconds, but is no big deal.
The problem is that as the script is setup right now, it does not store the “title” for each record – only the URL. To have the “Most viewed” display in a proper manner, you would have to do another query against the list where the hits are being registered to fetch the title.
Again not hard to do, but adds a few seconds to the page render (depending on the number of line in the counter list).
Alexander
Thanks for the sharing !!
I have implemented, but hit is showing always 0 and like it button show 1 when I hit on it, but if I refresh it becomes 0 again. I can see everything in the list. Any idea ?
Hi,
Does the “hits” show up in the “HitCounter-list”? What kind of browser do you use?
Alexander
thanks, great work, Right now this thing work for browser session, I want to use for per user, so if user have visited the site once, it won’t take hit or like again. Thank for awesome file.
Does the newest version include the change described in your October 30, 2010 post that made anonymous users work correctly?
Pop
The changes are there, but as i wrote then – i have not tested it with anonymous users myself.
Alexander
Tested anonymous access with the v1.5 01.11.2010 code as downloaded. It makes the page request a Sign In (using CAC in our case). Since the anonymous user doesn’t have an account in our AD domain they can’t Sign In to view the page.
Tried changing function spjs_wrapSoapRequest to comment out this statement…
xhr.setRequestHeader(‘SOAPAction’,requestHeader);
That caused an Alert box with the text “Null” on each page refresh.
My testing of anonymous access was flawed. The Contact Details web part (with presence) was causing the anonymous access for the page to fail. After removing it, the v1.5 01.11.2010 code as downloaded allowed anonymous access.
There is no hit item added to the HitCounter list for an anonymous user, and there is no error generated back to the user. I suspect this is caused by the list access permissions. The “add item” check box appears in the anonymous access options, but only “view item” will remained checked after the selection is saved.
I’m thinking about a modification to use a single HitCounter list for all the data collected in my site collection. I’ve got about 500 individual sites, but less than 50 pages would actually have hit counters. The usage is low. Only about 500 unique users per day and 10,000 requests on a busy day.
Any thoughts on what problems I migh have?
I do not know for sure, it depends on the amount of hits.
This being a client side code, the Ajax request has to pull down the xml and parse it locally. It you get thousands of hits on each “page” the data that has to be downloaded to the client can be as much as a few MB.
I did a quick test querying a list with 8000 items and it resulted in an”xml-blob” approximately 3 MB.
Alexander
I hadn’t thought about the size of the blob coming back. That might be “hidden” network traffic that we don’t want. It would be large compared to the page transfer size.
We’re only getting about 300 hits logged per day for the 5 pages that interest me. That’ll increase if I open the capability to all my site managers. Probably never top 1k hits logged per day, but we’d get to a large blob in a few weeks with a central list. We’ve got a Gb network, but it’s still a lot of extra traffic added to peak periods.
Isn’t there a way to do a query that only returns the count?
I added this script to a few pages when A first posted it. My SP admin was not happy for multiple reasons. 1. this will continually add hit in the list and we have no way of knowing how many. 2, currently there is no way to automatically archive this data. This this becomes a manual effort. 3. it could reduce performace depending on the usage the hit counter takes.
Now I still have it implemented and only use it on a few pages. Also I only keep about 90 days od data (1 quarter) but this again is a manual effort to delete the old data.
This is a great script and the concept is awesome. I dont want to take anything away from A’s work. Just some input from someone currently using the script.
Hi Alex,
This is a wonderful post. but i am facing the same issue as ‘wakeup009’ .
I have created list with columns as u mentioned. and the hits showing up in hitcounter list. but when i open the page it is not rendering the count from list. i use IE8. please help.
Hi,
Do you get any errors?
Is the site on a managed path?
Is it SP2007 or 2010?
What rights do you have to the site (read, contribute or owner)
If you answer these questions, i might be able to help you further.
Alexander
1) no errors.
2) yes the site is on managed path
3) SP 2010
4) i have site collection admin access
Does the record in the list “HitCounter” show the exact relative URL of the page where the counter is located (In the “URL” field)?
Alexander
Awesome work; however, I’m getting the same error as naveen. Here are my answers to A’s question:
1) no errors
2) yes the site is on a managed path
3) SP 2003, IE6
4) Full Control
Also, the RelativeURL is not always populating in the hit counter list…it is there for maybe 10% of the entries!
It’s still great to have the HitCounter List by itself, though 🙂
The solution is very simple, just make sure you create the column as a plain text, (URL & ReferringURL) and if you create the rich text then you will get always 0 when you refresh the page.
Love it! Nice job and post. thanks for sharing.
Very nice solution. We probably going to implement this on our intranet (though slightly different: no usernames and no “I like it”).
But this is a very good starting point.
Do you leave the Title column as is, or do you remove it?
The title column is untouched.
Alexander
Hi Alexander,
I implemented your code and all I am getting is -1 hits and -1 likes
I am not getting what should be needed.
I want this counter to work for anonymous User.
Any Help?
Thanks & Regards,
Alekhya.
Hi,
Anonymous users is a bit tricky as they would have to have write access to the hit counter list. It was originally thought to work with anonymous users, but the appropriate rights has to be added.
The -1 hits could be the hit counter list name not being exactly right, or the list is not in the current site.
Alexander
I have a question in reference to links on a site. I would like to know if it is possible to ‘track’ the link usage. We are a military hospital and using MOSS for our Intranet, I would like to see how often the links are access.
Hi,
You could do this by adding a counter to the “target” of the link and then look at the hit counter list for “ReferringURL”.
Alexander
Is there anyway to get this to work across a site collection, so I don’t have to have a list on each site?
Hi,
You would have to add some parameters to the script. I will incorporate this in the next release – i have started to look at the star rating in stead of the “like-button”.
Alexander
Hi All, I’ve got a useful tip that can be used with the Hit-Counter using Filtered Views.
You can create a web part on your main page for an enhanced Greetings “User” message and Your Last Visit Was: “date”.
– Create a View from within the HitCounter list.
– Select User and Created check box.
-Sort by: Created (Descending Order)
– Show items only when the following is true: Column “User” Is Equal To [Me]
and
Column “Created” Is Less Than [Today]
– Limit the total number of items returned to the specified amount. = 1
– Hide the Hit-Counter on your Default.aspx page.
So now using some DataView Webpart skills or some basic Rich Text Editor skills, you can display the Greetings “Current User” and/or Your Last Visit Was: “Date”.
I’ve also been toying with a Visitors Log, which displays a web part list of Users to that page’s URL.
– Show items when True: URL contains “Page URL”,
– Group by “Created”.
Webpart displays column “User” Grouped by Date.
Anyone else have examples of how this List can be used?
Generally, if you have a -1 your list was created incorrectly with a wrong data type. Recreate the HitCounter list with PlainText fields (not RTF)
Hi Alexander,
this is a great work! Thanks. Works perfectlly. I would love to use your solution but I would like to modify it in this way: each page has only one item in hitCounter list with a counter field, which is incremented every time the page is open. Could you please give me an advice what do I have to change and how to achive this? Maybe some code snippet? Thanks.
Lukas
Hi,
Sorry, this question never got my attention…
Unfortunately this cannot be done in a good way as multiple users would want to write to that same file at the same time. If we did this, we would possibly loose some hits due to simultaneously updates.
Alexander
Hi Alex,
i have a share point site where in i have lot of word documents in it( all present in a list). many people have rights to access to that documents. what i want is if people updates or alters any of the word documents then immediately that should be updated in the home page like ” so and so document is been updated by “x” at time….. can u help me in doing this …….
Hi,
Please post this one in the Requests post and i will see if i can find the time to make a solution.
Alexander
i already tried in my website http://www.jsurgacad.ukm.my, in few pc everthing is ok but few other pc i face the problem , i geeting the debug interface
Hi,
I need some more information to be able to help. Have you tried the new version linked in the top of the article?
Alexander
hey,
is there any way to connect the “like” with the like-metadata-functionality in sharepoint 2010??
if not – would you mind publishing a hitcounter without the like-functionality? would be awesome.
greetings.
Hi,
Not that i know of, sorry.
Follow the link in the top of the article to find a solution without the like functionality,
Alexander
Hey Alexander,
Can I use the script to get hit count of blog posts created in different site collection/ web application?
Hi,
This will work within the site collection only.
Alexander
Hello,
When I click on the link to download the source (The sourcecode for the file “HitCounterForSharePoint.js” is found here
), I get an error. Is it still available?
The link is updated. I had a redirect from my old server, but now i have fixed the link in the article.
Alexander
hi all do you have online user counter with javascript?
No,
Alexander
Hi!
I followed instructions. But I get undefined Hit and undefined Like in my CEWP even if i click Like.
If I go in my HitCounter list, it shows that my page has 1 like.
Do you know why it is not reflected on my page?
Thanks 🙂
-Daniel
Hi,
Could you post the content of the “URL” field in the record from the list where the hits and likes are stored? – you can strip away the domain name if you like, but the list path and name must be accurate.
Alexander
Try using jquery-1.6.2.min.js
This change worked for me
Hi Alexander, just wanted to let you know I just implemented the Hit and Like Counter on our intranet (SP2007 MOSS) and it works great. Think I’m becoming some kind of “Alexander groupie”, since I have used a couple more of your script to enhance our article pages :D. Thanks for all the great work!
Claudia
(ps If you like a screenshot of our article pages with your scripts, just let me know)
i added this to my site, it doesnt appear when i’m not looged in otherwise works very well
what could be the problem? any help is much appreciated
Hi,
This one will not work with anonymous access.
Alexander
ok
and thanks for the quick reply
hey alex thanks this hit counter is great! but why am I getting undefined likes and hits? help very much appreciated
btw im using SP2010 and im an owner. hope this info helps
url field in the HitCounter list displays /sites/hr2/default.aspx?ID=undefined
its working now! turns out i just have to use 1.4.2 instead of 1.7.2
Can i make it user dependent rather than session dependent so that same user cannot like again
This was working very well until we switched to MOSS2010, now I get an error message saying “One or more field types are not installed properly. Go to the list settings to delete thse fields.” HELP!!!!
Hi May i know how to find the source
Hi Alex,
I’m need to add the page counter to a sharepoint List for reporting purpose, please help!
Hi Alex,
Firstly i would like to thank you for this solution. it works extremely well.
i would just like to know what do I need to modify in the code have only the hits and not the like?
I tried removing the Like column in the hitCounter List but that just made the hit and like set to -1.
Please help.
Hi Alex – This code is amazing! Great work!
I ran into a problem with logging the hits. It would log the hits only once per user and I can’t get it to log all hits.
I have set the oncePerSession value to false but no luck.
I have tried using the new updated version with the rating stars and set the counters true to log every session but still no luck.
Can you assist/ give me some insight as to what I might be doing wrong?
–thank you!
Hi,
I did a quick test and reloading the page registers a new hit in my setup.
Ensure you do not have quotes around the arguments
Alexander
Hi
I am a novice with js and just want to use the ‘like’ function. I have set everything up as described but dont know how to trigger the javascript from a text link to put an entry into the hitcounter list.
Can you help? Im using sp designer 2007 and WSS3
Hi I’m still not getting this to work. List is getting updated but i’m getting /TestSite/default.aspx?ID=undefined and also getting -1 Hit and -1 Like. I have created a list with same HitCounter name and all the js file have been copied and path is correct. Please sort this one out. I’ll be thankful to you.
Regards,
Anki
Hello,
Can this solution be used for knowing number of views on the sharepoint discussion board?
Thanks
Hi Alexander,
Awesome solution as always! But I have a question.What if I want to save the querystring along with the url?
Sorry for the trouble. I should have tried before asking you. I got the resolve. I replaced location.pathname to location.href
Hi Alexander Bautz,
I have followed the instruction and I am getting undefinedHit undefinedLike in my CEWP.. how to fix this issue.. If possible I wnat to display only total hit count in numbers can it is possible , if Yes then how we can do?
Hi,
Sorry for the late reply. This solution requires the configuration list to be created in the same site as you want to use it – could this be the issue?
Also, there is a newer version linked in the top of the article.
Alexander
Hi Alex,
I have a question. What if I want USER ID instead of USER Name?
Hi,
I’m not sure I understand what you mean. The “user” is stored in the configuration list in a people picker field. If you want the user ID you can set this field to show the ID.
You can also change the field type for the “User” field in the configuration list to “Single line of text” to have the ID only.
Alexander
I also have the ‘undefined hit’ ‘undefined like’ – my scripts library (with scripts) and the hitcounter list are both within the blog site. Double checked the links which are fine. Using more up to date jquery but the reference is correct.
The list is recording the hits and likes, just not displaying the figures in the buttons.
Any help greatly appreciated!
I sussed it – went back to the original jquery 1.4.2. and it works fine now. Awesome work again Alex.
I’m glad you figured it out. There are some compatibility issues with newer versions of jQuery, and unfortunately I don’t have time to update all of the solutions.
Alexander
Hi,
Greate post! but how can i do so that each person can “like” only one time. My sharepoint site user AD authen.
Thanks!
Hi,
I don’t think this is possible, you should look at the updater version linked in the top of the article as this has this option.
Alexander
The counter is great and I see all the data in the HitCounter list but the counter on the page is always 0 even thought there are hits logged in the list. Any thoughts? Thanks!
Hi,
This solution has gotten a bit old, and it might very well be that you must use an older version of jQuery for it to work.
Have you checked out the updated version linked in the top of the page?
Alexander
Hello;
One more request for help…I am getting the following error:
“One or more field types are not installed properly. Go to the list settings page to delete these fields.” I’ve gone over all the info. however am getting the above error as well as -1Hit -1 Votes . This one has stumped me…Any help is much appreciated.
Fields I am using are:
•URL: Multiline plain text
•User: Person or Group
•ReferringURL: Multiline plain text
•Like: Single line of text
With the CEWP code as:
-1Hit
-1 Votes
var argObj = {counterListName:’HitCounter’,
counterListBaseUrl:”/sites/WME_WoW_Focus_Team”,
countHits:true,
hitCounterVisible:true,
countOneHitPerUser:false,
countOneHitPerUserPerDay:false,
hitSuffix:[‘Hit’,’Hits’],
isDispForm:true,
activateRating:true,
starImageSrc:[‘/sites/WME_WoW_Focus_Team/Documents/Scripts/star_off.gif’,
‘/sites/WME_WoW_Focus_Team/Documents/Scripts/star_on.gif’,
‘/sites/WME_WoW_Focus_Team/Documents/Scripts/star_selected.gif’],
starCount:5,
starMouseoverArr:[‘Very poor’,’Poor’,’Good’,’Very good’,’Fantastic’],
oneRatingPerUser:false,
ratingCountSuffix:[‘Vote’,’Votes’],
alreadyRatedMouseover:”You have already given this item {starCount} stars!”,
debug:false};
hitCounter(argObj);
Hi,
The message tells that one of the fields does not exist. Please note that it is the “FieldInternalName” that is used, and not the DisplayName.
Alexander
Hello;
I wanted to let you know, I finally was able to get this to work…now that it is, thank you for the scripts 🙂 I had a few missing fields in my custom list….
Thanks,
Michele
I’m glad you figured it out.
Have a nice weekend,
Alexander
HI,
It seems that I am having issues with my parameters:
hitCounter(true,true)
var argObj = {
isDispForm:true,
oncePerSession:true,
nothing is displaying on my page when loading and there is nothing in the console log.
any help would be great
Hi,
I’m not sure if this is the issue, but you are not supposed to have these lines in the code:
The object is not formatted correctly and can cause an error.
Hope this helps,
Alexander
Hi,
Not sure if you are still supporting this. I’m not having any errors with the code but my counter is just 0. “0 hit 0 like” I have checked the HitCounter list and there are records in the list but it isn’t reflected in the counter displaying. Any suggestions?
Hi,
I have not updated this one for a while and it may be down to an issue with the jQuery version – try with jQuery v1.6.4 and see if this helps.
Alexander
Hi Alexander,
I changed the jQuery version to 1.6.4 as suggested but it is still returning 0. I have looked through the code and debugged the issue down to this line.
var hitCount = spjs_QueryItemCount({listName:’HitCounter’,query:hQuery}).count;
This is setting hitCount to 0. I’m unsure if there is an error with this line or if the hQuery is just returning 0.
The hQuery is
var hQuery = “<Where><And><Eq><FieldRef Name=’URL’ /><Value Type=’Text’>”+urlDir+”</Value></Eq><IsNull><FieldRef Name=’Like’ /></IsNull></And></Where>”;
I’m really unsure of what most of this means but if you could provide any context to fix this or information to learn how to write my own query it would be appreciated.
Hi,
I’m not sure as I have not tested this version lately, but I see from my code example in the article that I used jQuery v1.4.2 and not v1.6.4 – can you test this version to see if this may be down to a change in jQuery?
You can also use the Network tab in the developer console (hit F12 > Network) to inspect the query and see if you see any errors there.
To look at the result of the query from your code snippet above, you can change it like this – you must have the developer console open (hit F12 > Console):
Alexander
Hi, your work is fantastic!!!
But i would like to have also a comment field beneath the stars that should also be connected to the same sharepoint list and the same ID like the stars…
Do you have any solutions or any ideas how i can achieve this?
Thanks in advance
I found your post for a commentBox for MOSS 2007…
Is it possible to combine both the commentBox and the star-rating in one sharepoint-list?
You should be able to do this, but ensure you do NOT load the jQuery plugin more than one time.
Alexander
ok thank you.
i will try to combine both scripts…
Hi,
I added the code in a webpart page located in one of my document library’s subfolder.
However, it only shows the Hits as -1 and the Likes also as -1.
Nothing happens if I click the Like button, as well as the HitCounter list does not track the hits for the page.
It only tracks the hits of the main page.
Is there anything I am doing wrong?
Have you read trough the comments? – This issue has been up multiple times – see if you find a solution there.
Alexander
I have added this into a page layout, it works as expected on a top level site however on subsites it does not count the hits or store the likes.
I have tried re creating the list in the subsite as well
any ideas
Unfortunately I have not had the time to keep this solution up to date – it’s nearly 5 years since I last reviewed it.
As this solution does not have a “baseUrl” property in the code interacting with the lists, I would guess this solution should work if you added the counter list to the subsite.
Do you see any errors in the developer console (hit F12 > Console)?
Alexander
Hi Alexander,
thanks for your response. I have tried adding in the counter List to the subsides and it is storing counts and likes.
however on the page it is displaying a 0 hits and 0 likes
there are no errors in the developer console
Hi!
It seems that users can register as many Likes as they wish. Once visiting the page, a user can only register ONE like. But the next time the user visits the page, he/she can register a new Like. Even a refresh of the page makes it possible to register more Likes.
Hi,
It has been almost five years since I did any work on this solution, but from the configuration options it looks like you can only limit the likes within one session (browser window).
You might have better luck with the the slightly newer solution linked in the top of this page.
Alexander
OK – thx for your reply.
I know it’s been almost 5 years since you’ve worked on this code, but we upgraded our servers to 2015, and now the User name is blank, so that it now counts EVERY time someone goes to a site instead of once a day. Any suggestions?
Hi,
Sorry for the delay. This should be an easy fix. Open the “HitCounterForSharePoint.js” file and replace this:
with this
Alexander
That worked BEAUTIFULLY!!!!!! Thank you SO much! I bought you a beer my coding brother!!!!!!
I’m glad it worked – and thank you for the beer!
Alexander