Code Monkey home page Code Monkey logo

dejavu's Introduction

Collect website user activity data and index it into Splunk

This demo shows interaction of a client side agent running in a browser and Splunk server. There is a single page website in agent/index.html that implements a minimalistic tictactoy game. This page loads a javascript agent that traps usera activity events and posts them to Splunk using HTTP Event Collector. Javascript agent is included with a single line at the begining of index.html:

<script src="./dejavu.js"></script>

For the sake of simplicity only mousedown and mouseup events are handled in our browser client. Adding more event handlers is very simple. For instance one may trap mousemove events using the code below:

    document.addEventListener('mousemove', function(event) {
        postEventToSplunk({
            type: event.type,
            info: {
                x: event.x,
                y: event.y,
                button: event.buttons != undefined ? event.buttons : event.which
            }
        });
    });

Splunk HTTP event collector supports "batching" (i.e., merge multiple pieces of input data into a single chunk). It's strongly recommended to use batching for mousemove because it produces huge number of individual events.

Due to restrictions of cross-site scripting limitations it's less convenient to send data to Splunk server directly. Instead javascript code posts events to a "proxy" located on the same server. agent/dejavu.php is our simple proxy that resends it's input to Splunk server.

In our tictactoy demo every gameboard cell has its own id that is composed of cell column and row. Browser agent traps user clicks and they immediately become available in Splunk in form of json entities. For example click in the middle of the gameboard is indexed as:

{
  "type": "mousedown",
  "info": {
    "x": 138,
    "y": 136,
    "target": {
      "id": "(1,1)",
      "class": "class: (1,1)"
    }
  }
}

License

The MIT License (MIT)

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

dejavu's People

Contributors

oizmerly avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.