var cookie_message1 = document.getElementById('cookie_message1');
cookie_message1.addEventListener('click', function() {
let date = new Date();
date.setDate(date.getDate() + 30);
let day = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"][date.getUTCDay()];
let dateNum = String(date.getUTCDate()).padStart(2, '0');
let month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][date.getUTCMonth()];
let year = date.getUTCFullYear();
let hours = String(date.getUTCHours()).padStart(2, '0');
let minutes = String(date.getUTCMinutes()).padStart(2, '0');
let seconds = String(date.getUTCSeconds()).padStart(2, '0');
let formattedDate = day + ', ' + dateNum + '-' + month + '-' + year + ' ' + hours + ':' + minutes + ':' + seconds + ' UTC';
let ticks = date.getTime();
b4j_raiseEvent('${Passed_Instance_Name}_Report', {'value': formattedDate});
var userAgent = window.navigator.userAgent;
b4j_raiseEvent('${Passed_Instance_Name}_Report', {'value': userAgent});
if (userAgent.match(/iPad|iPhone/i)) {
// User is on iPad or iPhone
try {
document.cookie = 'cookietest=1';
const isCookieEnabled = document.cookie.indexOf('cookietest=') !== -1;
document.cookie = 'cookietest=1; expires=Thu, 01-Jan-1970 00:00:01 GMT';
if (isCookieEnabled) {
b4j_raiseEvent('${Passed_Instance_Name}_Report', {'value': "iOS, 1st party cookies enabled"});
} else {
b4j_raiseEvent('${Passed_Instance_Name}_Report', {'value': "iOS, 1st party cookies blocked"});
return;
}
} catch (e) {
b4j_raiseEvent('${Passed_Instance_Name}_Report', {'value': "iOS false"});
return;
}
document.cookie = 'Cookie_iOS' + ticks + '=abcxyz/expiry=' + formattedDate + '; expires=' + formattedDate;
} else if (userAgent.match(/Android/i)) {
// User is on Android
const isCookieEnabled = navigator.cookieEnabled;
if (isCookieEnabled) {
b4j_raiseEvent('${Passed_Instance_Name}_Report', {'value': "Android, 1st party cookies enabled"});
} else {
b4j_raiseEvent('${Passed_Instance_Name}_Report', {'value': "Android, 1st party cookies blocked"});
return;
}
document.cookie = 'Cookie_Android' + ticks + '=abcxyz/expiry=' + formattedDate + '; expires=' + formattedDate;
} else {
b4j_raiseEvent('${Passed_Instance_Name}_Report', {'value': "Neither iPhone nor Android"});
}
b4j_raiseEvent('${Passed_Instance_Name}_Report', {'value': document.cookie});
});
var cookie_message2 = document.getElementById('cookie_message2');
cookie_message2.addEventListener('click', function() {
var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i];
var eqPos = cookie.indexOf("=");
var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
}
b4j_raiseEvent('${Passed_Instance_Name}_Report', {'value': "Cookies deleted"});
b4j_raiseEvent('${Passed_Instance_Name}_Report', {'value': document.cookie});
});