Displaying your Counted Clicks

Wed, Dec 12, 2007

Technology

After reading Mads blog entry on counting clicks on external links I decided to create a web control that would display the information in a nice package.  I also wanted to clean up the process to eliminate having to add the long string of Javascript on each link.  So first I set out to reconfigure the structure and this is what I came up with for the head section:

   1:  <script type="text/javascript">
   2:  <!--
   3:       function trackclick(element)
   4:            { if(element.href.indexOf('redirect.ashx')==-1)
   5:                 element.href='redirect.ashx?url='+element.href }
   6:  // -->
   7:  </script>

Then it’s just a matter of inserting the appropriate onclick="trackclick(this)" for the anchor tags I want to monitor.  For example you could add a tracker for  <a href="http://blog.madskristensen.dk" onclick="trackclick(this)">.NET Slave</a>

Okay, great… Now I need to either connect to ~/redirect.ashx?stats=true to see the results or manually look at the ~/app_code/redirector.xml file.  The problem is that I like to look at this info remotely, and connecting to the redirect.ashx doesn’t integrate with my theme.  So now lets talk about a custom control to display the information…

Being that this was my first control I decided to steal the structure from one of the many controls that are included in Blogengine.net, specifically the tagcloud.cs file.  Using the code from Mads redirect.ashx file I was able to parse out the necessary pieces and re-write the new control file to display the content the way I wanted it to look like.

After getting the control working correctly I added it to my site and gave it a spin. 

   1:  <% if (Page.User.Identity.IsAuthenticated){ %>
   2:    <h2>Click Tracker</h2>
   3:    <blog:RedirectStats ID="RedirectStats" runat="server" />
   4:  <%} %>

imageOops, I have a narrow sidebar, so having the three columns that is the default view wouldn’t work.  So I cut it down to the address and a count.  Now it looks nice and I can see what’s going on with my site from any remote location…

I’m not sure if anyone would be interested in this handy little control but it’s something that you want then feel free to download it!

Comments are closed.

Private