[Simplified] Calculating time on page in GA?
Time on a page is a very valuable metric for any organization as it helps identify how much time user spent on the website. This is very important for R&D of any business.
Unlike what some of us might think, Google does not have any timer to calculate user’s time on page. The standard calculation of time is done based on the timestamp that are sent to Google Analytics when the user interacts with the website. The difference of these timestamps is calculated to find the required time on page.
Suppose a user visits a website with 3 web pages: page A > page B > page C. Below is the table for their interaction with the website.

Google analytics captures these timestamps and uses their difference to calculate the time that the user spent on each page. In the above case:
Time on page A= 14 minutes.
Time on page B= 5 minutes.
Time on page C= 0 minutes (the user closed the website from page C, hence no time stamp was sent to google from it.)
Having said that, the question is- how can you track the time on page for a single page website or for the last page of the website?
If the user exits your website from page A itself after reading the content, then the total session duration will be 0 seconds no matter how much time user spent on the page and the bounce rate will be 100%. To avoid this anomaly in data, Google analytics provides us custom metrics to send custom hits after a predefined period (all the hits can be checked on dataslayer-a chrome extension, more about it in the upcoming blogs). We can send a custom hit after every 30 seconds or 60 seconds etc. This will tell us the real stats of the user interaction with the website and how much time they really spend on the page. The custom hit is implemented using a JavaScript code that runs after every 30 seconds (for example) as long as the web page is open, thus giving the required Metrics.
The implementation of custom hits depends on the type of website. If the website is content based and the user is required to spend time reading the content, then customised hits must be sent, else if it is a product or service-based website(E-commerce website) where the user is required to complete a goal or conversion funnel(purchase a product), default timestamp is recommended.
Fun Fact: Google analytics keeps on tracking your visit even after you close a website. Your session only ends after 30 minutes of inactivity. So, in the above scenario if you were to close the website from page C and open it again before 11:50am (because the last timestamp sent was at 11:20am), your session will continue.