PHP Classes

File: assets/js/components/lib/MouseMovementTracker.js

Recommend this page to a friend!
  Classes of Rodrigo Faustino   Web App Multi-Perfil   assets/js/components/lib/MouseMovementTracker.js   Download  
File: assets/js/components/lib/MouseMovementTracker.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Web App Multi-Perfil
App that uses CRUD to manage multiple users
Author: By
Last change:
Date: 1 month ago
Size: 1,697 bytes
 

Contents

Class file image Download
import BuscaApi from './BuscaApiG.js'; export default class MouseMovementTracker { constructor() { this.buscaApi = new BuscaApi(sessionStorage.getItem('token')); this.isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); this.screenSize = { width: window.innerWidth, height: window.innerHeight }; this.mouseMovements = []; this.visitorId = this.generateUniqueId(); } init() { document.addEventListener('DOMContentLoaded', () => { document.addEventListener('mousemove', this.handleMouseMove.bind(this)); setInterval(() => this.sendDataToServer(), 33000); }); } handleMouseMove(event) { this.mouseMovements.push({ x: event.pageX, y: event.pageY, time: Date.now(), visitor_id: this.visitorId, isMobile: this.isMobile, screenSize: this.screenSize }); if (this.mouseMovements.length >= 50) { this.mouseMovements.shift(); } } async sendDataToServer() { if (this.mouseMovements.length > 0) { try { const response = await this.buscaApi.fetchApi('Analitico', 'POST', this.mouseMovements); console.log('Success:', response); } catch (error) { console.error('Error:', error); } this.mouseMovements = []; } } generateUniqueId() { return 'visitor-' + Math.random().toString(36).substr(2, 9); } } const mouseTracker = new MouseMovementTracker(); mouseTracker.init();