/* AutoGen - Google Ads enhanced conversions, part 1 of 2. Captures quote-form values at submit so the confirmation page can pass them to the Google tag. Stored only in this browser tab, cleared on use. */ (function () { document.addEventListener("submit", function (e) { var f = e.target; if (!f || f.id !== "form_extractionservicesquote") { return; } function v(sel) { var el = f.querySelector(sel); return (el && el.value) ? el.value.trim() : ""; } var phone = v('[name="item_meta[13]"]').replace(/[^0-9+]/g, ""); if (phone && phone.charAt(0) !== "+") { phone = "+1" + phone.replace(/[^0-9]/g, ""); } try { sessionStorage.setItem("ag_ec", JSON.stringify({ em: v('[name="item_meta[12]"]').toLowerCase(), ph: phone, fn: v('[name="item_meta[10][first]"]'), ln: v('[name="item_meta[10][last]"]') })); } catch (err) {} }, true); })(); /* AutoGen - Google Ads enhanced conversions, part 2 of 2. On the quote confirmation page, hands the captured values to the Google tag so the page-load conversion is recorded as an enhanced conversion. Uses the standard dataLayer stub so it works whether it runs before or after Site Kit gtag.js. Does nothing on any other page. */ (function () { if (location.pathname.indexOf("extraction-services-contact-confirmation") === -1) { return; } var raw = null; try { raw = sessionStorage.getItem("ag_ec"); } catch (e) { return; } if (!raw) { return; } try { sessionStorage.removeItem("ag_ec"); } catch (e) {} var d; try { d = JSON.parse(raw); } catch (e) { return; } var user = {}; if (d.em) { user.email = d.em; } if (d.ph) { user.phone_number = d.ph; } if (d.fn || d.ln) { user.address = {}; if (d.fn) { user.address.first_name = d.fn; } if (d.ln) { user.address.last_name = d.ln; } } if (!user.email && !user.phone_number) { return; } window.dataLayer = window.dataLayer || []; function gtag() { window.dataLayer.push(arguments); } gtag("set", "user_data", user); })();