Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mouselog

Package Overview
Dependencies
Maintainers
2
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mouselog - npm Package Compare versions

Comparing version 0.0.7-beta1 to 0.0.7-beta2

config.js

41

index.js
const uuidv4 = require('uuid/v4');
const Uploader = require('./uploader');
let { config, buildConfig } = require('./config');
// default config
let config = {
// Set upload mode: "periodic" or "event-triggered"
uploadMode: "periodic",
// If `uploadMode` == "periodic", data will be uploaded every `uploadPeriod` ms.
// If no data are collected in a period, no data will be uploaded
uploadPeriod: 5000,
// If `uploadMode` == "event-triggered"
// The website interaction data will be uploaded when every `frequency` events are captured.
frequency: 50,
// The website interaction data will be encoded by `encoder` before uploading to the server.
encoder: JSON.stringify,
// The response data will be decoded by `decoder`
decoder: x => x,
// Use GET method to upload data? (stringified data will be embedded in URI)
enableGET: false,
// Time interval for resending the failed trace data
resendInterval: 3000
};
let targetEvents = [

@@ -134,17 +113,8 @@ "mousemove",

uploadIdx = 0;
uploader.start(
serverUrl,
websiteId,
impressionId,
config
);
uploader.start(impressionId);
}
export function run(_serverUrl, _websiteId, options) {
if (options) {
config = options;
}
serverUrl = _serverUrl;
websiteId = _websiteId;
export function run(params) {
buildConfig(params);
impressionId = uuidv4();

@@ -162,3 +132,2 @@ refresh();

uploadInterval = setInterval(() => {
console.log("here");
if (eventsList.length != 0) {

@@ -165,0 +134,0 @@ uploadTrace();

@@ -127,26 +127,5 @@ (function webpackUniversalModuleDefinition(root, factory) {

const Uploader = __webpack_require__(5);
let { config, buildConfig } = __webpack_require__(6);
// default config
let config = {
// Set upload mode: "periodic" or "event-triggered"
uploadMode: "periodic",
// If `uploadMode` == "periodic", data will be uploaded every `uploadPeriod` ms.
// If no data are collected in a period, no data will be uploaded
uploadPeriod: 5000,
// If `uploadMode` == "event-triggered"
// The website interaction data will be uploaded when every `frequency` events are captured.
frequency: 50,
// The website interaction data will be encoded by `encoder` before uploading to the server.
encoder: JSON.stringify,
// The response data will be decoded by `decoder`
decoder: x => x,
// Use GET method to upload data? (stringified data will be embedded in URI)
enableGET: false,
// Time interval for resending the failed trace data
resendInterval: 3000
};
let targetEvents = [

@@ -259,17 +238,8 @@ "mousemove",

uploadIdx = 0;
uploader.start(
serverUrl,
websiteId,
impressionId,
config
);
uploader.start(impressionId);
}
function run(_serverUrl, _websiteId, options) {
if (options) {
config = options;
}
serverUrl = _serverUrl;
websiteId = _websiteId;
function run(params) {
buildConfig(params);
impressionId = uuidv4();

@@ -287,3 +257,2 @@ refresh();

uploadInterval = setInterval(() => {
console.log("here");
if (eventsList.length != 0) {

@@ -421,4 +390,6 @@ uploadTrace();

/* 5 */
/***/ (function(module, exports) {
/***/ (function(module, exports, __webpack_require__) {
let {config} = __webpack_require__(6);
let StatusEnum = {

@@ -437,16 +408,9 @@ FAILED: -1,

start(serverUrl, websiteId, impressionId, options) {
this.serverUrl = serverUrl;
this.websiteId = websiteId;
start(impressionId) {
this.impressionId = impressionId;
// Resend all the failed data in this.buf every `resendInterval` ms
let resendInterval = options.resendInterval ? options.resendInterval : 3000;
this.resendInterval = setInterval(()=>{
this.resendFailedData.call(this);
}, resendInterval);
}, config.resendInterval);
this.enableGET = options.enableGET ? options.enableGET : false;
this.encoder = options.encoder ? options.encoder : JSON.stringify;
this.decoder = options.decoder ? options.decoder : x=>x;
this.enable = true;

@@ -480,5 +444,5 @@ }

_getUploadPromise(encodedData) {
if (this.enableGET) {
if (config.enableGet) {
return new Promise((resolve, reject) => {
fetch(`${this.serverUrl}/api/upload-trace?websiteId=${this.websiteId}&impressionId=${this.impressionId}&data=${encodedData}`, {
fetch(`${config.absoluteUrl}/api/upload-trace?websiteId=${config.websiteId}&impressionId=${this.impressionId}&data=${encodedData}`, {
method: "GET",

@@ -490,3 +454,3 @@ credentials: "include"

return new Promise((resolve, reject) => {
fetch(`${this.serverUrl}/api/upload-trace?websiteId=${this.websiteId}&impressionId=${this.impressionId}`, {
fetch(`${config.absoluteUrl}/api/upload-trace?websiteId=${config.websiteId}&impressionId=${this.impressionId}`, {
method: "POST",

@@ -502,3 +466,3 @@ credentials: "include",

obj.status = StatusEnum.SENDING;
let encodedData = this.encoder(obj.data);
let encodedData = config.encoder(obj.data);
this._getUploadPromise(encodedData)

@@ -522,4 +486,100 @@ .then(res => {

/***/ }),
/* 6 */
/***/ (function(module, exports) {
// Default config
let config = {
// Type: string, REQUIRED
// Endpoint Url
uploadEndpoint: "http://localhost:9000",
// Type: string
// Website ID
websiteId: "unknown",
// Endpoint type, "absolute" or "relative"
endpointType: "absolute",
// upload protocol, "https" or "http"
// If you declare it in `uploadEndpoint`, this property will be ignored.
uploadProtocol: "https",
// Upload mode, "periodic" or "event-triggered"
uploadMode: "periodic",
// Type: number
// If `uploadMode` == "periodic", data will be uploaded every `uploadPeriod` ms.
// If no data are collected in a period, no data will be uploaded
uploadPeriod: 5000,
// Type: number
// If `uploadMode` == "event-triggered"
// The website interaction data will be uploaded when every `frequency` events are captured.
frequency: 50,
// Type: function
// The website interaction data will be encoded by `encoder` before uploading to the server.
encoder: JSON.stringify,
// Type: function
// The response data will be decoded by `decoder`
decoder: x => x,
// Type: bool
// Use GET method to upload data? (stringified data will be embedded in URI)
enableGet: false,
// Type: number
// Time interval for resending the failed trace data
resendInterval: 3000,
}
// ----------------------------
let requiredParams = [
"uploadEndpoint",
];
let buildConfig = (params) => {
requiredParams.forEach(key => {
if (!(key in params)) {
throw new Error(`Param ${key} is required but not declared.`);
}
});
Object.keys(params).forEach(key => {
config[key] = params[key];
});
config.absoluteUrl = formatUrl();
}
let formatUrl = () => {
let url = config.uploadEndpoint
if (config.endpointType == "relative") {
// Format the head -> "/*"
if (url.startsWith("./")) {
url = url.slice(1);
} else if (url[0] !== "/") {
url = `/${url}`;
}
// Format the tail
if (url[url.length-1] === "/") {
url = url.slice(0, url.length-1);
}
// Construct absolute URL
url = `${config.uploadProtocol}://${window.location.hostname}${url}`;
} else if (config.endpointType == "absolute") {
if (!(url.startsWith("http://") || url.startsWith("https://"))) {
url = `${config.uploadProtocol}://${url}`;
}
} else {
throw new Error('`endpointType` can only be "absolute" or "relative"');
}
return url;
}
module.exports = { config, buildConfig }
/***/ })
/******/ ]);
});

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.mouselog=t():e.mouselog=t()}(window,(function(){return function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){let o=n(1);e.exports={run:function(e,t,n){o.run(e,t,n)},stop:function(){o.stop()}}},function(e,t,n){"use strict";n.r(t),n.d(t,"refresh",(function(){return g})),n.d(t,"run",(function(){return v})),n.d(t,"stop",(function(){return w}));const o=n(2),r=n(5);let i,s,a,u,d,l,c,p={uploadMode:"periodic",uploadPeriod:5e3,frequency:50,encoder:JSON.stringify,decoder:e=>e,enableGET:!1,resendInterval:3e3},f=["mousemove","mousedown","mouseup","mouseclick","dblclick","contextmenu","wheel","torchstart","touchmove","touchend"],h=new r;function m(){let e=new Date-d;return Math.trunc(e)/1e3}function b(e=!1){let t=function(){let e={id:"0",idx:l,url:window.location.hostname?window.location.hostname:"localhost",path:window.location.pathname,width:document.body.scrollWidth,height:document.body.scrollHeight,pageLoadTime:d,label:-1,guess:-1,events:[]};return l+=1,e}();e||(t.events=u,u=[]),h.upload(t)}function y(e){if("contextmenu"===e.type&&0===e.pageX&&0===e.pageY)return;let t=e.pageX,n=e.pageY;void 0===t&&(t=e.changedTouches[0].pageX,n=e.changedTouches[0].pageY);let o={id:u.length,timestamp:m(),type:e.type,x:t,y:n,button:(r=e.button,"2"===r?"Right":"")};var r;"wheel"==e.type&&(o.deltaX=e.deltaX,o.deltaY=e.deltaY),u.push(o),"event-triggered"==p.uploadMode&&u.length%p.frequency==0&&b()}function g(){u=[],d=new Date,l=0,h.start(s,a,i,p)}function v(e,t,n){n&&(p=n),s=e,a=t,i=o(),g(),f.forEach(e=>{window.document.addEventListener(e,e=>y(e))}),b(!0),"periodic"===p.uploadMode&&(c=setInterval(()=>{console.log("here"),0!=u.length&&b()},p.uploadPeriod)),onbeforeunload=e=>{0!=u.length&&b()}}function w(){f.forEach(e=>{window.document.removeEventListener(e,e=>y(e))}),clearInterval(c),h.stop()}},function(e,t,n){var o=n(3),r=n(4);e.exports=function(e,t,n){var i=t&&n||0;"string"==typeof e&&(t="binary"===e?new Array(16):null,e=null);var s=(e=e||{}).random||(e.rng||o)();if(s[6]=15&s[6]|64,s[8]=63&s[8]|128,t)for(var a=0;a<16;++a)t[i+a]=s[a];return t||r(s)}},function(e,t){var n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(n){var o=new Uint8Array(16);e.exports=function(){return n(o),o}}else{var r=new Array(16);e.exports=function(){for(var e,t=0;t<16;t++)0==(3&t)&&(e=4294967296*Math.random()),r[t]=e>>>((3&t)<<3)&255;return r}}},function(e,t){for(var n=[],o=0;o<256;++o)n[o]=(o+256).toString(16).substr(1);e.exports=function(e,t){var o=t||0,r=n;return[r[e[o++]],r[e[o++]],r[e[o++]],r[e[o++]],"-",r[e[o++]],r[e[o++]],"-",r[e[o++]],r[e[o++]],"-",r[e[o++]],r[e[o++]],"-",r[e[o++]],r[e[o++]],r[e[o++]],r[e[o++]],r[e[o++]],r[e[o++]]].join("")}},function(e,t){let n=-1,o=0,r=1,i=2;e.exports=class{constructor(){this.buf=[],this.enable=!1}start(e,t,n,o){this.serverUrl=e,this.websiteId=t,this.impressionId=n;let r=o.resendInterval?o.resendInterval:3e3;this.resendInterval=setInterval(()=>{this.resendFailedData.call(this)},r),this.enableGET=!!o.enableGET&&o.enableGET,this.encoder=o.encoder?o.encoder:JSON.stringify,this.decoder=o.decoder?o.decoder:e=>e,this.enable=!0}stop(){this.enable=!1,clearInterval(this.resendInterval)}upload(e){this.enable&&(this.buf.push({status:o,data:e}),this._uploadData(this.buf[this.buf.length-1]))}resendFailedData(){this.enable&&this.buf.forEach(e=>{e.status==n&&this._uploadData(e)})}_getUploadPromise(e){return this.enableGET?new Promise((t,n)=>{fetch(`${this.serverUrl}/api/upload-trace?websiteId=${this.websiteId}&impressionId=${this.impressionId}&data=${e}`,{method:"GET",credentials:"include"})}):new Promise((t,n)=>{fetch(`${this.serverUrl}/api/upload-trace?websiteId=${this.websiteId}&impressionId=${this.impressionId}`,{method:"POST",credentials:"include",body:e})})}_uploadData(e){e.status=i;let t=this.encoder(e.data);this._getUploadPromise(t).then(t=>{200==t.status?e.status=r:e.status=n}).catch(t=>{e.status=n,console.log(t)})}}}])}));
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.mouselog=t():e.mouselog=t()}(window,(function(){return function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){let o=n(1);e.exports={run:function(e,t,n){o.run(e,t,n)},stop:function(){o.stop()}}},function(e,t,n){"use strict";n.r(t),n.d(t,"refresh",(function(){return y})),n.d(t,"run",(function(){return g})),n.d(t,"stop",(function(){return w}));const o=n(2),r=n(5);let i,a,u,s,l,{config:d,buildConfig:c}=n(6),p=["mousemove","mousedown","mouseup","mouseclick","dblclick","contextmenu","wheel","torchstart","touchmove","touchend"],f=new r;function h(){let e=new Date-u;return Math.trunc(e)/1e3}function b(e=!1){let t=function(){let e={id:"0",idx:s,url:window.location.hostname?window.location.hostname:"localhost",path:window.location.pathname,width:document.body.scrollWidth,height:document.body.scrollHeight,pageLoadTime:u,label:-1,guess:-1,events:[]};return s+=1,e}();e||(t.events=a,a=[]),f.upload(t)}function m(e){if("contextmenu"===e.type&&0===e.pageX&&0===e.pageY)return;let t=e.pageX,n=e.pageY;void 0===t&&(t=e.changedTouches[0].pageX,n=e.changedTouches[0].pageY);let o={id:a.length,timestamp:h(),type:e.type,x:t,y:n,button:(r=e.button,"2"===r?"Right":"")};var r;"wheel"==e.type&&(o.deltaX=e.deltaX,o.deltaY=e.deltaY),a.push(o),"event-triggered"==d.uploadMode&&a.length%d.frequency==0&&b()}function y(){a=[],u=new Date,s=0,f.start(i)}function g(e){c(e),i=o(),y(),p.forEach(e=>{window.document.addEventListener(e,e=>m(e))}),b(!0),"periodic"===d.uploadMode&&(l=setInterval(()=>{0!=a.length&&b()},d.uploadPeriod)),onbeforeunload=e=>{0!=a.length&&b()}}function w(){p.forEach(e=>{window.document.removeEventListener(e,e=>m(e))}),clearInterval(l),f.stop()}},function(e,t,n){var o=n(3),r=n(4);e.exports=function(e,t,n){var i=t&&n||0;"string"==typeof e&&(t="binary"===e?new Array(16):null,e=null);var a=(e=e||{}).random||(e.rng||o)();if(a[6]=15&a[6]|64,a[8]=63&a[8]|128,t)for(var u=0;u<16;++u)t[i+u]=a[u];return t||r(a)}},function(e,t){var n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(n){var o=new Uint8Array(16);e.exports=function(){return n(o),o}}else{var r=new Array(16);e.exports=function(){for(var e,t=0;t<16;t++)0==(3&t)&&(e=4294967296*Math.random()),r[t]=e>>>((3&t)<<3)&255;return r}}},function(e,t){for(var n=[],o=0;o<256;++o)n[o]=(o+256).toString(16).substr(1);e.exports=function(e,t){var o=t||0,r=n;return[r[e[o++]],r[e[o++]],r[e[o++]],r[e[o++]],"-",r[e[o++]],r[e[o++]],"-",r[e[o++]],r[e[o++]],"-",r[e[o++]],r[e[o++]],"-",r[e[o++]],r[e[o++]],r[e[o++]],r[e[o++]],r[e[o++]],r[e[o++]]].join("")}},function(e,t,n){let{config:o}=n(6),r=-1,i=0,a=1,u=2;e.exports=class{constructor(){this.buf=[],this.enable=!1}start(e){this.impressionId=e,this.resendInterval=setInterval(()=>{this.resendFailedData.call(this)},o.resendInterval),this.enable=!0}stop(){this.enable=!1,clearInterval(this.resendInterval)}upload(e){this.enable&&(this.buf.push({status:i,data:e}),this._uploadData(this.buf[this.buf.length-1]))}resendFailedData(){this.enable&&this.buf.forEach(e=>{e.status==r&&this._uploadData(e)})}_getUploadPromise(e){return o.enableGet?new Promise((t,n)=>{fetch(`${o.absoluteUrl}/api/upload-trace?websiteId=${o.websiteId}&impressionId=${this.impressionId}&data=${e}`,{method:"GET",credentials:"include"})}):new Promise((t,n)=>{fetch(`${o.absoluteUrl}/api/upload-trace?websiteId=${o.websiteId}&impressionId=${this.impressionId}`,{method:"POST",credentials:"include",body:e})})}_uploadData(e){e.status=u;let t=o.encoder(e.data);this._getUploadPromise(t).then(t=>{200==t.status?e.status=a:e.status=r}).catch(t=>{e.status=r,console.log(t)})}}},function(e,t){let n={uploadEndpoint:"http://localhost:9000",websiteId:"unknown",endpointType:"absolute",uploadProtocol:"https",uploadMode:"periodic",uploadPeriod:5e3,frequency:50,encoder:JSON.stringify,decoder:e=>e,enableGet:!1,resendInterval:3e3},o=["uploadEndpoint"],r=()=>{let e=n.uploadEndpoint;if("relative"==n.endpointType)e.startsWith("./")?e=e.slice(1):"/"!==e[0]&&(e=`/${e}`),"/"===e[e.length-1]&&(e=e.slice(0,e.length-1)),e=`${n.uploadProtocol}://${window.location.hostname}${e}`;else{if("absolute"!=n.endpointType)throw new Error('`endpointType` can only be "absolute" or "relative"');e.startsWith("http://")||e.startsWith("https://")||(e=`${n.uploadProtocol}://${e}`)}return e};e.exports={config:n,buildConfig:e=>{o.forEach(t=>{if(!(t in e))throw new Error(`Param ${t} is required but not declared.`)}),Object.keys(e).forEach(t=>{n[t]=e[t]}),n.absoluteUrl=r()}}}])}));
{
"name": "mouselog",
"version": "0.0.7-beta1",
"version": "0.0.7-beta2",
"description": "The mouse tracking agent for Mouselog.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -13,5 +13,9 @@ [![NPM version](https://img.shields.io/npm/v/mouselog)](https://www.npmjs.com/package/mouselog)

```html
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/mouselog@0.0.7-beta1/mouselog.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/mouselog@latest/mouselog.js"></script>
<script>
mouselog.run("Your_Server_Url", "Your_Website_Id");
mouselog.run({
uploadEndpoint: "Your_Server_Url",
websiteId: "Your_Website_Id",
endpointType: "absolute"
});
</script>

@@ -23,5 +27,9 @@ ```

var script = document.createElement("script");
script.src = "https://cdn.jsdelivr.net/npm/mouselog@0.0.7-beta1/mouselog.js";
script.src = "https://cdn.jsdelivr.net/npm/mouselog@latest/mouselog.js";
script.onload = () => {
mouselog.run("Your_Server_Url", "Your_Website_Id");
mouselog.run({
uploadEndpoint: "Your_Server_Url",
websiteId: "Your_Website_Id",
endpointType: "absolute"
});
}

@@ -40,9 +48,37 @@ var t = document.getElementsByTagName("script");

Then load and configure mouselog
Then run Mouselog and it will automatically collect all you want.
```Javascript
const mouselog = require('mouselog');
let config = {
// Set upload mode: "periodic" or "event-triggered"
mouselog.run({
uploadEndpoint: "Your_Server_Url",
websiteId: "Your_Website_Id",
endpointType: "absolute"
});
```
You can also deactivate Mouselog by calling `mouselog.stop()`.
# Configuration
The default configuration:
```JSON
{
// Type: string
// Endpoint Url
uploadEndpoint: REQUIRED,
// Type: string
// Website ID
websiteId: "unknown",
// Endpoint type, "absolute" or "relative"
endpointType: "absolute",
// upload protocol, "https" or "http"
// If you declare it in `uploadEndpoint`, this property will be ignored.
uploadProtocol: "https",
// Upload mode, "periodic" or "event-triggered"
uploadMode: "periodic",
// Type: number
// If `uploadMode` == "periodic", data will be uploaded every `uploadPeriod` ms.

@@ -52,2 +88,3 @@ // If no data are collected in a period, no data will be uploaded

// Type: number
// If `uploadMode` == "event-triggered"

@@ -57,19 +94,19 @@ // The website interaction data will be uploaded when every `frequency` events are captured.

// Type: bool
// Use GET method to upload data? (stringified data will be embedded in URI)
enableGet: false,
// Type: function
// The website interaction data will be encoded by `encoder` before uploading to the server.
encoder: JSON.stringify,
// Type: function
// The response data will be decoded by `decoder`
decoder: x => x,
// Use GET method to upload data? (stringified data will be embedded in URI)
enableGET: false,
decoder: x => x,
// Type: number
// Time interval for resending the failed trace data
resendInterval: 3000
};
resendInterval: 3000,
}
```
Run Mouselog and it will automatically collect all you want.
```Javascript
mouselog.run("YOUR_SERVER_URL", "YOUR_WEBSITE_ID", config);
```
You can also deactivate Mouselog by calling `mouselog.stop()`.
# Demo

@@ -76,0 +113,0 @@ [Mouselog-demo](https://github.com/hsluoyz/mouselog-demo)

@@ -0,1 +1,3 @@

let {config} = require('./config');
let StatusEnum = {

@@ -14,16 +16,9 @@ FAILED: -1,

start(serverUrl, websiteId, impressionId, options) {
this.serverUrl = serverUrl;
this.websiteId = websiteId;
start(impressionId) {
this.impressionId = impressionId;
// Resend all the failed data in this.buf every `resendInterval` ms
let resendInterval = options.resendInterval ? options.resendInterval : 3000;
this.resendInterval = setInterval(()=>{
this.resendFailedData.call(this);
}, resendInterval);
}, config.resendInterval);
this.enableGET = options.enableGET ? options.enableGET : false;
this.encoder = options.encoder ? options.encoder : JSON.stringify;
this.decoder = options.decoder ? options.decoder : x=>x;
this.enable = true;

@@ -57,5 +52,5 @@ }

_getUploadPromise(encodedData) {
if (this.enableGET) {
if (config.enableGet) {
return new Promise((resolve, reject) => {
fetch(`${this.serverUrl}/api/upload-trace?websiteId=${this.websiteId}&impressionId=${this.impressionId}&data=${encodedData}`, {
fetch(`${config.absoluteUrl}/api/upload-trace?websiteId=${config.websiteId}&impressionId=${this.impressionId}&data=${encodedData}`, {
method: "GET",

@@ -67,3 +62,3 @@ credentials: "include"

return new Promise((resolve, reject) => {
fetch(`${this.serverUrl}/api/upload-trace?websiteId=${this.websiteId}&impressionId=${this.impressionId}`, {
fetch(`${config.absoluteUrl}/api/upload-trace?websiteId=${config.websiteId}&impressionId=${this.impressionId}`, {
method: "POST",

@@ -79,3 +74,3 @@ credentials: "include",

obj.status = StatusEnum.SENDING;
let encodedData = this.encoder(obj.data);
let encodedData = config.encoder(obj.data);
this._getUploadPromise(encodedData)

@@ -82,0 +77,0 @@ .then(res => {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc