Forums

ASP

This topic is locked

Small User Tracking Application

Posted 17 Aug 2005 17:44:01
1
has voted
17 Aug 2005 17:44:01 Richard Mariner posted:
I changed my browser setting to accept all cookies and it works.

I'm trying to see how many user visit a page and which page they are visiting. Here is how I have gone about it. Create a sub and a function and place it into an include file.

The sub checks the cookie for new or returning and gets the URL using the servervariable.
<pre id=code><font face=courier size=2 id=code>Sub SetFirstVisitedPage ()
Dim sPageName
sPageName = Request.ServerVariables("URL"
If Len(Request.Cookies("CheckFirstPage") = 0 Then
If Len(Request.Cookies("RevisitingUser") = 0 Then
' New user
Application("Page_New_" & sPageName) = _
Application("Page_New_" & sPageName) + 1
Else
' Revisiting user
Application("Page_Revisit_" & sPageName) = _
Application("Page_Revisit_" & sPageName) + 1
End If
Response.Cookies("CheckFirstPage" = "Done"
Response.Cookies("RevisitingUser" = "Yes"
Response.Cookies("RevisitingUser".Expires = Date() + 30
End If
End Sub
</font id=code></pre id=code>
Next we have a function that return a result. This function combines takes the name or the URL and the number of visits and combine them into a variable named "GetFirstVisitedPage". See last line of function.
<pre id=code><font face=courier size=2 id=code>Function GetFirstVisitedPage(ByVal bNewUsers)
Dim iMaxHits
Dim sAppVar
Dim sFirstVisitedPage
iMaxhits = 0
For Each sAppVar in Application.Contents()
If Left(sAppVar, 5) = "Page_" Then
If bNewUsers = True then
If Left(sAppVar, 9) = "Page_New_" Then
If CInt(Application(sAppVar)) &gt; iMaxHits Then
iMaxHits = Application(sAppVar)
sFirstVisitedPage = Right(sAppVar, Len(sAppVar) - 9)
End If
End If
Else
If Left(sAppVar, 13) = "Page_Revisit_" Then
If CInt(Application(sAppVar)) &gt; iMaxHits Then
iMaxHits = Application(sAppVar)
sFirstVisitedPage = Right(sAppVar, Len(sAppVar) - 13)
End If
End If
End If
End If
Next
GetFirstVisitedPage = sFirstVisitedPage & " with " & iMaxHits & " hits "
End Function
</font id=code></pre id=code>
The result of this should allow me to read the following to a page and get the page location/url and the number of hits for that page. However it will only give me the number of hits.
<pre id=code><font face=courier size=2 id=code>The most popular first page for new users is:
&lt;%= GetFirstVisitedPage (True) %&gt;
&lt;br&gt;
The most popular first page for returning visitors is:
&lt;%= GetFirstVisitedPage (False) %&gt;
</font id=code></pre id=code>
Thanks!
Rich

I moved the code to another server and it runs great! So it must be something about my server settings. Do you know of a place that list the proper settings?


Edited by - mar0364 on 17 Aug 2005 22:35:05<b></b><b></b>

Edited by - mar0364 on 18 Aug 2005 04:03:01

Reply to this topic