function wwTrack(cognitoUserId,cognitoIdentityId,apiKey){var EMAIL_REGEX=/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;var ENDPOINT_URL='https://af7fve7egj.execute-api.us-east-1.amazonaws.com/beta/visitors';var QUERY_ENDPOINT_URL=ENDPOINT_URL+'/gaid';var QUERY_USER='https://af7fve7egj.execute-api.us-east-1.amazonaws.com/beta/lhuser/getuser';var UPDATE_USER='https://af7fve7egj.execute-api.us-east-1.amazonaws.com/beta/lhuser/update';var gaClientId;var gaObj;var emailsSeen=[];var buttons;var inputButtons;function getQueryStringParameter(name){name=name.replace(/[\[\]]/g,"\\$&");var url=window.location.href;var regex=new RegExp("[?&]"+name+"(=([^&#]*)|&|#|$)"),results=regex.exec(url);if(!results)return null;if(!results[2])return '';return decodeURIComponent(results[2].replace(/\+/g," "));}
function emailValue(field){var value=false;if(field.type==='email'){value=field.value;}else{if(field.value===''||field.type==='hidden'){return;}
if(stringContainsEmail(field.name)||stringContainsEmail(field.placeholder)||stringContainsEmail(getLabelTextForInput(field))){value=field.value;}}
if(value&&EMAIL_REGEX.test(value)){return value.trim();}else{return false;}}
function getLabelTextForInput(element){var labels=element.labels||[];var labelString="";for(var i=0;i<labels.length;i++){var labelText=labels[i].innerText||labels[i].textContent;if(labelText){labelString+=labelText;}}
return labelString;}
function stringContainsEmail(string){if(!string){return false;}
var compare=string.toLowerCase().replace(/\W/g,'_');var index=compare.indexOf('email')+compare.indexOf('e_mail');if(index>=-1){return true;}
return false;}
function logEmailToWW(email){sendToWW({email:email});emailsSeen.push(email);}
function logMcToWW(mcEid,mcCid){sendToWW({mcEid:mcEid,mcCid:mcCid});}
function sendToWW(payload){if(!gaClientId){console.log('gaClientId is undefined');return;}
payload.userId=cognitoUserId;payload.identityId=cognitoIdentityId;payload.clientId=gaClientId;var r=new XMLHttpRequest();r.open('POST',ENDPOINT_URL);r.setRequestHeader('Content-Type','application/json');r.setRequestHeader('x-api-key',apiKey);r.send(JSON.stringify(payload));}
if(window.ga){gaObj=window.ga;}else if(window.GoogleAnalyticsObject){gaObj=window[window.GoogleAnalyticsObject];}else{console.log('GA not found. Make sure to call wwTrack() after ga loads. We recommend placing this script at the end of your <body> tag.');return;}
if(!cognitoUserId||!cognitoIdentityId){console.log('wwTrack() called without your website\'s tracker ID. Please check to make sure you copy+pasted the code correctly.');return;}
if(!apiKey){console.log('wwTrack() called without your website\'s API key. Please check to make sure you copy+pasted the code correctly.');return;}
gaObj(function(tracker){if(tracker){gaClientId=tracker.get('clientId');}else{gaClientId=gaObj.getAll()[0].get('clientId');}
var mcEid=getQueryStringParameter("mc_eid");var mcCid=getQueryStringParameter("mc_cid");if(mcEid&&mcCid){logMcToWW(mcEid,mcCid);};});function logFields(fields){var value;for(var i in fields){if(value=emailValue(fields[i])){if(emailsSeen.indexOf(value)<0){logEmailToWW(value);}
break;}}}
function clickListener(event){if(event.target.form){logFields(event.target.form.elements);}else{logFields(document.querySelectorAll('input'));}}
document.addEventListener('submit',function(event){logFields(event.target.elements);});document.addEventListener('click',function(event){if((['input','button'].indexOf(event.target.tagName.toLowerCase())>-1)&&event.target.type.toLowerCase()==='submit'){clickListener(event);}});buttons=document.querySelectorAll("button");for(var i=0;i<buttons.length;i++){buttons[i].addEventListener('click',clickListener);}
inputButtons=document.querySelectorAll("input");for(var i=0;i<inputButtons.length;i++){if(inputButtons[i].type==='button'||inputButtons[i].type==='submit'){inputButtons[i].addEventListener('click',clickListener);}}
function decodeEmail(code,origin){var containsSymbol;var email='';switch(origin){case 'e_src':containsSymbol=false;break;default:containsSymbol=true;break;}
if(containsSymbol){email=decodeURIComponent(code)}else{code=decodeURIComponent(code);for(var i=0;i<code.length;i++){var a=code.charCodeAt(i);var b=a^13;email=email+String.fromCharCode(b);}}
if(EMAIL_REGEX.test(email)){return email}}
function logEmailFromURL(){if(gaClientId){var emailDecoded='';if(window.location.search.split('?e_src=')[1]){emailDecoded=decodeEmail(window.location.search.split('?e_src=')[1],'e_src');}else{emailDecoded=decodeEmail(window.location.href.match(/supporterEmail=([^&]*)/)[1],'supporterEmail')}
logEmailToWW(emailDecoded)}else{setTimeout(logEmailFromURL,500);}}
function queryExistsInDB(){if(gaClientId){if(!window.sessionStorage.getItem('clientId')){var payload={userId:cognitoUserId,identityId:cognitoIdentityId,clientId:gaClientId};var r=new XMLHttpRequest();r.open('POST',QUERY_ENDPOINT_URL);r.setRequestHeader('x-api-key',apiKey);r.send(JSON.stringify(payload));r.addEventListener("error",function(ev){console.log('there was an error error: ',JSON.parse(ev))})
r.onreadystatechange=function(){if(r.readyState===4){var res=JSON.parse(r.response);if(res.result.length>0){window.sessionStorage.setItem('visitorExists',true);res.result.forEach(element=>logEmailToWW(element._source.email));window.sessionStorage.setItem('clientId',gaClientId);}else{return null}}}}else{return null}}else{setTimeout(queryExistsInDB,500);}}
if(window.sessionStorage){queryExistsInDB()}
if(window.location.search){logEmailFromURL()}
if(window.localStorage){if(window.localStorage.emailSubmission){logEmailToWW(window.localStorage.emailSubmission);window.localStorage.clear();}}
function isOptmnstrScriptLoaded(){var url="https://a.optmnstr.com/app/js/api.min.js";var url2="https://a.opmnstr.com/app/js/api.min.js";var scripts=document.getElementsByTagName('script');for(var i=scripts.length;i--;){if(scripts[i].src===url||scripts[i].src===url2){return true}}
return false;}
if(document.cookie.includes('_omappvp')||isOptmnstrScriptLoaded()){document.addEventListener('om.Campaign.afterShow',function(event){document.addEventListener('om.Optin.init.submit',function(event){const email=event.detail.Optin.data.fields.email;logEmailToWW(email);});});}}