Linc Abela
Linc Abela

Reputation: 815

AngularJS: Track the time spent in the web app then trigger an event on specific time

I want to track the time the user use the website and then I need to raise an event when the user have been on the site for 30 seconds. Any idea on how to do this?

Upvotes: 0

Views: 540

Answers (2)

4UmNinja
4UmNinja

Reputation: 540

where's the code? ..

heres an example without angular code, but feel free to use a $timeout and drop it inside of your app.run if you want it algularized.

// This event starts watching when document loads
// Any special event can work to trigger this instead

$(document).ready(function(){
    var countdown = 30000;

    // 30 Second  Event
    function thirty_second_event() {
        console.log("it's been " + (countdown/1000) + " seconds");
    }
    // Start the timer
    setTimeout( thirty_second_event, countdown );
});

Upvotes: 1

Paul Fitzgerald
Paul Fitzgerald

Reputation: 12129

Why not use Angular's built in $timeout

$timeout(function raiseEvent(){
   //do something here
}, 30000)

Upvotes: 2

Related Questions