sdlangers Posted June 20, 2005 Posted June 20, 2005 when you see those free counters that tell you to put in some javascript into your website and then that tracks the number of hits etc... what is that javascript doing? its normally an include file on their server, so i cant see it is it posting the data somewhere? or is it just putting in a small gif or something that is on their server, so they can process the info then from their logs of that file? Quote
bri189a Posted June 21, 2005 Posted June 21, 2005 I'd guess that the script it points to writes an IFRAME on your page which inserts the counter and handles the counting. I'd never use one, who knows what else they could be putting in that IFRAME...pop-ups to sponsored links, spyware, ActiveX exploits, etc. Those type of things could get you to lose any potential visitors pretty quick. I'd spend the 10 minutes make my own if you were thinking of going that route. A counter is a very simple thing, anybody who just doesn't want to give you the code all together but instead wants you to put in javascript that points to their site probably has some alterior motive. Quote
sdlangers Posted June 21, 2005 Author Posted June 21, 2005 thanks - i think this one is trustworthy - its not a counter i need, i need the full web stats - http://www.statcounter.com so i was wondering how they gather stats using clientside javascript or a frame or how are they doing it? Quote
bri189a Posted June 21, 2005 Posted June 21, 2005 Again they are probably using an IFRAME and on the server doing some browser sniffing, ip tracking and tracking the time and stuff. It's pretty elementary. Quote
TheWizardofInt Posted June 21, 2005 Posted June 21, 2005 It is EASY to do your own counter. Create a simple Access database called 'Counter' and put it in a folder called 'db' or 'data' or something on your web site. The table in the database for this example is called 'PageHits', and it has three fields: Hits - Numberic Page - Numeric Date -Date Public Sub CountHits(ByVal sPage As String, ByVal sServer As String) If sIP <> "xxx.xxx.xxx.xxx" Then Try Dim sNumber As String Dim sDate As String = DateString Dim oConn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & sServer & ";") oConn.Open() Dim sSQL As String = "SELECT [Hits] FROM [PageHits] WHERE Page='" & sPage & "' " & _ "AND Date=datevalue('" & sDate & "')" Dim MyCommand As New OleDb.OleDbCommand(sSQL, oConn) Dim MyReader As OleDb.OleDbDataReader = MyCommand.ExecuteReader() If MyReader.Read Then sNumber = MyReader(0).ToString Dim lNumber As Long = Val(sNumber + 1) sNumber = CStr(lNumber) MyReader.Close() Dim sUpDate As String = "UPDATE [PageHits] SET [Hits] = " & sNumber & " WHERE Page='" & sPage & "' " & _ "AND Date=DateValue('" & sDate & "')" MyCommand = New OleDb.OleDbCommand(sUpDate, oConn) MyCommand.ExecuteNonQuery() Else 'need to make the enty Dim sInsert As String = "Insert Into [PageHits] ([Page], [Hits], [Date])" & _ "Values('" & sPage & "', 1, '" & DateValue(sDate) & "')" MyReader.Close() Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(sInsert, oConn) cmd.ExecuteNonQuery() cmd.Dispose() End If MyCommand.Dispose() oConn.Close() MyCommand.Dispose() Catch ex As Exception End Try End If End Sub And then invoke it like this: CountHits("Index", Server.MapPath("database/Counter.mdb")) The xxx.xxx.xxx.xxx is your own IP, so it doesn't count your hits when you surf your own page Quote Read the Fovean Chronicles Because you just can't spend your whole day programming!
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.