0

I am building a website with react and node. I have to track clicks in entire document and check if the previous click happened less then 2 minute.

2 Answers 2

1
 class ClickTracker extends Component {
   trackClick(e){

   }

   componentWillMount() {
     document.addEventListener('click', this.trackClick); 
   }

   componentWillUnmount() {
     document.removeEventListener('click', this.trackClick);
   }

   render(){
     return (
         {this.props.children}
     );
   }
 }

Sign up to request clarification or add additional context in comments.

Comments

0

var last = new Date().getTime();

window.addEventListener('click', function(event) {

  var now = new Date().getTime();

  console.log(event.pageX, event.pageY);

  console.log(now-last);

  console.log((now-last) / 1000);

  if ( (now-last) < 2 * 60 * 1000 ) {
    console.log('clicked less than two minutes ago');
  }

  last = now;

});

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.