Results 1 to 11 of 11
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Implement a 'web counter'

    I've been asked to find out how many times people here take the time to read our on-line newsletter. I have an idea on how to do this and wanted to see if anyone had any suggestions.

    my plan:
    1. On clicking on the link, you are actually sent to an page that opens a connection to the db, writes a '1' to new row, closes the connection and redirects the page to the newsletter
    proper.
    2. I can put together a dinky little page that runs a query (or view, whatever) to show the total in the table at any time.

    I know this will work, but I wonder about error handling: if the db is dead for some reason, I don't want to prevent people from viewing the newsletter anyway. I was wondering if a javascript version of doing the db operations might be better in terms of, if an error is thrown, the page will load as needed. Or can you do error traping in ASP just as well? my experience with db stuff in ASP leads me to believe you'll see ugliness if the db connection fails completely...

    TIA
    <img src=/S/compute.gif border=0 alt=compute width=40 height=20>

  2. #2
    2 Star Lounger
    Join Date
    Aug 2004
    Location
    Withyham, Sussex, England
    Posts
    121
    Thanks
    2
    Thanked 1 Time in 1 Post

    Re: Implement a 'web counter'

    Hi Steve, would it not be possible to just put a CGI counter on the page and reset it every time you change the newsletter, just a thought. Cheers Graham.

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Implement a 'web counter'

    I suppose I could do this but I am working under IIS and I've never been successful with this CGI-BIN stuff. I am under the impression that CGI is deprecated tech (ASP, JavaScript, ASP.NET, PHP etc. are the 'replacements').

    I also seem to recall that IIS doesn't support CGI-BIN on a normal install so I'd have to get the webserver configged to support that kind of scripting, something I won't do (the agency webserver is not under my control).

    If my understanding is flawed or the CGI solution is easier than I think it is please let me know.

  4. #4
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Implement a 'web counter'

    I can recommend two options:

    1) Purchase some log-analyzing software. It's not free, but you'll find a rich set of tools that will analyze your IIS log for various trends. Just Goole for iis log anaylsis and you'll find a ton of stuff.
    2) Roll your own data-driven counter. You had the right idea about having a counter table or text file. Simply increment this value by one each time a new session is created. So you'll need to use the Session_OnStart() event in the Global.asa file to fire this process. You'll want to read up on using the Session_OnStart() for the nitty-gritty details. The database process should be very simple. A single-column table with only one row. Get the current value and update the table to value + 1. Easy-peezy lemon-squeezy. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>.

  5. #5
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Implement a 'web counter'

    thanks for the response. for the scope of this project, and because the server logs are on a webfarm, I don't think the logging SW is needed or, perhaps, even workable.

    as to the data-driven counter, why do I even need to get into a global.asa file? If I set up a page for opening and incrementing the db table and do a redirect that does basically the same thing, no?

  6. #6
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Implement a 'web counter'

    Do you want to count every single time the page is hit? Or would you rather count the unique visitors that hit the page?

    If the former, the simple solution is to apply the increment routine in the page itself.
    Otherwise, you'll want to apply some means to only count one hit per unique visitor (or session). On second thought, the Session_OnStart() event is only useful if you want to count visitors as the session starts - not necessarily when they hit the page in question.

    You could also modify the design of the hit-counting table to include a sessionId, date/time stamp, and IP address (rather than only holding a single count value), so you can run your own statistics on the data. Just remember that multiple users will show up with the same IP address if they're behind a firewall.

    Also, FYI: some web log analysis software packages support a server farm. I've used one in the past - I think it was WebTrends. The downside is that they're not cheap.

  7. #7
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Implement a 'web counter'

    Actually, one small problem with this project is the page being 'hit' is a PDF document, so I can't (I guess) embed some kind of counter code in the page. I can see doing this using ASP and a Session object on a html page (kind of) -- but, OTOH, I am not interested in displaying a count, just doing a report on it, so the backend db seems like the way to go. It does seem useful to distinguish click-thrus on a session ID as opposed to just clicking... I can do both of course.

    Your suggestion on using the HTTP queries to build a more interesting log file has merit.

    Well when I started thinking about this I wanted to implement the counter R/W to SQL Server and was concerned about errors blocking the PDF from loading is SQL Server when sideways. I think a small Access file may in fact be more reliable... The pity with using Access is, you *have* to build a maintenance page to get the info, or have a copy of the db sent over. Ah well, que sera sera as they say...

    Out agency in fact uses Webtrends on the web server farm but the page(s) I want to monitor are far too lightly trafficed for Webtrends standard reports to touch them. Hence my need to create an alternative.

  8. #8
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Implement a 'web counter'

    If you're already running Webtrends, why don't you just make a custom report that focuses on the PDF file? That seems like the obvious best solution in this case. Check with your administrator and/or Webtrends documentation to find out how to customize a report. I've done it before and it's pretty intuitive.

  9. #9
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Implement a 'web counter'

    the short answer to that is, Webtrends as it is currently configured doesn't report on pages below 80% of the total traffic, so I'd have to setup some custom work on the SW to do it.

    Anyway, I've already created a handy-dandy Access db to capture some of the more interesting HTTP request info so I think the problem is basically solved. Of course, I don't have Webtrend's nifty comprehensiveness and graphs but, OTOH, they're only asking me to tell them how many times the newsletter is being accessed. Hopefully some of the other HTTP request info will help me find out (roughly) where the access traffic is coming from in terms of the Remote Address.

    Also, I like to learn new things! Sure there's some wheel-reinventing going on but I'm having a little fun...

    I was originally concerned with a nice clean way to handle errors on a db connect as I was planning on using SQL Server for the logging but I think, in this case, it's not likely the Access file will die unless a lot of other things (like the enterprise website) dies as well.

    I'd *still* like to know if there are methods for detecting a db connection failure so that one can 'blip' over it. For this project, I don't want the backend counter page to prevent access to the newsletter, but I think using Access on the webserver will be stable enough.

    Any advice on setting up error handling so that a failure to open a db connection can be handled in the background? IOW, if the counter logfile errors, is there a way to just go ahead and open the page requested?

  10. #10
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Implement a 'web counter'

    Have you Googled for ASP error handling? It turns up quite a few articles and tutorials...

    One that looks good is 4 Guys from Rolla.

    Basically, prefix any section that may have an error with "ON ERROR RESUME NEXT"

    .NET has added a more extensive structured exception handling model - Try/Catch/Finally. Anyone interested in using .NET should read up on this feature as well.

  11. #11
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Implement a 'web counter'

    strangely enough, I had, on my own, created two error trapping pages for times when IIS kicks out two different errors: 404 and 500 errors. We all know what a 404 is; 500's cover failures in a request (which is most ASP variable-passing weirdness) I may not be totally on-target with a 500 error, but I believe it covers most ASP errors that display weird ADO - type messages. Trappign the 404 error is also handy as this may occur when my code is trying to redirect to a non-existent page (the page redirect being set in ASP code itself). What these files do is write the HTTP_REFERER server variable in an e-mail to me so I'll have some idea of what page the user was on just prior to getting the error. In addition, of course, the user can't continue on, which I wouldn't want anyway.

    As to the On Error Resume next, that might work just dandy for the counter page....I'm assuming the syntax is something like:

    < %
    On Error Resume Next

    ASP code, including db connect attempt

    Response.Redirect("my page")

    Error Handling code (like e-mailing me the obscure error number)

    % >

    In cases where I don't want execution to proceed the method of hooking into IIS's custom errors is definately more user-friendly than the default pages...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •