Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Chris Beardsley
Added: Aug 31, 2018 7:41 AM
Views: 8
Tags: no tags
  1. function(){
  2. if(sessionStorage.getItem('timeSpent') == null){
  3. sessionStorage.setItem('timeSpent', 0);
  4. }
  5.  
  6. var currentValue = parseInt(sessionStorage.getItem('timeSpent'), 10);
  7. var timer = setInterval(function(){
  8.         if(currentValue < 10){
  9.                 currentValue++;
  10.                 sessionStorage.setItem('timeSpent', currentValue);
  11.                 consolelog(currentValue);  //Remove line if used - only used to validate function
  12.         }
  13.         else{
  14.                 dataLayer.push({
  15.                         'event':'engangement'
  16.                 });
  17.                 clearInterval(timer);
  18.         }
  19. }, 1000);
  20. }
  21.