Customer Referral Dashboard
Key Referral Performance Indicators
Referral Program Insights
No insights generated yet. Please configure your data.
Data Configuration
Define your customer referral metrics, targets, and actuals. Click 'Add Metric' to add more rows.
Customer Referral Dashboard Report
Key Referral Performance Indicators
Referral Program Insights
Actual: ${formatValue(metric.actual, metric.unit)}
Progress: ${progress.toFixed(2)}%
No metrics defined to generate insights. Please add metrics in the Data Configuration tab.
'; } else { let overallProgress = 0; let metricsBelowTarget = []; let metricsAboveTarget = []; let significantProgress = []; referralMetrics.forEach(metric => { const progress = calculateProgress(metric.actual, metric.target); overallProgress += progress; if (progress < 100 && metric.actual < metric.target) { metricsBelowTarget.push({ name: metric.name, progress: progress.toFixed(2) }); } else if (progress >= 100 && metric.actual >= metric.target) { metricsAboveTarget.push({ name: metric.name, progress: progress.toFixed(2) }); } if (progress >= 90) { significantProgress.push({ name: metric.name, progress: progress.toFixed(2) }); } }); const avgProgress = referralMetrics.length > 0 ? (overallProgress / referralMetrics.length).toFixed(2) : 0; insightsHtml += `Overall Referral Program Performance: The average progress across all defined metrics is ${avgProgress}%.
`; if (metricsAboveTarget.length > 0) { insightsHtml += `Strengths: Excellent performance observed in: ${metricsAboveTarget.map(m => `${m.name} (${m.progress}%)`).join(', ')}. These areas indicate strong referral program success.
`; } if (metricsBelowTarget.length > 0) { insightsHtml += `Areas for Improvement: Metrics currently below target include: ${metricsBelowTarget.map(m => `${m.name} (${m.progress}%)`).join(', ')}. Focus efforts on these to boost referral performance.
`; } if (significantProgress.length > 0 && metricsAboveTarget.length === 0) { // Avoid redundancy if already listed in strengths insightsHtml += `Notable Progress: Metrics showing significant positive momentum (above 90% target) include: ${significantProgress.map(m => `${m.name} (${m.progress}%)`).join(', ')}.
`; } if (insightsHtml === '') { insightsHtml = 'No specific insights generated. Ensure your metrics have valid target and actual values.
'; } } referralInsights.innerHTML = insightsHtml; } // --- Event Handlers (Globally accessible for onclick attributes) --- /** * Switches between dashboard and data configuration tabs. * @param {string} tabName - 'dashboard' or 'dataConfig'. */ window.switchTab = function(tabName) { // Guard clauses for elements if (!dashboardTabBtn || !dataConfigTabBtn || !dashboardTabContent || !dataConfigTabContent || !prevTabBtn || !nextTabBtn) { console.error("One or more tab elements not found."); return; } currentTab = tabName; // Update button styles dashboardTabBtn.classList.remove('active'); dataConfigTabBtn.classList.remove('active'); dashboardTabContent.classList.add('hidden'); dataConfigTabContent.classList.add('hidden'); if (tabName === 'dashboard') { dashboardTabBtn.classList.add('active'); dashboardTabContent.classList.remove('hidden'); prevTabBtn.disabled = true; nextTabBtn.disabled = false; renderAllKpiCards(); // Re-render dashboard content when tab is active generateReferralInsights(); // Re-generate insights } else if (tabName === 'dataConfig') { dataConfigTabBtn.classList.add('active'); dataConfigTabContent.classList.remove('hidden'); prevTabBtn.disabled = false; nextTabBtn.disabled = true; renderAllMetricInputRows(); // Re-render input rows when tab is active } }; /** * Navigates between tabs using 'Next' and 'Previous' buttons. * @param {string} direction - 'prev' or 'next'. */ window.navigateTabs = function(direction) { if (direction === 'next') { if (currentTab === 'dashboard') { switchTab('dataConfig'); } } else if (direction === 'prev') { if (currentTab === 'dataConfig') { switchTab('dashboard'); } } }; /** * Adds a new empty metric row to the data configuration. */ if (addMetricBtn) { // Null check for addMetricBtn addMetricBtn.onclick = function() { const newMetricId = generateUniqueId(); const newMetric = { id: newMetricId, name: '', target: null, actual: null, unit: '' }; referralMetrics.push(newMetric); renderMetricInputRow(newMetric); showMessage('New metric row added.', 'info'); }; } /** * Updates a specific property of a metric in the referralMetrics array. * This function is called directly from input fields' oninput. * @param {string} id - The ID of the metric to update. * @param {string} property - The property to update ('name', 'target', 'actual', 'unit'). * @param {*} value - The new value for the property. */ window.updateMetricValue = function(id, property, value) { const metricIndex = referralMetrics.findIndex(m => m.id === id); if (metricIndex !== -1) { referralMetrics[metricIndex][property] = value; } }; /** * Removes a metric from the referralMetrics array and its corresponding input row. * @param {string} id - The ID of the metric to remove. */ window.removeMetric = function(id) { referralMetrics = referralMetrics.filter(m => m.id !== id); const metricRow = document.getElementById(`metric-row-${id}`); if (metricRow) { metricRow.remove(); showMessage('Metric removed successfully.', 'success'); } else { console.warn(`Metric row with ID ${id} not found for removal.`); } }; /** * Saves the data (which is already updated via oninput) and refreshes the dashboard. */ if (saveDataBtn) { // Null check for saveDataBtn saveDataBtn.onclick = function() { // Filter out any metrics that are completely empty or invalid referralMetrics = referralMetrics.filter(metric => metric.name.trim() !== '' || (typeof metric.target === 'number' && !isNaN(metric.target)) || (typeof metric.actual === 'number' && !isNaN(metric.actual)) ); // Ensure all numerical values are indeed numbers referralMetrics.forEach(metric => { metric.target = parseFloat(metric.target) || 0; metric.actual = parseFloat(metric.actual) || 0; }); renderAllKpiCards(); // Re-render dashboard generateReferralInsights(); // Re-generate insights showMessage('Data saved and dashboard updated!', 'success'); }; } /** * Handles the PDF download functionality. */ if (downloadPdfBtn) { // Null check for downloadPdfBtn downloadPdfBtn.onclick = async function() { if (!pdfContent || !pdfKpiMetrics || !pdfReferralInsights) { console.error("PDF content elements not found."); showMessage('Error: PDF content elements missing.', 'error'); return; } // Populate the hidden PDF content div with current dashboard data pdfKpiMetrics.innerHTML = `Key Referral Performance Indicators
`; if (referralMetrics.length === 0) { pdfKpiMetrics.innerHTML += 'No KPI data available.
'; } else { let kpiTableHtml = `| Metric Name | Target Value | Actual Value | Unit | Progress (%) |
|---|---|---|---|---|
| ${metric.name || 'N/A'} | ${formatValue(metric.target, metric.unit)} | ${formatValue(metric.actual, metric.unit)} | ${metric.unit || 'N/A'} | ${progress.toFixed(2)}% |
No insights generated. Please configure your data.
'; } else { let overallProgress = 0; let metricsBelowTarget = []; let metricsAboveTarget = []; referralMetrics.forEach(metric => { const progress = calculateProgress(metric.actual, metric.target); overallProgress += progress; if (progress < 100 && metric.actual < metric.target) { metricsBelowTarget.push({ name: metric.name, progress: progress.toFixed(2) }); } else if (progress >= 100 && metric.actual >= metric.target) { metricsAboveTarget.push({ name: metric.name, progress: progress.toFixed(2) }); } }); const avgProgress = referralMetrics.length > 0 ? (overallProgress / referralMetrics.length).toFixed(2) : 0; insightsForPdf += `Overall Referral Program Performance: The average progress across all defined metrics is ${avgProgress}%.
`; if (metricsAboveTarget.length > 0) { insightsForPdf += `Strengths: Excellent performance observed in: ${metricsAboveTarget.map(m => `${m.name} (${m.progress}%)`).join(', ')}. These areas indicate strong referral program success.
`; } if (metricsBelowTarget.length > 0) { insightsForPdf += `Areas for Improvement: Metrics currently below target include: ${metricsBelowTarget.map(m => `${m.name} (${m.progress}%)`).join(', ')}. Focus efforts on these to boost referral performance.
`; } insightsForPdf += `