Silver Arrow Systems

DWP: Page Hits Logger

Drop this web part on any page, and it will log all visits into a list, along with the username of the visitor. Just set up the URL and User columns, and look at the Created column to see when the visit was logged. Multiple instances of this web part can be pointed at either the same list or different ones, allowing for flexible organization and aggregation.
SharePoint 2007 and 2013 support coming soon.
<?xml version="1.0" encoding="utf-8"?>
<WebPart xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/WebPart/v2">
<Title>Page hits logger</Title>
<FrameType>None</FrameType>
<Description>Tracks visits to a page and stores them in a list with the visitor's username.</Description>
<IsIncluded>true</IsIncluded>
<ZoneID>Left</ZoneID>
<PartOrder>0</PartOrder>
<FrameState>Normal</FrameState>
<Height />
<Width />
<AllowRemove>true</AllowRemove>
<AllowZoneChange>true</AllowZoneChange>
<AllowMinimize>true</AllowMinimize>
<AllowConnect>true</AllowConnect>
<AllowEdit>true</AllowEdit>
<AllowHide>true</AllowHide>
<IsVisible>true</IsVisible>
<DetailLink />
<HelpLink />
<HelpMode>Modeless</HelpMode>
<Dir>Default</Dir>
<PartImageSmall />
<MissingAssembly>Cannot import this Web Part.</MissingAssembly>
<PartImageLarge>/_layouts/images/mscontl.gif</PartImageLarge>
<IsIncludedFilter />
<Assembly>Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
<TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>
<ContentLink xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
<Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor"><![CDATA[<script>
var listname = "PageHits",
urlcol = "URL",
usercol = "User";

function getCurrentUserFct(d){var b=new SP.ClientContext.get_current();var a=b.get_web();b.load(a);var c=a.get_currentUser();c.retrieve();b.executeQueryAsync(function(){if(d){d(c.get_loginName())}},function(e){console.error("Page hits web part current user request failed. The error was:\n"+args.get_message()+"\nThe stack trace (if any) was:\n"+args.get_stackTrace())})}function insertListFct(d,c,g){var b=new SP.ClientContext.get_current(),f=b.get_web().get_lists().getByTitle(d),e=new SP.ListItemCreationInformation();this.oListItem=f.addItem(e);for(var a=0;a<c.length;a++){oListItem.set_item(c[a][0],c[a][1])}oListItem.update();b.load(oListItem);b.executeQueryAsync(Function.createDelegate(this,function(){if(g){g()}}),Function.createDelegate(this,function(i,h){console.error("Page hits web part list insertion failed. The error was:\n"+h.get_message()+"\nThe stack trace (if any) was:\n"+h.get_stackTrace())}))}function pageHitFct(){getCurrentUserFct(function(a){insertListFct(listname,[[urlcol,document.URL],[usercol,a]])})}setTimeout(function(){SP.SOD.executeOrDelayUntilScriptLoaded(function(){pageHitFct()},"SP.js")},1);
</script>

<!-- Page Hits Logger Web Part v1.2.0 -->
<!-- All code copyright © 2013 Silver Arrow Systems. All rights reserved. -->
<!-- Usage and redistribution of this web part is restricted to individuals with permission expressly granted by Silver Arrow Systems (hereafter referred to as Licensed Users). -->
<!-- Licensed Users may use, modify, and redistribute this web part without any restrictions. -->
<!-- Individuals without permission expressly granted by Silver Arrow Systems (hereafter referred to as Unlicensed Users) may use and redistribute, but not modify this web part. -->
<!-- Unlicensed Users must keep this copyright notice intact in all usages or redistributions of this web part. -->
<!-- No user may hold Silver Arrow Systems responsible for any damages incurred by or because of this web part, its contents, or its usage. -->
<!-- http://www.silverarrowsystems.com -->]]></Content>
<PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
</WebPart>
How to use this web part:
Setup:
- Create a list with two columns for the URL and username.
Install options:
- Copy and paste this code, then save as a .dwp file (file will use default options).
- Download as a .dwp file (file will use default options).
- NEW! Use our custom DWP builder to set all your own options.
Don't know how to install a DWP?
Check out our tutorial for SharePoint 2010 (SharePoint 2007 and 2013 tutorials coming soon.)
X

Silver Arrow Systems Custom DWP Builder

Step 1: Set your options. All fields are required unless otherwise noted.

Step 2: Click the button.

Generate custom DWP
All fields are required unless otherwise noted.

Step 3: Copy and paste this text, then save as a .dwp file.