Thanks for the hint. I did search with the suggested term in community and found couple of your's comments and reference links.
To use 'Visibility API' was a valid suggestion. I have come up with a working code (with help of some other resources and code snippets) that suffice my requirement.
Following is the working code. Hope it helps somebody having similar requirement. (Also attached is the javascript file with code.)
$(document).ready(function(){
var timeOutComplete=false;
var timeoutCounter=0;
var currentURL = window.location.href;
if( document.referrer!=='undefined' || document.referrer!==null ){
var referrerURL = document.referrer;
}else{referrerURL=''}
var visProp = getHiddenProp();
var evtname = visProp.replace(/[H|h]idden/,'') + 'visibilitychange';
if(visProp){
var sessionTimer=setTimeout(function(){
sendMunchkinURLparams(currentURL,referrerURL);
timeOutComplete=true;
timeoutCounter++;
console.log('Min session time complete on first landing.');
},31000);
document.addEventListener(evtname, function(){
if(isHidden()){
clearTimeout(sessionTimer);
console.log('Session time count interupted.');
}else{
if(timeOutComplete==false && timeoutCounter==0){
setTimeout(function(){
sendMunchkinURLparams(currentURL,referrerURL);
timeOutComplete=true;
timeoutCounter++;
console.log('Min session time complete on coming back.');
},31000);
}
}
});
}
});
function sendMunchkinURLparams(webURL,refURL){
Munchkin.munchkinFunction('visitWebPage',{
'url':webURL,
'params':'sessionduration=minrequired&referrer='+refURL
});
}
function getHiddenProp(){
var prefixes = ['webkit','moz','ms','o'];
if ('hidden' in document) return 'hidden'; //if 'hidden' is natively supported just return it
// otherwise loop over all the known prefixes until we find one
for (var i = 0; i < prefixes.length; i++){
if ((prefixes[i] + 'Hidden') in document)
return prefixes[i] + 'Hidden';
}
return null; //otherwise it's not supported
}
function isHidden() {
var prop = getHiddenProp();
if (!prop) return false;
return document[prop];
}