0.1.3 • Published 6 months ago

user-behaviour-tracer v0.1.3

Weekly downloads
-
License
-
Repository
-
Last release
6 months ago

📝 Table of Contents

🧐 About

This Javascript Library allows to track user's behaviour by recording mouse activities:

  • Movements
  • Clicks
    • Exact element in CSS format
    • Time
  • Scroll
  • Time on page

🏁 Installation

There are two ways to include user-behaviour.js to your browser:

  1. jsDelivr CDN
<script src="https://cdn.jsdelivr.net/npm/user-behaviour-tracer/dist/index.min.js"></script>
  1. Local file
<script src="/path/to/user-behaviour-tracer.js"></script>

🔧 Configuration

The library requires a configuration object. Pass the object to the library with:

userBehaviour.config({.....});

If no configuration was passes the libray will use the default configuration:

{
    userInfo: true,
    clicks: true,
    mouseMovement: true,
    mouseMovementInterval: 1,
    mouseScroll: true,
    mousePageChange: true,
    keyLogger: false,
    contextChange: false,
    timeCount: true,
    clearAfterProcess: true,
    processTime: 15,
    processData: function(results){
        console.log(results);
    },
}
Config KeyDescriptionTypeDefault
userInforecord browser/device detailsbooltrue
clickstrack mouse clicksbooltrue
mouseMovementtrack mouse movementbooltrue
mouseMovementIntervaltime between tracking mouse movementsint (seconds)1
mouseScrolltrack mouse scrollbooltrue
mousePageChangetrack history changebooltrue
keyLoggertrack key upboolfalse
contextChangedocument visibility changeboolfalse
timeCounttrack timebooltrue
clearAfterProcessclear results object after processing the databooltrue
processTimetime between processing the data automatically (false will enable manual only data processing)int/bool (seconds)15
processDatafunction that processes the results objectfunction...

📚 Methods

This is a list of all available methods that can be called:

MethodDescriptionExample
showConfigreturns current configuserBehaviour.showConfig()
configsets the configurationuserBehaviour.config(config_object)
startstarts trackinguserBehaviour.start()
stopstops trackinguserBehaviour.stop()
showResultreturns current resultuserBehaviour.showResult()
processResultscalls the process function set in configuserBehaviour.processResults()

🚀 Tracking

Start tracking with:

userBehaviour.start();

Stop tracking with:

userBehaviour.stop();

🎈 Results

To view the results at anytime after the tracking has started:

userBehaviour.showResult();

The result will be passed to a function set regularly with an interval set in the configuration section.

The data could also be sent via a POST request using any HTTP request libraries e.g axios, ajax, ...

processData: function(results){
        axios.post('https://example.com', results);
}

If processTime was set to false, data will not be processed automatically. Therefore, you might require to process the data manually with:

userBehaviour.processResults();

This method will still require processData to be set in the configuration.

Example of Result

{
  "userInfo": {
    "appCodeName": "Mozilla",
    "appName": "Netscape",
    "vendor": "Google Inc.",
    "platform": "MacIntel",
    "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.87 Safari/537.36"
  },
  "time": {
    "startTime": 1572725042761,
    "currentTime": 1572725069204
  },
  "clicks": {
    "clickCount": 3,
    "clickDetails": [
      [
        {
          x: 554,
          y: 542,
          node: '<input type=\"text\" name=\"email\" placeholder=\"E-mail address\">',
          path: "html>body>div#login>div.ui.container.animated.fadeInDown>div.ui.center.aligned.colored.trends.segment>form.ui.form>div.fields>div.ten.wide.field>input",
          time: 1572725045313
        }
      ]
    ]
  },
  "mouseMovements": [
    [
      {
        x: 1031,
        y: 328,
        time:1572725043646
      }
    ]
  ],
  "mouseScroll": [],
  "keyLogger": [
        {
            "time": 1440001423813,
            "data": "a",
            "type": "keypress"
        },
    ],
     "contextChange": [
        {
            "time": 1440001429041,
            "type": "hidden"
        },
        {
            "time": 1440001436778,
            "type": "visible"
        },
    ],
}

🎉 Acknowledgements

0.1.3

6 months ago

0.1.2

6 months ago

0.1.1

6 months ago

0.0.2

6 months ago

0.0.1

6 months ago