var dml_mifo = dml_mifo || {}; if (/localhost/g.test("https://milkfoliant-production.herokuapp.com") || /192\.168\.0\./g.test("https://milkfoliant-production.herokuapp.com")){ dml_mifo.logAllFlag = true; }else{ dml_mifo.logAllFlag = false; } dml_mifo.forced_language = dml_mifo.forced_language || ""; dml_mifo.addToBagFlag = false; dml_mifo.hasBanner = dml_mifo.hasBanner || false; dml_mifo.bannerTexts = dml_mifo.bannerTexts || { "tagline_one" : "make peace with daily exfoliation", "tagline_two": "create a personalized exfoliation routine", "cta" : "show me how" }; dml_mifo.widget_wrapper=document.getElementById("dml_mifo_wrapper"); dml_mifo.debug = function(inStringBefore,inVariable){ if ( dml_mifo.logAllFlag){ inStringBefore = (inStringBefore === undefined) ? '' : inStringBefore; if (inVariable == undefined){ console.log(inStringBefore) }else{ console.log(inStringBefore, inVariable) } } } // GA - START dml_mifo.GAsetup = false; dml_mifo.sendGA = function(eventName,eventParameters){ if (eventParameters === undefined){ eventParameters = {}; } if (!window.gtag) return; if (!dml_mifo.GAsetup) return; var parametersAsString; try{ parametersAsString = JSON.stringify(eventParameters); dml_mifo.debug("GOOGLE ANALYTICS: " + eventName + " - " + parametersAsString); }catch(err){ console.warn("Error in GA event parameters - ",err); eventParameters={}; } window.gtag('event', eventName, eventParameters); } dml_mifo.setupGA = function(){ if (window.gtag) { dml_mifo.debug("setting up GA with 'gtag'"); window.gtag('config', "G-TNQK85LL90"); dml_mifo.GAsetup = true; } } // GA - END dml_mifo.getEmbedHtmlData = function(url, callback){ var request = new XMLHttpRequest(); request.open('GET', url, true); request.onload = function() { if (request.status >= 200 && request.status < 400) { callback({"status": "success","status_code":request.status, "data" : request.responseText}); } else { callback({"status": "success","status_code":request.status, "data" : "We reached our target server, but it returned an error"}); } }; request.onerror = function() { callback({"error": "success","status_code":request.status, "data" : "Error occured in getting html data"}); }; request.send(); } dml_mifo.getScript = function(source, callback) { var script = document.createElement('script'); script.async = 1; script.onload = function(evt) { callback({"status":"success","message":"done"}); }; script.onerror = function(err){ console.log(err) callback({"status":"error", "message":"error in getting script " + source}); } script.setAttribute('type','text/javascript'); script.src = source; dml_mifo.widget_wrapper.appendChild(script); } dml_mifo.getScript_withAttributes = function(source, attributeObj, callback) { var script = document.createElement('script'); script.async = 1; script.onload = function(evt) { callback({"status":"success","message":"done"}); }; script.onerror = function(err){ console.log(err) callback({"status":"error", "message":"error in getting script " + source}); } script.setAttribute('type','text/javascript'); try{ Object.keys(attributeObj).forEach( function(attrKey){ script.setAttribute(attrKey,attributeObj[attrKey]); }); }catch(err){ console.log(err); } script.src = source; dml_mifo.widget_wrapper.appendChild(script); } dml_mifo.openApp = function(){ var gaTimer = 100; var checkForWindowGA = true; var gacheckinterval = setInterval(function(){ if (window.gtag){ dml_mifo.debug("GA AVAILABLE - "+ gaTimer/1000 + "s",""); clearInterval(gacheckinterval); dml_mifo.setupGA(); }else{ if (checkForWindowGA){ if (window.ga){ checkForWindowGA = false; console.log("found ga but not gtag - adding gtag library"); dml_mifo.getScript("https://www.googletagmanager.com/gtag/js?id=G-TNQK85LL90",function(res){ window.dataLayer = window.dataLayer || []; window.gtag = function(){dataLayer.push(arguments);} gtag('js', new Date()); }); } } if (gaTimer > 20000){ dml_mifo.debug("GA NOT AVAILABLE - "+ gaTimer/1000 + "s"); clearInterval(gacheckinterval); } gaTimer += 100; } },100) if (document.getElementById("mifo_banner_container")){ document.getElementById("mifo_banner_container").style.display="none" } if (navigator.appName == 'Microsoft Internet Explorer' || !!(navigator.userAgent.match(/Trident/) || navigator.userAgent.match(/rv:11/))){ setTimeout(function(){dml_mifo.sendGA("flow",{action: "showing browser not supported screen", page_title: "landing_page", page_location: window.location.hostname, page_path: window.location.pathname});},2000); //alert("We don't currently support this browser. Please reopen this page in a different browser.") dml_mifo.widget_wrapper.style.height = window.innerHeight + "px"; dml_mifo.widget_wrapper.innerHTML = '

We don\'t currently support this browser. Please reopen this page in a different browser, such as Chrome.

' + dml_mifo.widget_wrapper.innerHTML; if (dml_mifo.widget_wrapper.offsetWidth >= 768){ dml_mifo.widget_wrapper.style.background = "url('https://milkfoliant-production.herokuapp.com/img/pwrbrt_onboarding_bg_desktop.jpg') no-repeat center center"; }else{ dml_mifo.widget_wrapper.style.background = "url('https://milkfoliant-production.herokuapp.com/img/pwrbrt_onboarding_mobile_bg.jpg') no-repeat center center"; } dml_mifo.widget_wrapper.style.backgroundSize= "cover"; }else{ var sessionTimeString = (new Date()).getTime(); var cssId = 'mifoStyleSheet'; var pagelink = document.createElement('link'); pagelink.id = cssId; pagelink.rel = 'stylesheet'; pagelink.type = 'text/css'; pagelink.href = 'https://milkfoliant-production.herokuapp.com/css/styles.min.css?'+sessionTimeString; pagelink.media = 'all'; dml_mifo.widget_wrapper.appendChild(pagelink); setTimeout(function(){dml_mifo.sendGA("flow",{action: "loading full script", page_title: "srs_landing_page", page_location: window.location.hostname, page_path: window.location.pathname});},2000); dml_mifo.getEmbedHtmlData('https://milkfoliant-production.herokuapp.com/widget?'+sessionTimeString, function(res) { dml_mifo.widget_wrapper.innerHTML = res.data + dml_mifo.widget_wrapper.innerHTML; dml_mifo.getScript('https://milkfoliant-production.herokuapp.com/script.js?'+sessionTimeString,function(){}); try{ dml_mifo.getScript('https://milkfoliant-production.herokuapp.com/js/hotjar.js?'+sessionTimeString,function(){ dml_mifo.debug("added htjar"); }); }catch(err){} dml_mifo.widget_wrapper.style.height = window.innerHeight + "px"; window.addEventListener('resize',dml_mifo.resizeWrapper); }) } } dml_mifo.resizeWrapper = function (){ if (dml_mifo.widget_wrapper.style.height != "auto"){ dml_mifo.widget_wrapper.style.height = window.innerHeight + "px"; } } // adjust follwing function according to the banner elements needed for that widget_wrapper dml_mifo.makeBanner = function(){ dml_mifo.openConsentOnWidgetLoad = false; dml_mifo.widget_wrapper.innerHTML = "
" + dml_mifo.widget_wrapper.innerHTML; var bannerEl = document.getElementById("mifo_banner_container"); var sessionTimeString = (new Date()).getTime(); var cssId = 'mifoBannerStyleSheet'; var bannerStyle = document.createElement('link'); bannerStyle.id = cssId; bannerStyle.rel = 'stylesheet'; bannerStyle.type = 'text/css'; bannerStyle.href = 'https://milkfoliant-production.herokuapp.com/css/banner.min.css?'+sessionTimeString; bannerStyle.media = 'all'; bannerEl.appendChild(bannerStyle); var bannerContent = document.createElement('div'); bannerContent.id = "mifo_banner_content"; var bannerBackgroundContainer = document.createElement('div'); bannerBackgroundContainer.id = "mifo_banner_background"; bannerContent.innerHTML = ``; bannerEl.appendChild(bannerContent); bannerEl.appendChild(bannerBackgroundContainer); function updateBannerClassDueWith(){ if (/(Mac|iPhone|iPod|iPad)/i.test(navigator.platform)){ document.getElementById('mifo_banner_cta').classList.add('mifo_is_os'); } document.getElementById("mifo_banner_container").style.backgroundPosition = "center"; if (dml_mifo.widget_wrapper.offsetWidth >= 768){ document.getElementById("mifo_banner_container").classList.remove('dml_768'); let bannerHeight = Math.max(250,Math.min(350,dml_mifo.widget_wrapper.offsetWidth * 0.3)); if (dml_mifo.widget_wrapper.offsetWidth < 1000){ //document.getElementById("mifo_banner_container").style.backgroundPosition = "right -150px center"; } document.getElementById("mifo_banner_container").style.height = bannerHeight + "px"; //document.getElementById("mifo_banner_content").style.transform = "scale(1)"; }else{ document.getElementById("mifo_banner_container").classList.add('dml_768'); document.getElementById("mifo_banner_container").style.height = Math.round(1.42 * dml_mifo.widget_wrapper.offsetWidth) + "px"; //document.getElementById("mifo_banner_content").style.transform = "scale(" + dml_mifo.widget_wrapper.offsetWidth * 0.8 / 300 + ")"; } if (document.getElementById("mifo_banner_container").offsetWidth < 400) { document.getElementById("mifo_banner_container").style.height = Math.round(2 * dml_mifo.widget_wrapper.offsetWidth) + "px"; } } if (dml_mifo.widget_wrapper.offsetWidth < 1){ dmlWrapperDisplayedInterval = setInterval(function(){ if (dml_mifo.widget_wrapper.offsetWidth > 0){ clearInterval(dmlWrapperDisplayedInterval); updateBannerClassDueWith() } },200) }else{ updateBannerClassDueWith(); } window.addEventListener("resize",updateBannerClassDueWith); } // start app/banner if (dml_mifo.hasBanner ){ dml_mifo.makeBanner() }else{ dml_mifo.openApp() }