in the site template). Stores the FIRST utm/gclid this browser arrived with for 90 days, then feeds it to forms. */ (function () { var KEY = "axx_first_touch"; var PARAMS = ["utm_source","utm_medium","utm_campaign","utm_term","utm_content","gclid"]; try { var q = new URLSearchParams(location.search); var incoming = {}; var has = false; PARAMS.forEach(function (p) { var v = q.get(p); if (v) { incoming[p] = v; has = true; } }); var stored = null; try { stored = JSON.parse(localStorage.getItem(KEY) || "null"); } catch (e) {} var expired = stored && stored._ts && (Date.now() - stored._ts > 90 * 864e5); if (has && (!stored || expired)) { // first touch wins incoming._ts = Date.now(); localStorage.setItem(KEY, JSON.stringify(incoming)); stored = incoming; } if (!stored) return; var fill = function () { // A) GHL embedded forms/surveys: append params to the iframe URL — // GHL prefills any form field whose key matches the param name. document.querySelectorAll('iframe[src*="/widget/form/"], iframe[src*="/widget/survey/"]') .forEach(function (f) { var url = new URL(f.src); PARAMS.forEach(function (p) { if (stored[p] && !url.searchParams.get(p)) url.searchParams.set(p, stored[p]); }); if (f.src !== url.toString()) f.src = url.toString(); }); // B) Plain HTML forms: fill hidden inputs named utm_source, gclid, etc. PARAMS.forEach(function (p) { if (!stored[p]) return; document.querySelectorAll('input[name="' + p + '"]').forEach(function (i) { if (!i.value) i.value = stored[p]; }); }); }; if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", fill); } else { fill(); } setTimeout(fill, 1500); // late-injected embeds } catch (e) {} })();