'use strict';
var MonsterInsightsUserJourney=window.MonsterInsightsUserJourney||(function(document, window){
var app={
init: function(){
if(! String.prototype.startsWith){
Object.defineProperty(String.prototype,
'startsWith',
{
value: function(search, rawPos){
var pos=rawPos > 0 ? rawPos | 0:0;
return this.substring(pos, pos + search.length)===search;
},
}
);
}
var timeStamp=Math.round(Date.now() / 1000),
cookie=app.getCookie('_monsterinsights_uj'),
data={},
url=window.location.href;
if(! cookie&&document.referrer!==''&&! document.referrer.startsWith(window.location.origin) ){
data[ timeStamp - 2 ]=document.referrer + '|#|{ReferrerPageTitle}';
}
url +='|#|' + document.title;
if(typeof monsterinsights_user_journey!=='undefined'&&monsterinsights_user_journey.page_id){
url +='|#|' + Number(monsterinsights_user_journey.page_id);
}
if(cookie){
data=JSON.parse(cookie);
}
var encodedUrl=encodeURIComponent(url);
var latestTimeStamp=app.getLatestTimeStamp(data);
if(data[latestTimeStamp]!==encodedUrl){
data[timeStamp]=encodedUrl;
}
var maxDataLength=4096 - 100;
var dataString=JSON.stringify(data);
while(dataString.length > maxDataLength){
delete data[ app.getEarliestTimeStamp(data) ];
dataString=JSON.stringify(data);
}
app.createCookie('_monsterinsights_uj', JSON.stringify(data), 365);
},
createCookie: function(name, value, days){
var expires='';
var secure='';
if(monsterinsights_user_journey.is_ssl){
secure=';secure';
}
if(days){
if('-1'===days){
expires='';
}else{
var date=new Date();
date.setTime(date.getTime() +(days * 24 * 60 * 60 * 1000) );
expires=';expires=' + date.toGMTString();
}}else{
expires=';expires=Thu, 01 Jan 1970 00:00:01 GMT';
}
document.cookie=name + '=' + value + expires + ';path=/;samesite=strict' + secure;
},
getCookie: function(name){
var nameEQ=name + '=',
ca=document.cookie.split(';');
for(var i=0; i < ca.length; i++){
var c=ca[i];
while(' '===c.charAt(0) ){
c=c.substring(1, c.length);
}
if(0===c.indexOf(nameEQ) ){
return c.substring(nameEQ.length, c.length);
}}
return null;
},
getEarliestTimeStamp: function(data){
let timeStamps=Object.keys(data).map(timeStamp=> parseInt(timeStamp, 10) );
return Math.min(...timeStamps).toString();
},
getLatestTimeStamp: function(data){
let timeStamps=Object.keys(data).map(timeStamp=> parseInt(timeStamp, 10) );
return Math.max(...timeStamps).toString();
},
};
return app;
}(document, window) );
MonsterInsightsUserJourney.init();