Custom Web Visitor Tracking using C#

Introduction

When you want to collect more data about your website visitors and client platform which is not provided by IIS log files you can use this simple technique to do that. If you are able to collect the data from the server side and if you have full control over the server side page creation code probably this technique will not be required at all for you.

Background

I started this simple task when I wanted to track a web document ID which the IIS logs did not log when user is requesting the pages. (By the way our site had dynamic content in JSP, each page with unique id). Whenever a user navigates through the pages in our site we want to track the document id he / she is visiting. The collected data is stored in SQL Server.

Using the code

1.
Decide what kind of data you want to collect. (Client browser information and platform information are provided by IIS logs. You can run a basic web log tool to extract this information.) In our case document ID, timestamp, and URL referrer is the data that we want to collect.

 

2.
Create a database table with the data fields which you are capturing. You Also need to create a stored procedure to insert the data.

 

3.
Include the following line of html in your web pages which you are trying to track the information. <img src='http://servername/dirname/webform.aspx?param1=val1&param2=val2' width="0" height="0">. The height and width attributes are 0 here because the source is not an actual image. We are tricking the browser to request this page with an image tag.

 

4.
Write an aspx application and in the Form load function extract the query string values and insert them into the database.

 

minus.gif Collapse
/*Script for generating DB object for the sample project
attached. Copy paste the following  section in to your sql server
enterprise manager and run it. */
if exists (
select * from dbo.sysobjects
where id = object_id(N'[dbo].[usr_log]')
and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[usr_log]
GO
if exists (
select * from dbo.sysobjects
where id = object_id(N'[dbo].[UsrLog]')
and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[UsrLog]
GO
CREATE TABLE [dbo].[UsrLog] (
 [id] [int] IDENTITY (1, 1) NOT NULL ,
 [timesmp] [datetime] NULL ,
 [Platform] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [BrowserVersion] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [ClrVersion] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [IsCrawler] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [RemoteHost] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [usr_log]
@Platform varchar(256),
@BowserVersion varchar(256),
@ClrVersion varchar(256),
@IsCrawler varchar(256),
@RemoteHost varchar(256)
AS
BEGIN
 insert into UsrLog (Platform,
BrowserVersion,
ClrVersion,
IsCrawler,
RemoteHost)
values (@Platform ,
@BowserVersion,
@ClrVersion,
@IsCrawler,
@RemoteHost)
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

转载于:https://www.cnblogs.com/godwar/archive/2007/07/09/811101.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值