(function () { function setCookie(name, value, days) { var expires = ""; if (days) { var date = new Date(); date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000); expires = "; expires=" + date.toUTCString(); } document.cookie = name + "=" + encodeURIComponent(value) + expires + "; path=/; SameSite=Lax"; } function getCookie(name) { var match = document.cookie.match(new RegExp("(^| )" + name + "=([^;]+)")); return match ? decodeURIComponent(match[2]) : ""; } var params = new URLSearchParams(window.location.search); var gclid = params.get("gclid"); var utmCampaign = params.get("utm_campaign"); if (gclid) setCookie("eco_gclid", gclid, 90); if (utmCampaign) setCookie("eco_utm_campaign", utmCampaign, 90); var FIELD_MAP = { 1: [12, 13], 2: [10, 11], 3: [10, 11], 4: [10, 11], 5: [10, 11], 6: [10, 11], 7: [7, 8], 8: [7, 8], }; function populateFields() { var g = getCookie("eco_gclid"); var u = getCookie("eco_utm_campaign"); document.querySelectorAll('form[id^="gform_"]').forEach(function (form) { var formId = parseInt(form.id.replace("gform_", ""), 10); var ids = FIELD_MAP[formId]; if (!ids) return; var gclidInput = form.querySelector('input[name="input_' + ids[0] + '"]'); var utmInput = form.querySelector('input[name="input_' + ids[1] + '"]'); if (gclidInput && g) gclidInput.value = g; if (utmInput && u) utmInput.value = u; }); } populateFields(); document.addEventListener("DOMContentLoaded", populateFields); if (window.gform && window.gform.addAction) { gform.addAction("gform_post_render", populateFields); } document.addEventListener( "submit", function (e) { if (e.target && e.target.tagName === "FORM" && e.target.id && e.target.id.indexOf("gform_") === 0) { populateFields(); } }, true ); })();