Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: user5f44c
Added: Jul 22, 2020 11:36 AM
Views: 24
Tags: no tags
  1. <script>
  2. (function(){
  3.   function resetStartTime() {
  4.   startTime = new Date();
  5.   window.sessionStorage.setItem('startTime', startTime);
  6.   return startTime;
  7. }
  8.   // get timestamp
  9.   startTime = new Date(window.sessionStorage.getItem('startTime') || resetStartTime());
  10.   // start timer
  11. window.setInterval(function() {
  12.     var secsDiff = new Date().getTime() - startTime.getTime();
  13.     var myTimer = Math.floor(secsDiff / 1000);
  14.     if(myTimer == 10){
  15.             dataLayer.push({'event':'timer reached'});
  16.                   }
  17.     else window.clearInterval()
  18.   }, 1000);
  19. })
  20.  ();
  21. </script>