 |
 |
Recent
Articles |
Creating Reusable User Controls In ASP.NET In almost every web project of any size, you would probably use a lot of user controls to separate the content and UI logic. Many of the user controls are used only at one place in the solution while others are used by various pages and other user controls. The ones...
ASP.NET: Is It Too Easy? Some time ago, I wrote a post called "Is ASP.NET too difficult?" and I strongly believe that it is.
Yet at the same time it cause problems by making it too easy to do relative advanced programming. It doesn't seem...
ASP.NET: Make GridView Control Accessible The GridView is a new web control in ASP.NET 2.0 and is an improvement of the old DataGrid. One of the biggest issues with the DataGrid was the lack of standard compliance and accessibility. This has been fixed in the new GridView along with a lot of other things as...
ASP.NET - Block IP Addresses From Your Site Recently, one of my readers asked me how to block certain IP addresses from accessing his ASP.NET website. It was a good question that could be answered in multiple correct ways. My answer was a plug 'n...
ASP.NET: Maintain Scroll Position After Postbacks To maintain the scroll position after postbacks is important for larger web pages in order to let the user know exactly what is going on. It is good usability and something you would expect in modern web...
GZip Vs. Deflate - Compression And Performance After I wrote about a HTTP compression module in ASP.NET 2.0 one of my colleagues pointed out that the Deflate compression is faster than GZip.Because the HTTP compression module chooses GZip over Deflate if the browser allows it, I thought that I'd better...
App_Code: Why It's Better I remember when ASP.NET 2.0 beta 1 was released about 2 years ago and I eagerly tried it out. The first thing that struck me as strange was the new application folders like App_Code, App_Data, and App_Themes etc.
|
|
|
03.09.07
ASP.NET: Count Clicks On External Links
By
Mads Kristensen
On a small test website I'm building in my spare time, I wanted a way to count the number of clicks to the outgoing links from that site.
Imaging hosting banners or other affiliate links where you get paid per click, it would be nice to know how many have clicked on them instead of relying on the advertiser's own statistics.
There are third-party products that can do it, but I would like to keep that data myself and it would be fun to build at the same time.
I came up with a very simple solution that uses a generic handler called redirect.ashx.
The handler registers the clicks in an XML file and is also able to print out the stats in a nice looking table.
It works by linking to redirect.ashx?url=http://example.com instead of http://example.com.
To get the stats from the handler, call it with the stats parameter redirect.ashx?stats=true.
That prints out a table with the statistics from each redirected URL.
Crawlers and spiders
To avoid that the clicks made by crawlers and spiders, you can use this simple little trick that filters them out.
By using the onclick event on the link, all clients that don't support JavaScript will just follow the original URL and never hits the redirect.ashx file.
Implementation
Download the redirect.ashx handler below and put it somewhere in your web project. If your website doesn't already have an App_Code folder in the root, then add it. That's all you need to do. The handler automatically adds an XML file in the App_Code folder the first time it is hit and it automatically creates an XML node for every new URL it redirects.
Download
redirect.zip (1,48 KB)
Comments
About the Author: Mads Kristensen currently works as a Senior Developer at Traceworks located in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in 2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and web services in his daily work as well. A true .NET developer with great passion for the simple solution.
http://www.madskristensen.dk/
|