Signup · Login
Stardeveloper.com  
Home · Tutorials · Forums · ASP.NET Newsletter Application · Web Hosting Plans · Faisal Khan's Blog · Contact
Search Stardeveloper.com
Newsletter
Enter your email address to receive full length articles at Stardeveloper:


Article Categories
.NET  .NET
  ASP (16)
  ASP.NET (43)
  ADO (16)
  ADO.NET (11)
  COM (6)
  Web Services (4)
  C# (1)
  VB.NET (3)
  IIS (2)

J2EE  J2EE
  JSP (15)
  Servlets (9)
  Web Services (1)
  EJB (4)
  JDBC (4)
  E-Commerce (1)
  J2ME (1)
  Products (1)
  Applets (1)
  Patterns (1)

Main Category  Other
  Website Maintenance (3)
Log In
UserName Or Email:

Password:

Auto-Login:

Hosted by Securewebs.com
 
Home : .NET : ASP.NET : How to Track Unique Users and Page Views?
 
Read full length articles at Stardeveloper using Twitter Follow on Twitter Facebook Facebook fan page Email Get Articles via Email RSS Get Articles via RSS Feed

How to Track Unique Users and Page Views?

by Faisal Khan.

Introduction
A tracker is an application that tracks website stats like unique users, page views (hits), referrers, popular pages, client browsers, and average time that users spend on a web site etc. This information is used by the webmaster to gauge things like the popular content on his website, and main referrers. He can then work more on the content his website's users like to spend their time on.

This tutorial is the part one of a multipart series of tutorials in which we will learn how to develop such an application using ASP.NET 2.0 (C#) and Microsoft SQL Server 2005. We will start by creating a basic tracker (more like a counter) which will track unique users and page views (hits) on our website. In later tutorials and throughout this series, we will continue to add more features and functionality to our application.

Our application will not require you to have access to IIS log files or any ISAPI extensions/filters. You will just have to insert a piece of client-side HTML code in the pages you want to be tracked. That HTML code will request a transparent image file from one of our ASP.NET page. ASP.NET will send that 1x1 pixel transparent image back to the browser, at the same it will log that request in the memory. Later, from the memory, those requests will be flushed to the database. Simple stuff, but very efficient and very effective.

Before we move on, to give you an idea what the report that our website statistics application will generate will look like, have a look below:

Figure – Sample Report
Figure – Sample Report

Most of the code will be quite simple and only a basic familiarity with C# and ASP.NET 2.0 is required.

A Little Background
At Stardeveloper.com, I have managed to use several counters and trackers from different companies with varying degrees of success. The one that I use now is a called "FastCounter". It's free version is nothing more than a very simple counter which provides just page views (hits) on a daily and weekly basis. This data is kept only for last 2 months after which you cannot access previous months' data.

Seeing the limitations of it, I took it as a challenge and decided to make one of my own for Stardeveloper.com that will provide me with more info than a simple counter and which I should be able to share with other people at Stardeveloper.com. The code has been developed keeping performance in mind, so that even the websites with a million hits per day will not notice any fluctuation in their performance at all.

Creating a Website Statistics Application:- (Multipart Series)

  1. How to Track Unique Users and Page Views?
  2. Tracking Referring Domains and URLs to our Website
  3. Creating Line, Bar, and Area Charts
  4. Tracking and Displaying Real-time Visitor Time Zones in a Chart

Overview of the Application
Our tracker application will consist of a database backend and an ASP.NET front-end. The database backend consists of just a single table with 4 stored procedures as listed below:

  • Tables: SD_Tut_Tracker.
  • Stored Procedures: SD_Tut_IncrementTracker, SD_Tut_GetDailyReport, SD_Tut_GetMonthlyReport, SD_Tut_GetYearlyReport.

The details of them will be described later. The ASP.NET front-end will consist of 2 ASP.NET pages, along with Web.config file and Global.asax files as listed below:

  • ASP.NET pages: track.aspx, report.aspx.
  • Images: trans.gif.
  • Web.config & Global.asax.

Now that we know what our application will consist of, you can already download the complete code and files that I will walk you through this tutorial, from here: 2007040101.zip.

In the zip file is present a file with the name of 'db.sql'. This is a SQL file that we will use to create the required structures (table and stored procedures) in our database.

At the end of this article, we will see the HTML code that is required to be inserted on the web pages you want to be tracked.

Ok, let us not waste any more time and get started on developing the database backend.


 ( 7 Remaining ) Next

Comments/Questions ( Threads: 6, Comments: 22 )
    Contains 1 or more replies by the Author of this Article.
    Contains 1 or more replies by Faisal Khan.

  1. Need help on transparent image tracking
  2. Receiving access denied to app_code
  3. work around for global.asax setting application language to C# ( 2 Replies )
  4. not inserting on database
  5. Trying to get this application to work ( 13 Replies ) This thread contains 5 replies by the Author of this Article. This thread contains 5 replies by Faisal Khan.
  6. VB.net version please ( 1 Reply ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.

Post Comments/Questions

In order to post questions/comments, you must be logged-in. If you are not a member yet, then signup, otherwise login. Once you login then come back to this page and you'll see a form right here which will allow you to post comments/questions.

Please note, one of the benefits of signing up is to be notified immediately by email everytime you receive a reply to the thread you have subscribed.

 
© 1999 - 2010 Stardeveloper.com, All Rights Reserved.