Add insurance lead capture to DOT compliance checker

When a carrier has a red insurance check, shows a pre-checked
checkbox with "Get a free trucking insurance quote". Form
pre-fills carrier name and phone from FMCSA data. Submits
lead to /api/v1/tickets as category "insurance_lead" with
carrier details, fleet size, and insurance deficiency info.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
justin 2026-05-28 23:44:58 -05:00
parent 068739cb20
commit 8e6888ff6e

View file

@ -230,6 +230,28 @@ Send reset link
html += '</div></div>';
});
// Insurance lead capture — auto-checked if insurance issue found
var hasInsuranceIssue = (data.checks || []).some(function(c) {
return c.id === "insurance" && c.status === "red";
});
if (hasInsuranceIssue) {
html += '<div class="bg-blue-50 border-2 border-blue-300 rounded-xl p-5 mt-2">';
html += '<label class="flex items-start gap-3 cursor-pointer">';
html += '<input type="checkbox" id="ins-lead-check" checked class="mt-1 accent-blue-600 w-5 h-5">';
html += '<div>';
html += '<span class="font-bold text-blue-900 text-sm">Get a free trucking insurance quote</span>';
html += '<p class="text-xs text-blue-700 mt-1">Your FMCSA insurance filing shows a gap. We can connect you with a licensed trucking insurance agent to get you properly covered — no obligation.</p>';
html += '</div></label>';
html += '<div id="ins-lead-form" class="mt-3 ml-8 space-y-2">';
html += '<input type="text" id="ins-lead-name" placeholder="Your name" value="' + (data.legal_name || '') + '" class="w-full px-3 py-2 text-sm border border-blue-200 rounded-lg outline-none focus:border-blue-400">';
html += '<input type="email" id="ins-lead-email" placeholder="Email address" class="w-full px-3 py-2 text-sm border border-blue-200 rounded-lg outline-none focus:border-blue-400">';
html += '<input type="tel" id="ins-lead-phone" placeholder="Phone number" value="' + (data.telephone || '') + '" class="w-full px-3 py-2 text-sm border border-blue-200 rounded-lg outline-none focus:border-blue-400">';
html += '<button type="button" id="ins-lead-submit" class="px-6 py-2 bg-blue-600 text-white font-semibold rounded-lg text-sm hover:bg-blue-700">Request Insurance Quote</button>';
html += '<p id="ins-lead-status" class="text-xs hidden"></p>';
html += '</div></div>';
}
// CTA
var redCount = (s.red || 0);
if (redCount > 0) {
@ -248,6 +270,70 @@ Send reset link
resultsEl.innerHTML = html;
resultsEl.classList.remove("hidden");
// Insurance lead checkbox toggle
var insCheck = document.getElementById("ins-lead-check");
var insForm = document.getElementById("ins-lead-form");
if (insCheck && insForm) {
insCheck.addEventListener("change", function() {
insForm.style.display = insCheck.checked ? "block" : "none";
});
}
// Insurance lead submit
var insBtn = document.getElementById("ins-lead-submit");
if (insBtn) {
insBtn.addEventListener("click", function() {
var name = document.getElementById("ins-lead-name").value.trim();
var email = document.getElementById("ins-lead-email").value.trim();
var phone = document.getElementById("ins-lead-phone").value.trim();
var statusEl = document.getElementById("ins-lead-status");
if (!email) { statusEl.textContent = "Please enter your email."; statusEl.className = "text-xs text-red-600"; statusEl.classList.remove("hidden"); return; }
insBtn.disabled = true;
insBtn.textContent = "Submitting...";
fetch(API + "/api/v1/tickets", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
category: "insurance_lead",
subject: "Insurance Lead — " + data.legal_name + " (DOT " + data.dot_number + ")",
message: [
"Insurance lead from DOT Compliance Checker.",
"",
"Carrier: " + data.legal_name,
"DOT#: " + data.dot_number,
"Location: " + (data.phy_city || "") + ", " + (data.phy_state || ""),
"Fleet: " + (data.fleet ? data.fleet.power_units + " trucks, " + data.fleet.drivers + " drivers" : "unknown"),
"Phone: " + (phone || data.telephone || "not provided"),
"",
"Insurance deficiency: " + ((data.checks || []).filter(function(c) { return c.id === "insurance"; })[0] || {}).detail,
"",
"Contact: " + name,
"Email: " + email,
"Phone: " + phone,
].join("\n"),
email: email,
name: name,
})
}).then(function(r) {
if (r.ok) {
statusEl.textContent = "Submitted! We'll be in touch within 1 business day.";
statusEl.className = "text-xs text-green-700";
statusEl.classList.remove("hidden");
insBtn.textContent = "Submitted";
} else {
throw new Error("Failed");
}
}).catch(function() {
statusEl.textContent = "Something went wrong. Email info@performancewest.net instead.";
statusEl.className = "text-xs text-red-600";
statusEl.classList.remove("hidden");
insBtn.disabled = false;
insBtn.textContent = "Request Insurance Quote";
});
});
}
}
// Auto-fill from URL