Data Model
For the purposes of the application, we are going to keep the user's details in an SQL Server database, along with the URL and timestamp of every page they visit. Thus we have two database tables:
/* tables for holding the details of each user and their clickstream */
CREATE TABLE [dbo].[tbl_OnlineUsers] (
[IP_Address] [varchar] (15) NOT NULL, /* max is 255.255.255.255 ie 15 chars */
[Session_ID] [varchar] (50) NOT NULL,
[User_Agent] [varchar] (250) NULL,
[Referer] [varchar] (250) NULL, /* yes, it is spelt incorrectly in the HTTP standard */
[TimeStamp] [datetime] NOT NULL
)
GO
CREATE TABLE [dbo].[tbl_OnlineUsers_VisitedURLs] (
[URL] [varchar] (250) NOT NULL, /* we don't keep querystrings for security reasons, so 250 chars should be enough*/
[Session_ID] [varchar] (50) NOT NULL,
[Timestamp] [datetime] NOT NULL
)
And 7 stored procedures to manage them, but I won't describe them here as they are detailed in the DDL file here.