Customer Referral Predictor

Customer Referral Predictor

Analyze customer data to predict their likelihood of making a referral.

Awaiting Customer Data

Input a customer's details in the next tab to calculate their referral probability.

${results.recommendation}

`; document.getElementById('download-pdf-btn').addEventListener('click', handlePdfDownload); lucide.createIcons(); } async function handlePdfDownload() { if (!lastResults) return; const { jsPDF } = window.jspdf; // Populate PDF container document.getElementById('pdf-generation-date').textContent = new Date().toLocaleDateString(); const scoreEl = document.getElementById('pdf-score'); scoreEl.textContent = `${lastResults.probability}%`; scoreEl.className = `text-6xl font-bold ${lastResults.color}`; const scoreLevelEl = document.getElementById('pdf-score-level'); scoreLevelEl.textContent = lastResults.level; scoreLevelEl.className = `text-xl font-semibold mt-1 ${lastResults.color}`; document.getElementById('pdf-recommendation').textContent = lastResults.recommendation; document.getElementById('pdf-metrics-table').innerHTML = `
CSAT Score:${lastResults.metrics.csat}/10
Total Purchases:${lastResults.metrics.purchases}
Customer Tenure:${lastResults.metrics.tenureMonths} months
`; lucide.createIcons({ nodes: [document.getElementById('pdf-content')] }); try { await new Promise(resolve => setTimeout(resolve, 100)); // Allow icons to render const canvas = await html2canvas(document.getElementById('pdf-content'), { scale: 2 }); const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const imgProps = pdf.getImageProperties(imgData); const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width; pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight); pdf.save('Customer_Referral_Prediction.pdf'); } catch (e) { console.error("PDF generation failed:", e); alert("An error occurred generating the PDF."); } } // --- Event Listeners --- tabs.forEach((tab, index) => tab.btn.addEventListener('click', () => switchTab(index))); prevBtn.addEventListener('click', () => switchTab(currentTab - 1)); nextBtn.addEventListener('click', () => switchTab(currentTab + 1)); predictBtn.addEventListener('click', handlePrediction); csatScoreInput.addEventListener('input', () => { csatScoreVal.textContent = csatScoreInput.value; }); // --- Initialization --- const defaultDate = new Date(); defaultDate.setFullYear(defaultDate.getFullYear() - 2); customerSinceInput.value = defaultDate.toISOString().split('T')[0]; switchTab(0); updateNavButtons(); lucide.createIcons(); });
Scroll to Top