Click here to view or download the code for this example
ASP Code Articles
Page View and Visitor Tracking
Every webserver has the capability to log every single access to any website hosted on it. This will however record requests (hits) for every object referenced on every page in the site, images, javascripts, CSS files etc. Much of this data, while the information can be useful, is superfluous when what you really need to know is, Where did each unique visitor come from, How long were they on the site, how many pages did they view and did they buy anything?.
Several utilities exist to analyse site logs either on the server or locally when they are downloaded. However some hosts do not make the logs available and often hosting companies disable logging on the sites for many reasons. One is that logs can and do get extremely large and will eat up disk space at an alarming rate for a server with several busy sites on it. So if you can't get access to your logs how do you get the information about your site visitors?
This is a script for adding each page view to a database, useful for tracking a visitors progress through the website, checking which pages get the most views, where a visitors exits the site and Search Engine crawler visits. This could be extended to include cookie tracking for checking return visits and member access among other things.
One use for this script, even if you do have log access is as an affiliate tracking system. A couple of changes to the code to detect the affiliate querystring identifier and add a field to the database for logging the ID, this can then be linked with any purchases that this visitor makes. The session ID and IP can be used by the shopping cart/purchasing system to identify the items
The data collected is;Access Date and Access Time. No explanation needed here I would think
Session ID Ref. This is a unique reference code assigned to each new visitor when they first arrive on the site, and will remain the same until the visitor closes their browser or exits the site. So it is a useful metric when looking at visitor traffic and page views
Remote IP.The Remote IP is the ISP assigned number for the visitors Internet Address. This could be used to identify unique vistors, However some visitors may well be sharing one address. Corporate proxy servers will only have one IP and there may be many visitors from the one IP. AOL (America On-Line) also divert all their users through a group of proxy servers, this is to allow them to offer their own managed content systems.
Referer URL.This is one important metric when analysing website statistics. The information in this field will show where the visitor arrived from. It may be from the site navigation and you can then track the visitor route through the website using the date & time for the sort order and Session ID for a filter or grouping. One vital metric from here is that the Querystring will be part of this field when visitors first arrive on the site and can then show which phrases the site is being found for, Which Search Engine the hit came from and which page was the target. Clicks from external links will also show here so the effectiveness of any linking campaign and the popularity of the links can be analysed.
Site URL. This is the page name that triggered the database entry. Used in conjunction with the Session ID it can give which pages or products are more popular with site visitors. Used with the Referer URL it can show what pages are the most popular or most effective as landing pages and it can also be used to analyse what product pages may need attention.
Query String. This field will show the in-site querystring. A metric that is very important for dynamic sites where a single page may be doing all the display work and each product or category is selected by passing a value in the address bar (eg: product.asp?item=23). Combining a report using this field and the Site URL field will give a popularity check for individual products or category hits.
Method. This is just the HTTP method that was used to access the page, mostly this will be "GET" as this is the method used by user-agents to request all the page data to be sent. The only other methods that may appear are "POST" used when sending data back via a form, or "HEAD" which just retrieves the page headers.
User Agent. The User Agent String is text information sent by the user-agent (Browser or SE crawler) that identifies it. The string contains no personal information about the user, but it does normally identify which browser version and operating system the visitor is using. Analysis of the string can indicate what devices visitors are using and querying this field for known crawlers will show what pages and when each search engine crawler visited.
Knowing what browsers/devices are arriving on the site, and possibly more importantly, where they are leaving, can be used to identify usability issues in the site code, layout or the copy.

