Introduction
Keeping a tap on website statistics is imperative for webmasters. They must know how many users are visiting their website, how do they manage to reach our website, what content they spend most of their time on, etc. We covered a significant part of this introduction in part 1 of this multipart series (Creating a Website Statistics Application – How to Track Unique Users and Page Views?).
Creating a Website Statistics Application:- (Multipart Series)
- How to Track Unique Users and Page Views?
- Tracking Referring Domains and URLs to our Website.
- Creating Line, Bar, and Area Charts
- Tracking and Displaying Real-time Visitor Time Zones in a Chart
In part 1 (
How to Track Unique Users and Page Views?), we created a high performance website counter. It used to track unique users (using cookies) and page views, silently, rather well. But one thing that I some how managed to understand after a few months having written that article is that, the algorithm that I presented in that article for caching request data and then to write all of it in a
single go to the database, was, well, a bit complex for the average user that read that article. That weakness, if you want to call it, will be overcome in this tutorial. We will not cache requests, but will write to the database every time our tracker receives a request. This will lessen the source code and thus the learning curve for the benefit of all the readers.
Note: If you created the table after reading part 1 of this multipart series, then you should know that your data will be kept safe and utilized by the code in this tutorial. The table (SD_Tut_Tracker) that we created in part 1 will continue to hold the data for unique users and page views. We will create two new tables to store some more data, but I will come to it a little bit later.
To give you an idea as to what kind of reports, our sample application will generate, I am posting here 1 of the 3 kinds of reports this application will generate. And just to emphasize the topic of this tutorial, this report is listing the number and names of referring domains:
Website Statistics Tracking Application - Referring Domains Report
Overview
Following topics will be covered in this tutorial:
- Creating the Database Backend:
- Creating the ASP.NET Front-end:
- Constructing the Client-side HTML Tags
- Sample Images and Reports
- Summary
Creating the Database Back-end
Our database backend will consist of a SQL Server (2000 or 2005) database. To store the data of unique users, page views, referring domains and URLs, we will be creating 3 tables. You can create these tables by running the 'db_tables_withTracker.sql' file in the SQL Server Query Analyzer. This file can be found in the zip file that you can download on the last page of this tutorial.
Note: If you have already created a SD_Tut_Tracker table after reading the part 1 of this multipart series of tutorials, then you should instead run the file 'db_tables_withoutTracker.sql' in the Query Analyzer. This SQL script will not create the SD_Tut_Tracker table, rather will use the existing one.
Tip: While, you can create the tables (and stored procedures) using the *.sql files provided in the downloadable zip file of this tutorial; I recommend that you instead create those tables (and stored procedures) manually as will be described step-by-step in this tutorial. This will make you learn a little bit more about why and how those tables (and stored procedures) are created the way they are.
Overview of the Tables
I will assume that you have not created any tables in your SQL Server database, and will thus explain how to create each one of them one-by-one. I will describe all the steps using SQL Server 2000 since it is more prevalent yet than SQL Server 2005. The code will be the same which if you have SQL Server 2005, will work just as nicely.
Creating the Tables
Let's cut all this talk and start creating the tables. Open your SQL Server database where you want to create the tables for your website Tracker, using SQL Server 'Enterprise Manager'. Expand the node of your database and you will see following items listed:
Note: The name of the database that I am using for demonstration is 'Tut'. The database that you will most probably use will have a different name than this one.