var liveGuideUID = 'LiveGuide_tZl3HKrMYaWSKshzj0TOF-i'; var liveGuideCookies = (function(liveGuideUID, undefined){ 'use strict'; /** * Creates a cookie with specific name and TTL * @param {string} name * @param {number|string} value * @param {number} days */ function setCookie(name, value, days) { var expires = ''; if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = '; expires=' + date.toGMTString(); } document.cookie = name + '=' + value + expires + '; SameSite=None; Secure; path=/'; } /** * Retrieves a cookie's value by its name * @param {string} name The name of the cookie whose value we need to retrieve * @returns {string} A string representation of the cookie's value or the empty string as a default */ function getCookie(name) { var cookie = document.cookie; var cookieStartIndex = -1; var cookieEndIndex = -1; var parsedCookie = ''; if (cookie.length > 0) { cookieStartIndex = cookie.indexOf(name + '='); if (cookieStartIndex != -1) { cookieStartIndex = cookieStartIndex + name.length + 1; cookieEndIndex = cookie.indexOf(';', cookieStartIndex); if (cookieEndIndex == -1) { cookieEndIndex = cookie.length; } parsedCookie = encodeURIComponent(cookie.substring(cookieStartIndex,cookieEndIndex)); } } return parsedCookie; } /** * Saves information about the time spent on the site by the customers * before they calls an operator. */ (function initialize() { var currentDate = (new Date()).getTime(); var lastDate = getCookie(liveGuideUID + '_date'); if (lastDate === null || lastDate === '') { setCookie(liveGuideUID + '_date', currentDate, 0); setCookie(liveGuideUID + '_url', encodeURIComponent(window.document.URL), 0); setCookie(liveGuideUID + '_title', encodeURIComponent(window.document.title), 0); setCookie(liveGuideUID + '_ref', encodeURIComponent(window.document.referrer), 0); setCookie(liveGuideUID + '_duration', 0, 0); } else { setCookie(liveGuideUID + '_duration', currentDate - parseInt(lastDate), 0); } })(); return { setCookie: setCookie, getCookie: getCookie } }(liveGuideUID));