I am using MOSS and not WSS. Not sure if it makes a difference.
Download the file here
Overview:
The problem is that the script Nedstats provides has two parts to it. One is the JavaScript aspect and a NoScript aspect. The javascript part would not be a problem and can generate the unique counter for each page but the NoScript part is where the issue lies. It can not build the counter dynamically, so we have to build a webpart the solve our woes.
Solution:
We need the counter to be the same no matter what page we are on for the JavaScript and NoScript part. So we need to build the counter dynamically and we can use the breadcrumb SiteMapNode object used by SharePoint and hook into that. We can than deploy the webpart to SharePoint server and add it to the master page.
Code:
Download the file here
The tricky part is building the counter
private string BuildCounter()
{
var stack = new Stack
sb = new StringBuilder();
var provider = SiteMap.Providers[siteMapProviderString];
if (provider == null)
return string.Empty;
var node = provider.RootNode;
if (node == null)
return string.Empty;
// Stack the nodes, child first
stack.Push(node);
while (node.ParentNode != null)
{
node = node.ParentNode;
stack.Push(node);
}
foreach (SiteMapNode mapNode in stack)
sb.Append(mapNode.Title).Append(".");
var pageName = GetPageName();
sb.Append(pageName);
// Clean any not supported Chars, ect
var cleanCounter = sb.ToString().Replace(" ", "-").Replace("&", "-").ToLower();
//Controls.Add(new LiteralControl(cleanCounter));
return cleanCounter;
}
Implementation:
Copy the DLL to the bin
Make it safe in the web.config
Make the webpart avalible to the website
Open SharePoint designer and then open your website. Open your default.master or custom master page
Locate the PlaceHolderLeftActions placeholder in the master page.
You now need to add the webpart into the master page in-between this placeholder.
This was a tricky one as SharePoint does not allow webpart zones to master pages stipulated here http://msdn.microsoft.com/en-us/library/ms476046.aspx
Example
< id="PlaceHolderLeftActions" runat="server">
< runat="server">
IsIncluded="True"
... / >
< /asp:ContentPlaceHolder >
Don't forget:
Add DLL to GAC or bin
Add the SafeControl into the web.config
Make the webpart avalible to the website
Make sure that the master page has a reference to the webpart (<%@ Register tagprefix="Webpart" namespace="..." %>)
Testing:
To test that it is all working you need to use Firefox.
Download Tamper and install it.
Using Tamper you can then see if your URL is being sent to sitestat with the correct counter name
Small Issue:
It does seem to carry some extra rubish with the URL, but we do not mind that at the moment
Have fun
No comments:
Post a Comment