Skip to content

Commit 146ed38

Browse files
TahaTaha
authored andcommitted
added userInfo option and better methods
1 parent f038470 commit 146ed38

File tree

3 files changed

+54
-20
lines changed

3 files changed

+54
-20
lines changed

README.md

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<h3 align="center">User Behaviour Tracking</h3>
2-
<h4 align="center">4.0 KB</h4>
2+
<h4 align="center">2.7 KB</h4>
33

44
<div align="center">
55

@@ -20,6 +20,7 @@
2020
- [About](#about)
2121
- [Installation](#install)
2222
- [Configuration](#config)
23+
- [Methods](#methods)
2324
- [Tracking](#tracking)
2425
- [Results](#results)
2526

@@ -55,6 +56,7 @@ userBehaviour.config({.....});
5556
If no configuration was passes the libray will use the default configuration:
5657
```javascript
5758
{
59+
userInfo: true,
5860
clicks: true,
5961
mouseMovement: true,
6062
mouseMovementInterval: 1,
@@ -67,18 +69,30 @@ If no configuration was passes the libray will use the default configuration:
6769
},
6870
}
6971
```
70-
| Config Key | Description | Type | Default | | |
71-
|-----------------------|----------------------------------------------------------------------------------------------------|--------------------|---------|---|---|
72-
| clicks | track mouse clicks | bool | true | | |
73-
| mouseMovement | track mouse movement | bool | true | | |
74-
| mouseMovementInterval | time between tracking mouse movements | int (seconds) | 1 | | |
75-
| mouseScroll | track mouse scroll | bool | true | | |
76-
| timeCount | track time | bool | true | | |
77-
| clearAfterProcess | clear results object after processing the data | bool | true | | |
78-
| processTime | time between processing the data automatically <br>(false will enable manual only data processing) | int/bool (seconds) | 15 | | |
79-
| processData | function that processes the results object | function | ... | | |
80-
81-
72+
| Config Key | Description | Type | Default |
73+
|-----------------------|----------------------------------------------------------------------------------------------------|--------------------|---------|
74+
| userInfo | record browser/device details | bool | true |
75+
| clicks | track mouse clicks | bool | true |
76+
| mouseMovement | track mouse movement | bool | true |
77+
| mouseMovementInterval | time between tracking mouse movements | int (seconds) | 1 |
78+
| mouseScroll | track mouse scroll | bool | true |
79+
| timeCount | track time | bool | true |
80+
| clearAfterProcess | clear results object after processing the data | bool | true |
81+
| processTime | time between processing the data automatically <br>(false will enable manual only data processing) | int/bool (seconds) | 15 |
82+
| processData | function that processes the results object | function | ... |
83+
84+
## 📚 Methods <a name="methods"></a>
85+
86+
This is a list of all available methods that can be called:
87+
88+
| Method | Description | Example |
89+
|----------------|------------------------------------------|-------------------------------------|
90+
| showConfig | returns current config | userBehaviour.showConfig() |
91+
| config | sets the configuration | userBehaviour.config(config_object) |
92+
| start | starts tracking | userBehaviour.start() |
93+
| stop | stops tracking | userBehaviour.stop() |
94+
| showResult | returns current result | userBehaviour.showResult() |
95+
| processResults | calls the process function set in config | userBehaviour.processResults() |
8296

8397
## 🚀 Tracking <a name = "tracking"></a>
8498

userBehaviour.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
/**
2+
* @author Taha Al-Jody <taha@ta3design.com>
3+
* https://github.com/TA3/web-user-behaviour
4+
*/
15
var userBehaviour = (function(){
26
var defaults = {
7+
userInfo: true,
38
clicks: true,
49
mouseMovement: true,
510
mouseMovementInterval: 1,
@@ -113,15 +118,15 @@ var userBehaviour = (function(){
113118
//PROCESS INTERVAL
114119
if(user_config.processTime !== false){
115120
mem.processInterval = setInterval(()=>{
116-
user_config.processData(results);
117-
if (user_config.clearAfterProcess) {
118-
resetResults();
119-
}
121+
user_config.processData(result());
120122
},user_config.processTime*1000)
121123
}
122124
};
123125
function processResults(){
124-
user_config.processData(results);
126+
user_config.processData(result());
127+
if (user_config.clearAfterProcess) {
128+
resetResults();
129+
}
125130
}
126131
function stop(){
127132
if(user_config.processTime !== false){
@@ -133,13 +138,24 @@ var userBehaviour = (function(){
133138
window.removeEventListener("mousemove", mem.eventsFunctions.mouseMovement);
134139
}
135140
function result(){
141+
if (user_config.userInfo === false && userBehaviour.showResult().userInfo !== undefined) {
142+
delete userBehaviour.showResult().userInfo;
143+
}
136144
if(user_config.time.timeCount !== undefined && user_config.time.timeCount){
137145
results.time.currentTime = getTimeStamp();
138146
}
139147
return results
140148
};
149+
function showConfig(){
150+
if (Object.keys(user_config).length !== Object.keys(defaults).length) {
151+
return defaults;
152+
}
153+
else{
154+
return user_config;
155+
}
156+
};
141157
return {
142-
showConfig: user_config,
158+
showConfig: showConfig,
143159
config: config,
144160
start: start,
145161
stop: stop,

userBehaviour.min.js

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)