function _validateEvent(tag_event) {
var hostname;
if (window.location.hostname) {
var hostname = window.location.hostname.replace('www.', '');
} else {
// Fallback case for iframe
try {
// Get this script's own URL to find the hostname parameter
const scriptUrl = new URL(document.currentScript.src);
const hostnameParam = scriptUrl.searchParams.get('hostname');
if (hostnameParam) {
hostname = hostnameParam.replace('www.', '');
} else {
// If the parameter isn't found, we can't proceed
console.error('Validate: Hostname parameter is missing from script URL.');
return;
}
} catch (e) {
console.error('Validate: Could not determine hostname.', e);
return; // Stop execution if we can't find a hostname
}
}
var ss = window.screen.width * window.devicePixelRatio + "x" + window.screen.height * window.devicePixelRatio;
var pathname = encodeURIComponent(window.location.pathname)
var id_lookup_url = 'https://tag.validate.audio/site/' + hostname + '/?pathname=' + pathname + '&tag_event=' + encodeURIComponent(tag_event) + '&ss=' + ss + '&cb=' + new Date().getTime();
if (window.location.search) {
id_lookup_url += '&query_params=' + encodeURIComponent(window.location.search);
}
navigator.sendBeacon(id_lookup_url, '');
}
(function() {
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/; SameSite=Lax";
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
if (getCookie('validate_session_today')) {
_validateEvent('Page View');
} else {
_validateEvent('Website Visit');
setCookie('validate_session_today', 'true', 1);
}
})();