var datalayerJS = { RFV: function() { var rfv = ''; try { rfv = datalayerJS.getCookie('RFV'); if (rfv != null && rfv != '') return rfv; var ga = datalayerJS.getCookie('_ga'); if (ga == null || ga == '') return ''; rfv = datalayerJS.getHttp('https://apis.joins.com/DataLayer/RFV?ga=' + encodeURIComponent(ga)); } catch (e) { console.log(e); } return rfv; }, getCookie: function (key) { var cookie = ''; try { cookie = document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(key).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1") || null; if (cookie) { try { cookie = decodeURIComponent(cookie); } catch (e) { cookie = decodeURIComponent(unescape(cookie)); } } } catch (e) { console.log(e); } return cookie; }, setCookie: function (key, value, expires) { try { document.cookie = encodeURIComponent(key) + '=' + encodeURIComponent(value) + '; expires=Fri, 31 Dec 9999 23:59:59 GMT' + '; max-age=' + (60 * 60 * 24 * expires) + '; domain=joins.com' + '; path=/'; return true; } catch (e) { console.log(e); return false; } }, getHttp: function(url) { var text = ''; try { var xhr = new XMLHttpRequest(); xhr.open('GET', url, true); xhr.send(); xhr.onload = function() { if (xhr.status == 200) { text = xhr.responseText.replace(/"/gi, '').trim(); if (text == null || text == '' || text == '0') return ''; datalayerJS.setCookie('RFV', text, 1); } } } catch (e) { console.log(e); } return text; } };