Is there a proven method/demo that shows how to log (track) the position of a scroll/mouse on a page, so one can determine how far down a salesletter a user goes, before they leave?

I can pass data upon the exit, and even send it to a db every second if need be. I just need to learn how to GRAB such a value in the first place.

How would one do this?

Thank you