Coder Social home page Coder Social logo

condor's Introduction

condor

Track what a user does on a site in csv-format

NPM

NPM

Sauce Test Status

Example

See the example folder for examples of how to use condor.

Usage

var xhr = require('xhr')
  , track = require('../condor')({
        // default 500ms
        // set for how long time scroll & resize events should be
        // [debounced](https://www.npmjs.org/package/debounce)
        // The `duration`-attribute is the last of these events.

        debounceTime: 300
    })

  , noop = function () {}

track.onevent = function (csv) {
  // this callback is called everytime an event happens
  // the data is a line of csv, see below for information on the format of the
  // csv
  xhr({
      method: 'POST'
    , body: csv
    , uri: '/track'
  }, noop)
}

// this gets called by beforeunload - so anything in here must be synchronous
track.onend = function (csv) {
  // this will be an end-event - meaning that the visit on the page has ended
  xhr({
      method: 'POST'
    , body: csv
    , uri: '/track'
    , sync: true
  }, noop)
}

The callback to '/track' gets called everytime a trackable event occur. csv is the data about the event (see data-format for details).

Csv format

Track is done in csv that corresponds to the following headers:

clientName,clientVersion,eventName,windowWidth,windowHeight,scrollX,scrollY,location,duration,referrer,path,clickX,clickY,href,target,visibility,name,trackableType,trackableValue,visitor,session

If not explicitly written out, the columns are always included (when available). For example, there's always a column describing the width of the window and if a referrer exists that's also always included in the events.

  • clientName Always set to 'condor' so you can easily identify condor logs
  • clientVersion The version of condor that generated the CSV
  • eventName Describes what event that has occured. Is one of the following:
    • load Emitted when the page has loaded (window.onload)
    • resize Emitted everytime a user resize the window (window.onresize). All resizing within 500ms are tracked as one resize-event.
    • scroll Emitted everytime a user scroll. All scrolling within 500ms is tracked as one scoll-event.
    • visibility Event describing if the page is visible or not. The initial visibility (when the script was loaded) will have duration 0.
    • change Emitted when a user changes a form (document.onchange)
    • click Emitted when a user clicks on the page
    • end Emitted when a user ends its session on a page, e.g. closes the window or click on a link.
    • trackable-load, trackable-visible, trackable-hover, trackable-click These events handles dom-elements with special data-trackable-type and data-trackable-value attributes.
      • trackable-load On load each trackable element is logged with this event
      • trackable-visible Event emitted when a trackable gets visible, e.g. when a user scroll enough to show a trackable element
      • trackable-hover Event emitted when a user hover over a trackable element.
      • trackable-click Event emitted when a user click on a trackable element.
  • windowWidth The width of the users window (Number in px)
  • windowHeight The height of the users window (Number in px)
  • scrollX How far the user has scrolled (horizontally)
  • scrollY How far the user has scrolled (vertically)
  • location The page the user is on (window.location)
  • duration Time (in ms) that has gone by since tracking was initiated
  • timestamp The time when the event happened (date.toUTCString())
  • timezone The timezone (in minutes) the user is in (date..getTimezoneOffset())
  • referrer The referrer header (document.referrer)
  • path The css-path describing the DOM-element (if available). For click events this is the element clicked, for change events this is the element changed. For trackable-* events this is the trackable element.
  • clickX The x-coordinate on the page that was clicked (event.pageX). Only applicable for click events.
  • clickY The y-coordinate on the page that was clicked (event.pageY). Only applicable for click events.
  • href The href-attribute on the a DOM-element associated with the DOM-element that was clicked. Only applicable for click events.
  • target The target-attribute on the a DOM-element associated with the DOM-element that was clicked. Only applicable for click events.
  • visibility String describing if the page was visible or not. Can be one of visible or hidden. Only applicable for visibility events.
  • name The name-attribute on the DOM-element that was changed. Only applicable for change events.
  • trackableType For trackable-* events this is the string from the data-trackable-type attribute.
  • trackableValue For trackable-* events this is the string from the data-trackable-value attribute
  • visitor A string that uniquely identifies a visitor
  • session The number of all-time sessions for this visitor. This value is incremented after 30 minutes of inactivity.

condor's People

Contributors

dey-dey avatar dominictarr avatar heapwolf avatar kesla avatar ralphtheninja avatar will123195 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

condor's Issues

Unite initial visibility with onfocus & onblur

We want to unite initial visibility, focus and blur events into a visibility event.

The initial visibility would then be a visibility that happens at the offset 0.

For this to work a polyfill for older browsers would need to be created.

visible time elapsed

I'm seeing quite large values for duration, i figure because people leave tabs open,
so what would be more meaningful is how long someone actually spends looking at a page,
therefore we should have visible-duration column, which is a timer that would be paused when the page is hidden.

Secure tracking

We need to figure out a way to make sure that other people can't send in bogus data to our tracking stream.

lots of scroll data

I think we should reduce the amount of scroll data collected. Perhaps, we can send the max-Y that was scrolled to instead of every scroll action.

image

Also:

  • 7,030 load events vs 7,141 end events -- why the discrepancy?

add max-scroll column(s)

The ability to create a scroll distance heatmap would be much easier if the end event contained the max scroll distance.

Batching data & timestamp on server

In the example we're now batching up data and sendning multiple events in one POST request.
However, we also want to be able to set correct timestamps on each event in the sever, something that isn't duable when we batch data up like this.

Track arbitrary data

In some cases we will want to track arbitrary data, this could be contained in a data attribute (ie: data-trackable="...").

Tests are faling

They're not only failing, they don't seem to be run correctly at all. I need to investigate what's up with that.

Ability to push trackable-custom events

Currently we can't push custom events.

My idea is to add a "trackable-custom" event type and expose a condor.log() method.

For example, after a Facebook share is completed:

function onShare() {
  // push trackable-custom event
  var trackableType = 'fb-share'
  var trackableValue = 'articleId:12345'
  condor.log(trackableType, trackableValue)
}

which would post:

trackable-custom,1280,855,0,4107,...,fb-share,articleId:12345

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.