/Development Idle Timeout w/ Angular JS

A client was concerned about keeping users on the site, and wanted a way to “shout” a call-to-action be if the user was about to leave the site. The call-to-action could be some text, or a video, or a form, the client wasn’t sure what would work.

I see this kind of thing on blogs all the time, and wondered to do it. Particularly, how do I anticipate the user leaving the site?