title: Send google analytics event when time on page goes over 30 seconds
body: <p>I have a client with a 1 page website. He'd like to track people who have spent more than 30 seconds on the page as a goal completion. </p>
  
  <p>I was thinking I could use javascript to count the time on page and when it goes over 30 seconds trigger the an analytics event.  </p>
  
  <p>I'm fairly unfamiliar with javascript but I did come across this simple counter which counts up from 0 on page load.</p>
  
  <pre><code> &lt;script type="text/javascript"&gt;
      var minutesLabel = document.getElementById("minutes");
      var secondsLabel = document.getElementById("seconds");
      var works = document.getElementById("works");
      var totalSeconds = 0;
      setInterval(setTime, 1000);
  
      function setTime()
      {
          ++totalSeconds;
          secondsLabel.innerHTML = pad(totalSeconds%60);
          minutesLabel.innerHTML = pad(parseInt(totalSeconds/60));
      }
  
      function pad(val)
      {
          var valString = val + "";
          if(valString.length &lt; 2)
          {
              return "0" + valString;
          }
          else
          {
              return valString;
          }
      }   
  &lt;/script&gt;
  </code></pre>
  
  <p>Is there some way I have have it send the event below when the "totalSeconds" hits 30? </p>
  
  <pre><code>onClick="ga('send', 'event', 'time on page', 'over 30 seconds');"
  </code></pre>
  
  <p>thanks!</p>