function getTestQS(name){ name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); var regexS = "[\\?&]"+name+"=([^&#]*)"; var regex = new RegExp( regexS ); var results = regex.exec( window.location.href ); if( results == null ){ if (nmxuser != undefined && nmxuser != ""){ return nmxuser; } return "(unknown)"; } else { return decodeURIComponent(results[1].replace(/\+/g, " ")); } } function qs(name){ name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); var regexS = "[\\?&]"+name+"=([^&#]*)"; var regex = new RegExp( regexS ); var results = regex.exec( window.location.href ); if( results == null ){ return ""; } else { return decodeURIComponent(results[1].replace(/\+/g, " ")); } } // cookie functions function setTestCookie(c_name, value, expiredays) { var exdate = new Date(); exdate.setDate(exdate.getDate() + expiredays); document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toUTCString()) + "; path=/; SameSite=None; Secure"; } function getTestCookie(c_name) { //var cookie = document.cookie.replace(/; /g, ";") + ";"; var cookie = document.cookie; if (cookie.length > 0) { c_start = cookie.indexOf(c_name + "="); if (c_start != -1) { c_start = c_start + c_name.length + 1; c_end = cookie.indexOf(";", c_start); if (c_end == -1) c_end = cookie.length; return unescape(cookie.substring(c_start, c_end)); } } return ""; } if (location.search.indexOf("?test")>-1){ setTestCookie("test_view", getTestQS("test"), 1); } // else if (location.search.indexOf("?test")>-1){ // console.clear(); // console.log("%cNOT IN TEST MODE", "font-family: Arial Black; font-weight: normal; font-size: 32px; color: red; -webkit-text-fill-color: red; -webkit-text-stroke-width: 1px; -webkit-text-stroke-color: black;"); // console.log("%cUse: ?test=[username] to activate test mode", "color:#888; font-size: 21px; font-weight:normal;"); // } if (getTestCookie("test_view") != ""){ if (location.search.indexOf("?test")>-1){ //console.clear(); ga('nmxdashboard.send', 'event', 'Test Mode', 'Activated', getTestCookie("test_view")); } if (location.search.indexOf("?notest")>-1){ console.log("%cPRODUCTION", "font-family: Arial Black; font-weight: normal; font-size: 32px; color: red; -webkit-text-fill-color: red; -webkit-text-stroke-width: 1px; -webkit-text-stroke-color: black;"); if (getTestQS("test") == "(unknown)"){ console.log("%cUse: ?test=[username] to activate test mode", "color:#888; font-size: 21px; font-weight:normal;"); } else { console.log("%cUse: ?test to activate test mode", "color:#888; font-size: 21px; font-weight:normal;"); } console.log("%cYou will not see this message again while in Production!", "color:#333; font-size: 16px; font-weight:normal;"); setTestCookie("test_view", 1, -1); ga('nmxdashboard.send', 'event', 'Test Mode', 'Deactivated', getTestQS("notest")); } else{ document.getElementsByTagName("body")[0].setAttribute("testmode", "true"); console.log("%cTEST MODE", "font-family: Arial Black; font-weight: normal; font-size: 32px; color: #09ad52; -webkit-text-fill-color: #09ad52; -webkit-text-stroke-width: 1px; -webkit-text-stroke-color: black;"); console.log("%cUse: ?notest to leave test mode", "color:#000; font-size: 18px; font-weight:normal;"); ga('nmxdashboard.set', 'dimension1', getTestCookie("test_view")); //tester ga('nmxdashboard.set', 'metric1', 1); //test //ga('set', 'dimension2', getTestCookie("test_view")); //build ga('nmxdashboard.send', 'pageview', location.pathname); ga('nmxdashboard.send', 'event', 'Test Mode', 'Tested', getTestCookie("test_view")); var script_nmx20190507a = document.createElement("script"); script_nmx20190507a.type = "text/javascript"; script_nmx20190507a.src = "https://www.nutramax.biz/nmx.flags/index.nmx.js?test&onlytestmode"; document.getElementsByTagName("head")[0].appendChild(script_nmx20190507a); } } else { if (location.search.indexOf("?notest")>-1 || location.search.indexOf("?test")>-1){ console.log("%cNOT IN TEST MODE", "font-family: Arial Black; font-weight: normal; font-size: 32px; color: black; -webkit-text-fill-color: black; -webkit-text-stroke-width: 1px; -webkit-text-stroke-color: black;"); if (getTestQS("test") == "(unknown)"){ console.log("%cUse: ?test=[username] to activate test mode", "color:#888; font-size: 21px; font-weight:normal;"); } else { console.log("%cUse: ?test to activate test mode", "color:#888; font-size: 21px; font-weight:normal;"); } } }