(function (tid) {
var startTime = Date.now(); // Track the start time
var referrer = document.referrer;
var title = document.getElementsByTagName("title")[0].innerHTML;
var pathname = window.location.pathname ?? "/";
var search = window.location.search;
var myHeaders = new Headers();
var search = new URLSearchParams(window.location.search)
var lvv = search.get("lvv")
myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({
referrer,
title,
pathname,
search,
});
var requestOptions = {
method: "POST",
headers: myHeaders,
body: raw,
redirect: "follow",
};
if(lvv) {
requestOptions = {
method: "GET",
redirect: "follow"
}
}
var url = "https://visitor.leadsourcing.co/api/info?tid=" + tid;
fetch(url, requestOptions);
window.addEventListener("beforeunload", function() {
var timeSpent = Math.round((Date.now() - startTime) / 1000); // Calculate time spent in seconds
raw = JSON.stringify({
referrer,
title,
pathname,
search,
timeSpent,
type: "page_leave"
});
fetch(url, { ...requestOptions, body: raw }); // Send updated data
});
})("Cb77Ms6lgTGc6NMNI7kL");