WebStats 2.0
============

WebStats is brought to you by WebTest Server (www.dyessindustries.com/webtest)


RELEASE NOTES
=============

WebStats 2.0 is a group of scripts that make use of IIS's global.asa file
as well as a stand alone reporting screen to give users real time information
on the activity of your web site. Some useful statistics include session peaks
and peak times; sessions per hour, minute and second; and session forecasting
based on your current sessions per second ratio which is calculated every
time WebStats 2.0 is refreshed.

With the comming of WebStats 2.0, an external session log page is introduced
that is accessable by clicking "View Session Log" on the main WebStats 2.0 page.
A new window will open (using JavaScript) displaying all the sessions made to 
your server since the server was restarted.

WebStats also has two convenient selection bars: Statistical Refresh Rate and 
Session Timeout. The statistical refresh rate selection bar allows the user
to set of often the statistics are recomputed and displayed. Default is 5 seconds.
The session timeout selection bar allows the user to change the timeout for any
given session. The greater the timeout, the longer IIS keeps an inactive user's
session active. Usually a longer session timeout will result in WebStats 2.0 to
report higher peak times.

All statistical information WebStats 2.0 is stored in memory, which means that
whenever the IIS or the WWW service is restarted, or your global.asa file has
been modified, your statistics will reset to 0. In later versions, the user
will have the option to store their data in a database; although this is not
recommended due to the system overhead required to write a record at the start
of each session.

WebStats 2.0 makes heavy use of Session_OnStart event in the global.asa file. 
Creating Session variables in this area of the global.asa can waste memory
because memory for the variables have to be allocated for each session. WebStats 2.0
doesn't create any Session variables, but modified application variables, which
are only stored once for the entire web site. 

The storage of information in memory as well as the use of application variables as
opposed to session variables results in a very efficient statistical engine that
requires only a minute amount of system resources.

INSTALLATION
============

NOTE: If you are upgrading from WebStats 1.0, see section titled UPGRADING at
----- the end of this document.

There are five (5) files that are included in the WebStats 2.0 distrobution package.
These four files are:

	stats.asp		- This is the HTML interface for the user to monitor
				  site activity.

	statslog.asp		- This is the HTML interface to display the session
				  log.

	global_changes.asa	- This file contains the code you need to insert into
				  your global.asa file. If you do not have a global.asa
				  file, you should rename this file to global.asa and place
				  it in your root (default is wwwroot).

	Slider.gif		- A small .gif89a compressed image used in the selection bars.

	SliderSelected.gif	- A small .gif89a compressed image used in the selection bars.

STEP 1
======
Uncompress WebStat20.zip into a directory on your hard drive.
Make sure you have the stats.asp, statslog.asp, global_changes.asa, Slider.gif 
and SliderSelected.gif.

STEP 2
======
Place stats.asp, statslog.asp, Slider.gif and SliderSelected.gif in your web root 
(default is c:\InetPub\wwwroot)

STEP 3
======
Look in your web root for a global.asa file. It's OK if it doesn't exist, the global_changes.asa
file can act as a fully functional global.asa file.

STEP 4a (I don't have a global.asa file in my web root (default default is c:\InetPub\wwwroot)
=======
If you don't already have a global.asa file in your web root --

Copy the global_changes.asa file into your web root (default is c:\InetPub\wwwroot) and rename 
it to global.asa. Proceed to STEP 5.

STEP4b (I already have a global.asa file in my web root (default is c:\InetPub\wwwroot)
======
If you already have a global.asa file in your web root --

This is a little trickier because you must manually enter in code into your existing global.asa
file.

The global.asa file is separated into four event handlers: 

	Application_OnStart	-	This code is executed whenever the IIS or WWW services
					are started or restarted.

	Application_OnEnd	-	This section of code executes when the application is
					shut down.

	Session_OnStart		-	This code is executed whenever a user connects to IIS.

	Session_OnEnd		-	This code is fired when there is no activity for a set
					amount of time (i.e. if the visitor doesn't type anything
					for 20 minutes, their session is killed to make room
					for other users).

To install WebStats 2.0, you need to add code to the Application_OnStart event, the 
Session_OnStart event, and the Session_OnEnd event.

STEP 4b1
========
Open your global.asa file. Search for the following code--
	
SUB Application_OnStart

Just after that code, cut and paste the following

'********************************************************************************************'
'*					 Tracking Variables 				    *'
'********************************************************************************************'


' This section initializes your 

application("gSessions") = 0
application("gResetDate") = date()
application("gResetTime") = now()
application("gToday") = now()
application("gSessionsToday") = 0
application("gSessionsYesterday") = 0
if application("gSessions") = "" then application("gSessions") = 0
application("gSessionsSinceReset") = application("gSessions")
application("gPeakSessions") = application("gSessions")
application("gPeakSessionDate") = now()
application("gSessionTimeout") = 20

'********************************************************************************************'
'*					 Tracking Variables 				    *'
'********************************************************************************************'

The rest of your global.asa should come after this code (actually placement doesn't really matter,
as long as your don't paste this in the middle of an existing loop or something like that. It's
just best in this example to place the code in the beginning, just after the SUB Application_OnStart
event.

STEP 4b2
========

Search for the following code--

SUB Session_OnStart

Just after that code, cut and paste the following into your global.asa file.

'********************************************************************************************'
'*				Capture Data for every session	      	    		    *'
'********************************************************************************************'

application.lock
lCurrentSessionLog = application("gCurrentSessionLog")
lCurrentSessionLogLength = UBOUND(lCurrentSessionLog,2)
redim preserve lCurrentSessionLog(6, lCurrentSessionLogLength+1)

lCurrentSessionLog(0, lCurrentSessionLogLength) = session.sessionid
lCurrentSessionLog(1, lCurrentSessionLogLength) = time()
lCurrentSessionLog(2, lCurrentSessionLogLength) = request.servervariables("REMOTE_HOST")
lCurrentSessionLog(3, lCurrentSessionLogLength) = request.servervariables("SCRIPT_NAME")
lCurrentSessionLog(4, lCurrentSessionLogLength) = request.servervariables("HTTP_ACCEPT_LANGUAGE")
lCurrentSessionLog(5, lCurrentSessionLogLength) = request.servervariables("HTTP_REFERER")
lCurrentSessionLog(6, lCurrentSessionLogLength) = request.servervariables("HTTP_USER_AGENT")

application("gCurrentSessionLog") = lCurrentSessionLog

lSessionLog = application("gSessionLog")
lSessionLogLength = UBOUND(lSessionLog,2)
redim preserve lSessionLog(6, lSessionLogLength+1)

lSessionLog(0, lSessionLogLength) = session.sessionid
lSessionLog(1, lSessionLogLength) = time()
lSessionLog(2, lSessionLogLength) = request.servervariables("REMOTE_HOST")
lSessionLog(3, lSessionLogLength) = request.servervariables("SCRIPT_NAME")
lSessionLog(4, lSessionLogLength) = request.servervariables("HTTP_ACCEPT_LANGUAGE")
lSessionLog(5, lSessionLogLength) = request.servervariables("HTTP_REFERER")
lSessionLog(6, lSessionLogLength) = request.servervariables("HTTP_USER_AGENT")

application("gSessionLog") = lSessionLog

session.timeout = application("gSessionTimeout")

application("gSessions") = application("gSessions") + 1
application("gSessionsToday") = application("gSessionsToday") + 1
application("gSessionsSinceReset") = application("gSessionsSinceReset") + 1


if application("gSessions") >= application("gPeakSessions") then
  application("gPeakSessions") = application("gSessions")
  application("gPeakSessionDate") = now()
end if

if not datepart("d", application("gToday")) = datepart("d", date()) then '* New Day *'
  application.lock
    application("gToday") = date() 
	application("gSessionsYesterday") = application("gSessionsToday")
    application("gSessionsToday") = application("gSessions") '* Reset to current sessions *'
  application.unlock
end if

application.unlock
'********************************************************************************************'
'*				Capture Data for every session				    *'		    	    		*'
'********************************************************************************************'


STEP 4b3
========

Search for the following code--

SUB Session_OnEnd

Cut and paste the following lines of code right after the SUB Session_OnEnd header

'********************************************************************************************'
'*				Modify Active Sessions after departure	    	    	    *'
'********************************************************************************************'

application("gSessions") = application("gSessions") - 1 

'********************************************************************************************'
'*				Modify Active Sessions after departure	    	    	    *'
'********************************************************************************************'

STEP 5
======

Copy the stats.asp, statslog.asp, Slider.gif, SliderSelected.gif and your newly modified 
global.asa file to your root directory (default is c:\InetPub\wwwroot)

WebStats 2.0 is now capturing your web site's activity information. To view Real Time statistics,
open the /stats.asp file in your browser. For WebTest Server, it would be
www.dyessindustries.com/stats.asp; www.dyessindustries.com is the domain name, and thus the
lowest level of the site. stats.asp is in the wwwroot directory.

To download the latest version of WebStats 2.0, and many other useful scripts, please open your
browser to www.dyessindustries.com/webtest

UPGRADING
=========
Upgrading from WebStats is quick and easy. 

STEP 1
======
Copy the stats.asp, statslog.asp, Slider.gif, and the SliderSelected.gif into your root 
directory (default is c:\InetPub\wwwroot)

STEP 2
======
Open your global.asa file, and search for the following code --

'********************************************************************************************'
'*				Capture Data for every session				    *'
'********************************************************************************************'

session.timeout = application("gSessionTimeout")

application("gSessions") = application("gSessions") + 1
application("gSessionsToday") = application("gSessionsToday") + 1
application("gSessionsSinceReset") = application("gSessionsSinceReset") + 1


if application("gSessions") >= application("gPeakSessions") then
  application("gPeakSessions") = application("gSessions")
  application("gPeakSessionDate") = now()
end if

if not datepart("d", application("gToday")) = datepart("d", date()) then '* New Day *'
  application.lock
    application("gToday") = date() 
	application("gSessionsYesterday") = application("gSessionsToday")
    application("gSessionsToday") = application("gSessions") '* Reset to current sessions *'
  application.unlock
end if

'********************************************************************************************'
'*				Capture Data for every session				    *'
'********************************************************************************************'

This is the code from WebStats 1.0 that needs to be replaced. You can replace this code with
the code found in the global_changes.asa file --

'********************************************************************************************'
'*				Capture Data for every session				    *'
'********************************************************************************************'

application.lock
lCurrentSessionLog = application("gCurrentSessionLog")
lCurrentSessionLogLength = UBOUND(lCurrentSessionLog,2)
redim preserve lCurrentSessionLog(6, lCurrentSessionLogLength+1)

lCurrentSessionLog(0, lCurrentSessionLogLength) = session.sessionid
lCurrentSessionLog(1, lCurrentSessionLogLength) = time()
lCurrentSessionLog(2, lCurrentSessionLogLength) = request.servervariables("REMOTE_HOST")
lCurrentSessionLog(3, lCurrentSessionLogLength) = request.servervariables("SCRIPT_NAME")
lCurrentSessionLog(4, lCurrentSessionLogLength) = request.servervariables("HTTP_ACCEPT_LANGUAGE")
lCurrentSessionLog(5, lCurrentSessionLogLength) = request.servervariables("HTTP_REFERER")
lCurrentSessionLog(6, lCurrentSessionLogLength) = request.servervariables("HTTP_USER_AGENT")

application("gCurrentSessionLog") = lCurrentSessionLog

lSessionLog = application("gSessionLog")
lSessionLogLength = UBOUND(lSessionLog,2)
redim preserve lSessionLog(6, lSessionLogLength+1)

lSessionLog(0, lSessionLogLength) = session.sessionid
lSessionLog(1, lSessionLogLength) = time()
lSessionLog(2, lSessionLogLength) = request.servervariables("REMOTE_HOST")
lSessionLog(3, lSessionLogLength) = request.servervariables("SCRIPT_NAME")
lSessionLog(4, lSessionLogLength) = request.servervariables("HTTP_ACCEPT_LANGUAGE")
lSessionLog(5, lSessionLogLength) = request.servervariables("HTTP_REFERER")
lSessionLog(6, lSessionLogLength) = request.servervariables("HTTP_USER_AGENT")

application("gSessionLog") = lSessionLog

session.timeout = application("gSessionTimeout")

application("gSessions") = application("gSessions") + 1
application("gSessionsToday") = application("gSessionsToday") + 1
application("gSessionsSinceReset") = application("gSessionsSinceReset") + 1


if application("gSessions") >= application("gPeakSessions") then
  application("gPeakSessions") = application("gSessions")
  application("gPeakSessionDate") = now()
end if

if not datepart("d", application("gToday")) = datepart("d", date()) then '* New Day *'
  application.lock
    application("gToday") = date() 
	application("gSessionsYesterday") = application("gSessionsToday")
    application("gSessionsToday") = application("gSessions") '* Reset to current sessions *'
  application.unlock
end if

application.unlock
'********************************************************************************************'
'*				Capture Data for every session				    *'
'********************************************************************************************'

That's it. enjoy!
