I understand that Google uses 'Average Visit Duration' as one factor influencing ranking - but how does it determine how long a user has stayed on a certain page for? Is it as simple as registering when they left Google, then registering when clicked back? I can't think of any efficient way of measuring this.
How Time on Page is Calculated
Time on Page is calculated in two different ways. The calculation depends if the visit has one pageview OR if the visit has multiple pageviews.
When There are Multiple Pageviews in a Visit
This is pretty easy to understand.
If there are multiple pageviews during a visit then the time calculation is based on the >start time between the current page and the start time of the next page hit.
When There is Only One Pageview in the Visit
Most people believe that Google Analytics can not, and does not, calculate time on page when there is only one page viewed in a visit. This is partially correct.
If no other page is viewed during the visit, Google Analytics use the time between the initial page hit and the last engagement hit that follows the page hit.
I suggest that you go take a look a the Article it is very informative on how google calculte time(generaly) in thier Analytics services
Once I did my own data analytics to fit a customer needs. Then, I face your question: how to determine how long the user stayed on a site. Better, how to determine when the user leaves your site.
From the experience I had on this project, I believe google just do an estimative when the user leaves the last viewed page. Although you can use js events like onbeforeunload, onunload, they are no reliable and, sometimes, even dangerous. We know Google does not use them, since we see not network activity when we leave any page.
Now, to estimate the time a user stayed in a site is easy. For example, if a user has entered in a site and has viewed 3 pages. Is very easier to know when the user has started viewing the page. You may know if he left a previous page after the last interaction or when he opened a new page. But it's very difficult to determine when he leaves the last page. But, doing a estimative is simple. If he stayed 30 seconds on the first two pages, probably he stayed around 30 seconds on the last page as well. Total: 1:30.
If the Google searcher goes back to SERP and clicks a result of out it then Google can know how much time was spent in the site visited in the last click. It can average from 100's of visitors reaching that web page through SERP.
If visitors find solution in a click and don't search the same keywords back again in Google then Google can assume that satisfactory solution was found in the site reached from SERP. This should be the prime factor in site rankings.