Thursday 3 November 2011

Hit counter for SharePoint

 
 
 
 
 


01.11.2010 Redone the scripts and added support for rating individual items in a list – for example in “Dispform” in a blog:
IMG 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:
1<script type="text/javascript" src="/test/English/Blog/Scripts/jquery-1.4.2.min.js"></script>
2<script type="text/javascript" src="/test/English/Blog/Scripts/sessvars.js"></script>
3<script type="text/javascript" src="/test/English/Blog/Scripts/HitCounterForSharePoint.js"></script>
4<script type="text/javascript">
5    hitCounter(true,true);
6</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

For more info http://sharepointjavascript.wordpress.com/2010/02/18/hit-counter-for-sharepoint/

No comments:

Post a Comment