A while back i found this article over at O’Reilly Radar about the first day of Rails Conf. Since i am a geek and im interested in Scaling web applications (cause you never know…) I started reading the Scribd Scalling Rails Presentation. Its a good presentation, and its not just handy for Rails users. the idea of Fragment Caching is very cool. But, back to the original idea of the post: custom traffic analysis. This is quite a cool idea. In the presentation, they show some code on what the DB should look like. So, i wrote some code, in C# of course, to use this DB and build my own traffic analysis section to a site i am building. here is some of that code:


public Counter(HttpRequest req)
            bl = new BLL();
            string referer = "";
            if (req.UrlReferrer != null)
                referer = req.UrlReferrer.AbsoluteUri;
            bl.PageView(req.Url.AbsoluteUri, req.AnonymousID, req.UserHostAddress, referer, req.UserAgent, DateTime.Now);



The idea is that on each page you want to count, you would use the following code:


Counter</font> c = new Counter(context.Request);</p>


well, not exactly that code. this was used in an ASHX file. normally it would be </p>

Counter</font> c = new Counter(Request);

the bl.pageview method only checks what is being entered. it makes sure anything that is being sent in is not null. then it just chucks it in the DB. the req.AnonymousID is the session ID, or at least i think it is. If I am wrong, which it has been known, please leave a comment. I will update the code accordingly… :)

[updated: using proper coloring for the code!]

[1]: http://11011.net/software/vspaste