I integrated the JS timeonsite library timeonsitetracker.js in web page as given in document,
<script type="text/javascript">
var Tos;
(function(d, s, id, file) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s);
js.id = id;
js.onload = function() {
var config = {
trackBy: 'seconds',
developerMode: true
};
if(TimeOnSiteTracker) {
Tos = new TimeOnSiteTracker(config);
}
};
js.src = file;fjs.parentNode.insertBefore(js, fjs);
} (document, 'script', 'TimeOnSiteTracker', '//cdn.jsdelivr.net/gh/saleemkce/timeonsite@1.1.0/timeonsitetracker.min.js'));
</script>
After calling the Tos object,
Tos.getTimeOnPage();
{
TOSId: 13650383319214852
TOSSessionKey: "6606159448467693493359"
TOSUserId: "anonymous"
URL: "https://localhost/index.html"
currentTime: "2020-07-11 16:25:17.908"
entryTime: "2020-07-11 16:24:36.911"
timeOnPage: 41
timeOnPageByDuration: "0d 00h 00m 41s"
timeOnPageTrackedBy: "second"
timeOnSite: 0
timeOnSiteByDuration: "0d 00h 00m 00s"
title: "real-time demo"
trackingType: "tos"
}
On calling the Tos.getTimeOnPage() API, I see the "timeOnSite" always "0" but timeOnPage updates periodically. But on refreshing the page, I get the updated timeOnPage, timeOnSite in DB saved automatically by tracker. Is there a way to get the real-time "timeonsite" param on page without refreshing the whole page as given in demo page?