Click here to Skip to main content
15,887,746 members
Articles / Web Development / IIS

Web Session - Monitor, Record, and Video Playback

Rate me:
Please Sign up or sign in to vote.
2.94/5 (12 votes)
6 Mar 2008CPOL6 min read 65.8K   41   20
How to: Monitor, Record, and Playback every visit to a website using very simple techniques and existing technologies.

Introduction

Using JavaScript, a little AJAX, and an HTTP Module, we can record client DOM events by posting them to the server via small AJAX packets, storing the information in XML format for later retrieval. The XML could then be parsed either in real-time, or otherwise to provide a true visual representation of the user's session (in motion or with an accompanied timeline), enabling video playback of an entire visitor's session.

The concept has many applications:

  • Real-time web application technical support
  • This could be achieved by viewing a user's session to identify the issues whilst speaking to the visitor via messenger/telephone etc.

  • Web application training
  • Talk the user through the application whilst you view the session in action.

  • Advanced web statistics
  • Provide almost video playback of each and every visitor to a particular website.

  • Usability testing
  • Generate genuine usability figures by processing the session information captured.

  • Remote assistance
  • With a little tweaking, control could be passed to another session and events relayed to allow an administrator to take over a visitor's web page on request and perform clicks, fake mouse moves etc.

Limited only by your imagination I believe.

Concept Overview

The concept is to provide an HTTP Module that intercepts web requests and records session information in XML format. At the same time, it injects some client-side JavaScript that captures all the events on the page via the DOM. Using a very light-weight AJAX script, it sends information about each event such as tag name, event type, and event date (millisecond resolution) the event was triggered to the server. This information is then stored on the server in an XML structure under the current users session key for later retrieval.

The site administrator would then be able to view a list of all sessions on the server, select a session, and either choose to play back the entire session or view the almost real-time session in process. This could happen by loading a page containing an IFrame to show the pages visited, and the contained page executes a script to retrieve the events and fire them accordingly. To demonstrate the mouse movement, an absolute Div could be positioned over the page at the specified X and Y. Events on the page could be triggered using .fireevent or an equivalent method.

Alternatively, a Flash presentation type application could be created; together with some C# it could read the XML, have C# take a snapshot of the page as an image, load the image, and process events using mouse pointers etc., to demonstrate the events. As each event is recorded with a millisecond timing, the overall time of the session could be calculated and a timeline assigned, thus allowing the user to speed up the session playback or skip sections. Of course, as I have said, this could also be done in real time as the user is using the site.

The applications for this are immense. Why bother recording geo location and page visits when you could have it all together with a video of the entire session? A usability tool could be applied over the top to determine how difficult the user found the site. The point is, once you understand the concept, the possibilities are endless.

You could even transmit events from one session to another, creating remote assistance in the browser. Now, that's smart, right?

Required Elements

  • HTTP Module
  • Captures the session start and creates an application variable with the name of the session key. It then inserts an XML document into the variable as a string that would later be used for storing events. It injects a script file (link) into the page to load the monitoring events. The script file is requested from the HTTP Module and built on the fly, maybe using an embedded resource file as a template. This means we could have an XML config file on the server to allow the administrator to define which events he's interested in monitoring/recording for each visitor. Such as click, mouse move, mouse over, onbeforeunload, keyup, etc.

  • AJAX Layer
  • A light AJAX layer to allow sending of events without refresh. This must be light weight because I just hate all the overloaded frameworks out there, and it would only cripple the solution. The AJAX layer would take events into a local array/stack and push them to the server when possible, ensuring no events are missed. Common sense would need to be used here as we only want to send essential and compact information (so no complete form posts); find another way to do that. It should only be a few bytes at a time. Anything more could mean close to real-time viewing of sessions could be compromised due to the time taken to send/process events. Each event should be bytes in size including the HTTP header posted.

  • Admin Interface
  • Again, embed this into the HTTP Module as it will make the component more portable. Have a username and password stored in the web.config or another config file. Once the HTTP Module receives the request for the said page, it will prompt the user for login, and providing they pass, it will render the page containing a list of sessions sorted by time, with maybe a nice flag to show where each visitor is from. OK, you could go mad here and render them over Google Maps. Actually, that would be impressive - a Google globe map of your live sessions.

  • Playback
  • Again, an embedded resource to make the DLL portable. Provide a page that contains an IFrame tag, and again, light AJAX to retrieve the session XML in fragments. Using the IFrame, load the relevant pages when required. Using a Div with maybe an image of the mouse pointer, animate mouse movements. You could also tweak the IFrame DOM directly to fire the relevant events. (Maybe an elements GID could be created based on the original elements index in the DOM.)

  • Flash Movie
  • XML event information could be passed to a Flash interface. Maybe use C# to return an image of the required URL, and then use Flash to animate the pointer over the image to represent the session in motion. Again, this could be almost real-time.

    For full session viewing, the XML event file could be parsed and all event times processed to provide a second timeline of a session. This would mean the user could skip parts of the session similar to how they might skip sections of FLV videos. Alternatively, they could speed up the replay of the session.

  • Data Analysis
  • Given we have detailed event information in XML format, we could use this to estimate usability trends. E.g., how long it took the user to reach the final goal of the site (ordering a product, for example) before ending the session.

Event recording example (JavaScript)

JavaScript
var oAJAX = new AJAX();

window.onload=function()
{
    //
    // global mouse move
    //
    document.mousemove = function(e)
    {
        // send event to server with X and Y
        oAJAX.send("send Mouse X & Y, tagName " + 
                   "and Current Date/Time to the millisecond")
    }
    
    //
    // global mouse down
    //
    document.onmousedown = function(e)
    {
        // send event to server with X and Y
        oAJAX.send("send Mouse X & Y, tagName and " + 
                   "Current Date/Time to the millisecond")
    }

    //
    // get a collection of all tags
    //
    var aTags = document.getElementById("*");
    
    //
    // the events to be captured could be configured in an XML config
    // file on the server and this script file build on the fly.
    // therefore allowing the site administrator
    // to decide the events/elements to monitor.
    //
    for (var i=0; i<aTags.length; i++)
    {
        var el = aTags[i];
        
        el.onclick = function(e)
        {
            // send event to server
            AJAX.send("send Mouse X & Y, tagName and Current " + 
                      "Date/Time to the millisecond");
        }

        el.onmouseover = function(e)
        {
            // send event to server
            oAJAX.send("send Mouse X & Y, tagName and " + 
                       "Current Date/Time to the millisecond");
        }

        el.onblur = function(e)
        {
            // send event to server
            oAJAX.send("send Mouse X & Y, tagName and " + 
                       "Current Date/Time to the millisecond");
        }

    }   
}

Danger, Danger

There are, of course, many side effects to this concept. If we captured all events on the screen, this would also give us the ability to capture the message you were thinking of posting to a newsgroup but decided to delete, or maybe the chat room message you re-edited before posting. I guess when we get to this level of monitoring, it makes you realise how exposed we really are.

As JavaScript/AJAX are in massive use in today's browsers and applications, this technique could be created and implemented without the visitor ever realising they were being monitored.

Points of Interest

I do hope this makes sense; I would welcome any feedback. I am a behind the scenes type of developer, and therefore have never posted an article, so please don't shoot me down!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer MammothWorkwear.com
United Kingdom United Kingdom
Senior Web Developer, Systems Architect and Entrepreneur. Technical Director of MammothWorkwear.com. More information is available at http://www.johndoherty.info/

Comments and Discussions

 
GeneralMy vote of 4 Pin
ramanujkumar5-May-14 2:23
ramanujkumar5-May-14 2:23 
GeneralThe idea is not new ;))) Pin
davidg@actcom.co.il11-May-07 6:09
davidg@actcom.co.il11-May-07 6:09 
GeneralRe: The idea is not new ;))) Pin
John Doherty12-May-07 6:14
John Doherty12-May-07 6:14 
GeneralRe: The idea is not new ;))) Pin
User of Users Group13-May-07 0:44
User of Users Group13-May-07 0:44 
GeneralRe: The idea is not new ;))) Pin
John Doherty13-May-07 7:28
John Doherty13-May-07 7:28 
GeneralRe: The idea is not new ;))) Pin
User of Users Group14-May-07 0:26
User of Users Group14-May-07 0:26 
Please do not get me wrong, I believe article is and could be a great starting point.

I am not making any assumptions on your experience, but I was rather commenting on constant influx of general input on this site overall. You know the one coming in form of : 'this is not new', 'patent pending', 'got that in VB', 'got that in CSharp', 'got that in MFC', 'this is not new', 'there is my product.com', 'check out that.net'

I was only aiming at making the article less 'my cool idea marketing'-like and more in a form of 'business proposal', professional and without the 'look how good I am' hints. The proposal or work should speak for itself or in seperate presentation document or media.

And I believe you should fear no patent comments, and especially in Europe at the very least. Even if not, then you always have workarounds, possibility of an entire hurd of prior art claims and more. Thus whether MS has patent on something is probably too much detail.

The best Web work probably was done around the time you mention, it rings bells, and I have no doubt your work was leading back then.

I often recall seeing people do a lot more than thought possible at that time but only taken as 'wow' today on yahoo or google or those silly 'look ma, mash up, smash up debug JS' sites.

And those roots are important while the rest pile in overbloated ASP.NET or JSP or runtime approach.

And I can understand what you went through but by no means do I think you should focus on it at all. Past is past, and moving on is more important I would think.

I am all up for demos any day. I do them regurarly before bothering with many say web, productivity, architecture, including hu ha nhibernate based solutions and more, and usually they all fall apart rapidly. Or they do not provide anything that was not possible before, even in 'low-level' languages.

Yet if you look at their licencing costs it is tragic to find out most of the work was ripped from Code Project in fact. And often not even polished.. It is hard to find good and elegant and economic 'components', it is even harder to find time/money-saving solutions, and hardest to find the work done with true love.

So I would be more than happy to view it and even recommend it for what I perceive your work is suitable for. You are not far away from us and UK is flourishing in this space.

My point being there is always plenty of web, workflow, documentation and integration work to be done, that is what this industry has become. Not many people go back to the roots and bother, new generation is in that assumes only their software will hammer the machine to the max. Even big vendors do that.

You might argue the business side is more ruthless than before, but so there is plenty of tech discussion not focusing on making money (architecture this that, enterprise library, best practices, Folwerism, rest, xml and clr overbloat and more). If it was all that simple and guidance did what it was almost claiming to do, then we would probably not see such fragility or expenses or support costs or fragmentation.

Thus I believe if the product is not build with that integratation feature from the outset then the only overlap clients will find is 'bits and pieces' approach to save development (people cost, pro-buy over build) time. And that can work too, it does although not as good from what I have seen or been told about.

And for the record, I really like the way you think, styling the article aside (and they are never discussed right? Smile | :)

I mean, I like the minimalistic approach you take on, and the reason I bothered with the article is because you said it yourself early on: ajaxiamisms, clr-isms and more are always too cumbersome for the task you need done. They often make it more complex than simple, introduce complexity we do not need, and a huge penalty for the enivornment or solution they are aiming at.

I will contact you offline to get a picture of your past work, what it was done in, how easy it is to connect to other systems. Why not? I have seen enough in this article and your explanation to know you have the 'anger' to do better than most. But imagine something does come out of it, we would prefer to focus on technical detail and integration features to immediatelly satisfy business needs rather than 'oh but this idea is real cool', 'it is worth more than xxxx' etc.

And that is the type of people you want to work with, not the cut and paste hackers, megalo-abstractionists, or every latest framework release hurd followers. Hope you see where my comment was coming from and what it was aiming at, it was not at all directed at you.

And your reply to that provocation of mine was very professional.

When you are ready..
GeneralRe: The idea is not new ;))) Pin
John Doherty15-May-07 9:06
John Doherty15-May-07 9:06 
GeneralRe: The idea is not new ;))) [modified] Pin
User of Users Group16-May-07 10:55
User of Users Group16-May-07 10:55 
QuestionPerformance issues? Pin
Thomas Lykke Petersen9-May-07 0:26
Thomas Lykke Petersen9-May-07 0:26 
AnswerRe: Performance issues? [modified] Pin
John Doherty10-May-07 8:39
John Doherty10-May-07 8:39 
QuestionDid you can provide a source code? Pin
knoami24-Apr-07 4:56
knoami24-Apr-07 4:56 
AnswerRe: Did you can provide a source code? Pin
John Doherty24-Apr-07 5:06
John Doherty24-Apr-07 5:06 
GeneralRe: Did you can provide a source code? Pin
getemerson20-Jul-09 22:24
getemerson20-Jul-09 22:24 
GeneralRe: Did you can provide a source code? Pin
John Doherty23-Jul-09 5:59
John Doherty23-Jul-09 5:59 
GeneralVery smart indeed! Pin
chaygavvara24-Apr-07 2:01
chaygavvara24-Apr-07 2:01 
Generalnice thought Pin
Niiiissssshhhhhuuuuu23-Apr-07 17:51
Niiiissssshhhhhuuuuu23-Apr-07 17:51 
GeneralInteresting idea... Pin
daluu23-Apr-07 13:07
daluu23-Apr-07 13:07 
GeneralRe: Interesting idea... [modified] Pin
John Doherty24-Apr-07 0:39
John Doherty24-Apr-07 0:39 
GeneralRe: Interesting idea... [modified] Pin
Jabez_Azariah20-Aug-18 23:43
Jabez_Azariah20-Aug-18 23:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.