Thursday, March 22, 2012

Site Stats??

Does anyone know how to code in vb.net/asp.net a way to get information each time a user views your web site, eg browser type, operating system, IP address, ect... well as much detail as possible? (mainly stuff that would be usefull for market research).

Thank youRequest.ServerVariables("REMOTE_ADDR") helps you to get the client IP! Similarly you can get other info using servervariables().

Below user can helps you on it.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/iis/servervariables.asp
Or use a third party service like www.WebStat.com

I use the free service and it has the basic stats I need.
To get the most info, you'll need to turn on logging for IIS. You can then get some third party tools to parse the log files to create usefull information for you.
I'm trying to do the same thing.

Heres what I have so far...


Sub Page_Load(Sender as Object, E as EventArgs)
'Try

txtClient.text &= "UserAddress:" & CType(Request.UserHostAddress, String) & "<br>"
txtClient.text &= "Agent:" & CType(Request.UserAgent, String) & "<br>"

Dim BrowserCaps
Dim Language as String
BrowserCaps = Request.Browser

txtClient.text &= "Browser:" & CType(BrowserCaps.Browser, String) & "<br>"
txtClient.text &= "Version:" & CType(BrowserCaps.MajorVersion, String) & "." & CType(BrowserCaps.MinorVersion, String) & "<br>"
txtClient.text &= "Platform:" & CType(BrowserCaps.Platform, String) & "<br>"

txtClient.text &= "Languages:"
For Each Language In Request.UserLanguages
txtClient.text &= Language & " "
Next
txtClient.text &= "<br>"

txtClient.text &= "Interface:" & CType(Request.ServerVariables("GATEWAY_INTERFACE"), String) & "<br>"
txtClient.text &= "Protocol:" & CType(Request.ServerVariables("SERVER_PROTOCOL"), String) & "<br>"
txtClient.text &= "Port:" & CType(Request.ServerVariables("SERVER_PORT"), String) & "<br>"
txtClient.text &= "Referer:" & CType(Request.QueryString("referer"), String) & "<br>"

Dim IPHost
IPHost = DNS.GetHostByAddress(CType(Request.UserHostAddress, String))
txtClient.text &= "HostName:" & IPHost.HostName & "<br>"

End Sub

You'll notice that my referer is passed via a QueryString rather than using Request.ServerVariables("HTTP_REFERER"). Thats mainly because I have a single page which redirects several domains to mutliple sites.
Oh! One other thing - take a peak at
http://lyfecouk.plus.com/securityandstats/
which is a prototype security and stats engine outline. Some things in there that are already outdated... but you get the idea.
You could also set awstats up to get stats:
http://awstats.sourceforge.net/

Works with IIS ;)

0 comments:

Post a Comment