Visitor Stats

Discussion in 'ASP General' started by Jon, Dec 31, 2003.

  1. Jon

    Jon Guest

    Hi,

    I'm writing a VERY BASIC stats databse for the default page of my web site.
    I'm detecting various stats and saving them:

    <%
    visitdate = date()
    visittime = time()
    visitbrowser = Request.ServerVariables("HTTP_USER_AGENT")
    visitreferer = Request.ServerVariables("HTTP_REFERER")
    ' code here for screen size
    ' code here to save to database
    %>

    I wish to also get screen resolution/size. I realise this is client side so
    I can use:

    <script language="JavaScript" type="text/javascript">
    <!--
    var screenW = screen.width
    var screenH = screen.height
    document.write(screenW + "x" + screenH)
    //-->
    </script>
    But I can't save that into my database!!

    Has anyone solved this problem before?

    Thanks

    Jon
     
    Jon, Dec 31, 2003
    #1
    1. Advertising

  2. Jon

    TomB Guest

    Have a form with a hidden field, use your javascript to populate the hidden
    field(s) then post the form.

    "Jon" <jon@SPAM_OFFtheexperts.co.uk> wrote in message
    news:bsuhae$o54$...
    > Hi,
    >
    > I'm writing a VERY BASIC stats databse for the default page of my web

    site.
    > I'm detecting various stats and saving them:
    >
    > <%
    > visitdate = date()
    > visittime = time()
    > visitbrowser = Request.ServerVariables("HTTP_USER_AGENT")
    > visitreferer = Request.ServerVariables("HTTP_REFERER")
    > ' code here for screen size
    > ' code here to save to database
    > %>
    >
    > I wish to also get screen resolution/size. I realise this is client side

    so
    > I can use:
    >
    > <script language="JavaScript" type="text/javascript">
    > <!--
    > var screenW = screen.width
    > var screenH = screen.height
    > document.write(screenW + "x" + screenH)
    > //-->
    > </script>
    > But I can't save that into my database!!
    >
    > Has anyone solved this problem before?
    >
    > Thanks
    >
    > Jon
    >
    >
     
    TomB, Dec 31, 2003
    #2
    1. Advertising

  3. Jon wrote:

    > Hi,
    >
    > I'm writing a VERY BASIC stats databse for the default page of my web site.
    > I'm detecting various stats and saving them:
    >
    > <%
    > visitdate = date()
    > visittime = time()
    > visitbrowser = Request.ServerVariables("HTTP_USER_AGENT")
    > visitreferer = Request.ServerVariables("HTTP_REFERER")
    > ' code here for screen size
    > ' code here to save to database
    > %>
    >
    > I wish to also get screen resolution/size. I realise this is client side so
    > I can use:
    >
    > <script language="JavaScript" type="text/javascript">
    > <!--
    > var screenW = screen.width
    > var screenH = screen.height
    > document.write(screenW + "x" + screenH)
    > //-->
    > </script>
    > But I can't save that into my database!!


    You can try
    <script type="text/javascript">
    document.write('<img alt="" src="log.asp?width='
    + screen.width
    + '&height=' + screen.height
    + '" width="0" height="0">');
    </script>
    then in log.asp you store those values from the query string.
    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Dec 31, 2003
    #3
  4. Jon

    Jon Guest

    > Have a form with a hidden field, use your javascript to populate the
    hidden
    > field(s) then post the form.
    >
    > > Hi,
    > >
    > > I'm writing a VERY BASIC stats databse for the default page of my web

    > site.
    > > I'm detecting various stats and saving them:
    > >
    > > <%
    > > visitdate = date()
    > > visittime = time()
    > > visitbrowser = Request.ServerVariables("HTTP_USER_AGENT")
    > > visitreferer = Request.ServerVariables("HTTP_REFERER")
    > > ' code here for screen size
    > > ' code here to save to database
    > > %>
    > >
    > > I wish to also get screen resolution/size. I realise this is client side

    > so
    > > I can use:
    > >
    > > <script language="JavaScript" type="text/javascript">
    > > <!--
    > > var screenW = screen.width
    > > var screenH = screen.height
    > > document.write(screenW + "x" + screenH)
    > > //-->
    > > </script>
    > > But I can't save that into my database!!
    > >
    > > Has anyone solved this problem before?
    > >
    > > Thanks
    > >
    > > Jon


    When I considered the form idea I figured the problem is that it needs
    posting, that is it won't work as the visitor goes to the page.

    I'm going to have a try with Martins idea. I considered at the 'top' of the
    page write the info to a cookie using javascript, at the 'end' of the page
    retrieving this information using vbscript for my database?!

    Jon
     
    Jon, Dec 31, 2003
    #4
  5. Jon

    Jon Guest

    Sorted, thanks Martin.

    The result:

    index.htm or whatever:

    <script language="JavaScript" type="text/javascript">
    document.write('<img alt="" src="log.asp?width=' + screen.width +
    '&height=' + screen.height + '" width="0" height="0">');
    </script>

    log.asp:

    <%
    dim conn, strsql, rsuser, strMDBPath
    set conn=server.createobject("ADODB.Connection")
    set rsuser=server.createobject("ADODB.Recordset")
    strMDBpath = Server.MapPath("stats.mdb")
    conn.open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & strMDBPath

    visitdate = date()
    visittime = time()
    visitbrowser = Request.ServerVariables("HTTP_USER_AGENT")
    visitreferer = Request.ServerVariables("HTTP_REFERER")
    if visitreferer = "" then
    visitreferer = "None shown"
    end if
    visitscreenresolution = request.QueryString("width") & "x" &
    request.QueryString(+"height")

    sql="INSERT INTO tblVisitors (visitdate, visittime, visitbrowser,
    visitreferer, visitscreenresolution) VALUES ('" & visitdate & "', '" &
    visittime & "', '" & visitbrowser & "', '" & visitreferer & "', '" &
    visitscreenresolution & "');"

    conn.Execute sql

    conn.close
    set rsuser=nothing
    set conn=nothing
    %>

    Almost worthy of an FAQ ?????

    Jon
     
    Jon, Dec 31, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shige
    Replies:
    1
    Views:
    809
    Munsifali Rashid
    Jan 13, 2004
  2. Mohammed Dwaikat

    Knowning IP Web site Visitor

    Mohammed Dwaikat, Nov 17, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    372
    Nick Stansbury
    Nov 17, 2004
  3. Scott Allen
    Replies:
    4
    Views:
    1,066
    bruce barker
    Jan 14, 2005
  4. Greg Collins [InfoPath MVP]

    Active Visitor Count

    Greg Collins [InfoPath MVP], Nov 10, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    457
    Juan T. Llibre
    Nov 10, 2005
  5. Alexey Smirnov

    Re: Recording Visitor Stats

    Alexey Smirnov, Sep 16, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    422
    Alexey Smirnov
    Sep 18, 2008
Loading...

Share This Page