Google Analytics calculates the average time on page by dividing the total amount of time that users spend on a particular page by the number of users who visited that page. To calculate the total amount of time that users spend on a page, Google Analytics tracks the time at which a user first lands on the page and the time at which the user navigates away from the page. The difference between these two times is considered to be the amount of time that the user spent on the page. The average time on page is then calculated by dividing this total amount of time by the number of users who visited the page.
It's important to note that Google Analytics may not always accurately track the time that a user spends on a page. For example, if a user leaves a page open in their browser and goes away from their computer for a long period of time, the time that they are away from the computer will not be included in the average time on page calculation. Additionally, if a user closes their browser or navigates away from the page before the Google Analytics tracking code has a chance to run, the time that they spent on the page will not be recorded.
Additionally, Google Analytics also calculates average time on page differently for the last page a user visits during a session. Since there is no next page to track the time until the user leaves the website, Google Analytics assumes a default session timeout of 30 minutes for this page. So, if a user spends 10 minutes on the last page they visit, Google Analytics will record it as 10 minutes rather than the full session timeout of 30 minutes.