// helper functions function pfc_getParameterByName(name, url = window.location.href) { name = name.replace(/[\[\]]/g, '\\$&'); var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'), results = regex.exec(url); if (!results) return null; if (!results[2]) return ''; return decodeURIComponent(results[2].replace(/\+/g, ' ')); } function pfc_setCookie(cname, cvalue, exdays) { const d = new Date(); d.setTime(d.getTime() + (exdays*24*60*60*1000)); expires = "expires="+ d.toUTCString(); document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; } function pfc_getCookie(cname) { let name = cname + "="; let ca = document.cookie.split(';'); for(let i = 0; i < ca.length; i++) { let c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } // main process function pfc_main() { var oldPFCE=pfc_getCookie("PFCE"); // get an existing cookie // see if 3rd party values have been passed in by a profundcom link var PFCE=pfc_getParameterByName("PFCE"); var PFCT=pfc_getParameterByName("PFCT"); var PFCN=pfc_getParameterByName("PFCN"); if(PFCE) { // data is in the query string - clean it var cleanhref=window.location.href; cleanhref=cleanhref.replace("&PFCE="+PFCE,""); cleanhref=cleanhref.replace("&PFCT="+PFCT,""); cleanhref=cleanhref.replace("&PFCN="+PFCN,""); if(cleanhref.endsWith("?")) cleanhref=cleanhref.substring(0,cleanhref.length-1); history.pushState({}, document.title, cleanhref) } if(!oldPFCE) //have we already set a 1st pary cookie, if not see if 3rd pery will work { var new_script = document.createElement('script'); new_script.setAttribute('src','https://connectioncapital.profundcom.net/dms/w.php?PFCC=true'); document.head.appendChild(new_script); return; } if(PFCE) { //values from link in query params pfc_setCookie("PFCE",PFCE, 30); pfc_setCookie("PFCT",PFCT, 30); pfc_setCookie("PFCN",PFCN, 30); } else { //values from 1st party cookies PFCE=oldPFCE; PFCT=pfc_getCookie("PFCT"); PFCN=pfc_getCookie("PFCN"); } if(!PFCE) { // set dummy as it would be in 3rd party PFCE=dummyPFCE; pfc_setCookie("PFCE",PFCE, 30); PFCT=dummyPFCT; pfc_setCookie("PFCT",PFCT, 30); } // call the tracked with the data we have from query string or 1st party cookie var new_script = document.createElement('script'); new_script.setAttribute('src','https://connectioncapital.profundcom.net/dms/w.php?PFCE='+PFCE+'&PFCT='+PFCT+'&PFCN='+PFCN+'&oldPFCE='+oldPFCE); document.head.appendChild(new_script); } pfc_main();