{"version":3,"sources":["acton-prefiller.js"],"names":["readCookie","name","nameEQ","encodeURI","document","cookie","i","c","ca","length","charAt","substring","indexOf","decodeURI","observer","Promise","resolve","querySelector","selector","MutationObserver","mutations","waitForElm","disconnect","observe","body","childList","elm","subtree","gclidInput","gclidInput2","cookieClientId","split","slice","join","cookieGclid","clientIdInput","value","clientIdInput2"],"mappings":"cAOA,WAEE,SAAAA,EAAAC,GAGE,IAFF,IAAAC,EAASF,UAATC,GAA0B,IACpBC,EAAAA,SAASC,OAAUF,MAAQ,KACtBG,EAAAA,EAAAA,EAASC,EAAAA,OAAaC,IAA/B,CACA,IACE,IAAIC,EAAIC,EAAGF,GADUG,KAAdH,EAACI,OAAO,IAAjBH,EAAgCA,EAAhCI,UAAoC,EAAAJ,EAAAE,QAClC,GAAA,GAAIF,EAACK,QAALV,GAAA,OAAAW,UAAAN,EAAAI,UAAAT,EAAAO,OAAAF,EAAAE,SACA,OAAA,KACA,IAAcP,GAAAA,EAiBZY,WAhBH,IAAAC,QAAA,SAAAC,GAOG,GAAIZ,SAASa,cAAcC,GANxB,OAAPF,EAAAZ,SAAAa,cAAAC,IASI,IAAMJ,EAAW,IAAIK,iBAAiB,SAAAC,GAC9BhB,SAASa,cAAcC,KAN5BG,EAAWH,SAAUD,cAAAC,IACjBH,EAAQO,gBAGdR,EAAAS,QAAAnB,SAAAoB,KAAA,CAQGC,WAAW,EAPTX,SAAW,OAMAV,KAAAA,SAAQsB,GACrBD,IAAAA,EAD4BrB,SAAAa,cAAA,2BAE5BU,EAASvB,SAAAa,cAAA,0BAFbW,EAAAxB,SAAAa,cAAA,uBAVJY,EAAAzB,SAAAa,cAAA,uBAiBFa,EAAA9B,EAAA,OAAAA,EAAA,OAAA+B,MAAA,KAAAC,MAAA,GAAAC,KAAA,KAAA,GAOQC,EAAclC,EAAW,gBAAkB,GANnDqB,IAAUc,EAAkBC,MAASN,GAC7BK,IAAgB/B,EAASa,MAAca,GACvCO,IAAAA,EAAiBjC,MAASa,GAC1BW,IAAaxB,EAASa,MAAAA,KArChC","file":"acton-prefiller.js","sourcesContent":["/**\r\n * Place this file after the act-on embed code\r\n * - this will prefill the GA clientID and gclid hidden input fields\r\n * - the act-on form will need to have the hidden fields below\r\n * - input[name=\"Client ID\"] and input[name=\"gclid\"]\r\n */\r\n\r\n// eslint-disable-next-line no-undef\r\n(function() {\r\n // this is the script that adds the GA clientID and Gclid to the Act-on's embeded form\r\n function readCookie(name) {\r\n let nameEQ = encodeURI(name) + '=';\r\n let ca = document.cookie.split(';');\r\n for (let i = 0; i < ca.length; i++) {\r\n let c = ca[i];\r\n while (c.charAt(0) == ' ') c = c.substring(1, c.length);\r\n if (c.indexOf(nameEQ) == 0) return decodeURI(c.substring(nameEQ.length, c.length));\r\n }\r\n return null;\r\n }\r\n\r\n // from https://stackoverflow.com/questions/5525071/how-to-wait-until-an-element-exists\r\n function waitForElm(selector) {\r\n return new Promise(resolve => {\r\n if (document.querySelector(selector)) {\r\n return resolve(document.querySelector(selector));\r\n }\r\n const observer = new MutationObserver(mutations => {\r\n if (document.querySelector(selector)) {\r\n resolve(document.querySelector(selector));\r\n observer.disconnect();\r\n }\r\n });\r\n observer.observe(document.body, {\r\n childList: true,\r\n subtree: true\r\n });\r\n });\r\n }\r\n\r\n // using the Act-on form class to check if the form is added to the DOM\r\n waitForElm('.ao-form').then((elm) => {\r\n const clientIdInput = document.querySelector('input[name=\"Client ID\"]')\r\n const clientIdInput2 = document.querySelector('input[name=\"ClientID\"]')\r\n const gclidInput = document.querySelector('input[name=\"gclid\"]')\r\n const gclidInput2 = document.querySelector('input[name=\"Gclid\"]')\r\n const cookieClientId = readCookie('_ga') ? readCookie('_ga').split(\".\").slice(2).join(\".\") : \"\";\r\n const cookieGclid = readCookie(\"adwordsLead\") || \"\";\r\n\r\n if (clientIdInput) clientIdInput.value = cookieClientId;\r\n if (clientIdInput2) clientIdInput2.value = cookieClientId;\r\n if (gclidInput) gclidInput.value = cookieGclid;\r\n if (gclidInput2) gclidInput2.value = cookieGclid;\r\n });\r\n\r\n})()"]}