Skip to content

/* Enquiry source capture. Fills the hidden UTM source, medium, campaign and GCLID fields on the Gravity Forms. Reads the URL and the referring site. Remembers the source for 90 days only if CookieYes analytics consent is given. Added 9 Oct 2026. */ var MAP = { 7: [10, 11, 12, 13], 8: [10, 11, 12, 13] }; (function () { var KEY = 'hbs_src', DAYS = 90; function consent() { var m = document.cookie.match(/cookieyes-consent=([^;]+)/); return !!(m && /analytics:yes/.test(decodeURIComponent(m[1]))); } function fromPage() { var q = new URLSearchParams(location.search); var s = { source: q.get('utm_source') || '', medium: q.get('utm_medium') || '', campaign: q.get('utm_campaign') || '', gclid: q.get('gclid') || '' }; if (s.gclid && !s.source) { s.source = 'google'; s.medium = 'cpc'; } if (!s.source && document.referrer) { var h = ''; try { h = new URL(document.referrer).hostname.replace(/^www\./, ''); } catch (e) {} if (h && h !== location.hostname.replace(/^www\./, '')) { s.source = h; s.medium = /(^|\.)(google|bing|yahoo|duckduckgo|ecosia)\./.test(h) ? 'organic' : 'referral'; } } return s; } var s = fromPage(), stored = null; try { stored = JSON.parse(localStorage.getItem(KEY) || 'null'); } catch (e) {} if (s.source) { if (consent()) { try { localStorage.setItem(KEY, JSON.stringify({ d: s, t: Date.now() })); } catch (e) {} } } else if (stored && Date.now() - stored.t < DAYS * 864e5) { s = stored.d; } else { var internal = document.referrer && document.referrer.indexOf(location.hostname) > -1; s = { source: internal ? '(not recorded)' : '(direct)', medium: internal ? '(not recorded)' : '(none)', campaign: '', gclid: '' }; } function fill() { Object.keys(MAP).forEach(function (f) { var vals = [s.source, s.medium, s.campaign, s.gclid]; MAP[f].forEach(function (id, i) { var el = document.getElementById('input_' + f + '_' + id); if (el && !el.value && vals[i]) { el.value = vals[i]; } }); }); } if (document.readyState !== 'loading') { fill(); } else { document.addEventListener('DOMContentLoaded', fill); } document.addEventListener('gform/post_render', fill); if (window.jQuery) { jQuery(document).on('gform_post_render', fill); } })();