? event.target.closest('a, button')
: null;
if (!target) return;
var href = target.tagName === 'A'
? (target.getAttribute('href') || '')
: '';
var absoluteUrl = '';
if (href) {
try { absoluteUrl = new URL(href, window.location.href).href; }
catch (e) { absoluteUrl = href; }
}
if (href.toLowerCase().indexOf('tel:') === 0) {
sendEvent('click_to_call', {
link_text: cleanText(target),
link_url: absoluteUrl
});
}
if (
href === '#estimate-form' ||
target.getAttribute('data-target') === '#estimate-form' ||
target.getAttribute('aria-controls') === 'estimate-form'
) {
sendEvent('estimate_click', {
link_text: cleanText(target),
link_url: absoluteUrl || (window.location.href.split('#')[0] + '#estimate-form')
});
}
if (absoluteUrl && /^https:\/\/apply\.svcfin\.com\//i.test(absoluteUrl)) {
sendEvent('financing_click', {
link_text: cleanText(target),
link_url: absoluteUrl
});
}
}, true);
var leadArmed = false;
var leadSent = false;
document.addEventListener('submit', function (event) {
var form = event.target;
if (!form || !form.closest || !form.closest('#estimate-form')) return;
leadArmed = true;
leadSent = false;
}, true);
function successIsVisible() {
if (!leadArmed || leadSent) return false;
var root = document.querySelector('#estimate-form');
if (!root) return false;
var candidates = root.querySelectorAll('*');
for (var i = 0; i < candidates.length; i++) {
var el = candidates[i];
if (cleanText(el).indexOf('Request Received') === -1) continue;
var style = window.getComputedStyle(el);
var rect = el.getBoundingClientRect();
if (
style.display !== 'none' &&
style.visibility !== 'hidden' &&
rect.width > 0 &&
rect.height > 0
) return true;
}
return false;
}
function recordConfirmedLead() {
if (!successIsVisible()) return;
leadSent = true;
leadArmed = false;
sendEvent('generate_lead');
}
var observer = new MutationObserver(recordConfirmedLead);
observer.observe(document.documentElement, {
childList: true,
subtree: true,
characterData: true,
attributes: true,
attributeFilter: ['class', 'style', 'hidden', 'aria-hidden']
});
var lastPath = window.location.pathname + window.location.search;
function routePageView() {
var nextPath = window.location.pathname + window.location.search;
if (nextPath === lastPath) return;
lastPath = nextPath;
sendEvent('page_view');
}
['pushState', 'replaceState'].forEach(function (method) {
var original = history[method];
history[method] = function () {
var result = original.apply(this, arguments);
window.setTimeout(routePageView, 0);
return result;
};
});
window.addEventListener('popstate', routePageView);
})();