Customer Interaction Dashboard

Customer Interaction Dashboard

Overall Interaction Metrics

Total Interactions

0

Unique Customers Interacted

0

Avg. Interactions per Customer

0.00

Avg. Handle Time (minutes)

0.00

First Contact Resolution Rate

0.00%

Overall Interaction Sentiment

Neutral

Interaction Volume by Channel

Channel Volume % of Total

Top Interaction Reasons/Topics

Reason/Topic Volume % of Total

Avg. Interactions per Customer

${displayAvgInteractionsPerCustomer.textContent}

Avg. Handle Time (minutes)

${displayAHT.textContent}

First Contact Resolution Rate

${displayFCRRate.textContent}

Overall Interaction Sentiment

${displayOverallSentiment.textContent}

Interaction Volume by Channel

${channelBreakdownHtml}
Channel Volume % of Total

Top Interaction Reasons/Topics

${reasonBreakdownHtml}
Reason/Topic Volume % of Total
`; // Append to body temporarily to render for html2canvas document.body.appendChild(pdfContentWrapper); try { const canvas = await html2canvas(pdfContentWrapper, { scale: 2, // Increase scale for better resolution useCORS: true, // Required if images are from different origin (though we don't use images here) logging: false // Disable logging for cleaner console }); const imgData = canvas.toDataURL('image/png'); const pdf = new window.jspdf.jsPDF({ orientation: 'portrait', unit: 'mm', format: 'a4' }); const imgWidth = 210; // A4 width in mm const pageHeight = 297; // A4 height in mm const imgHeight = canvas.height * imgWidth / canvas.width; let heightLeft = imgHeight; let position = 0; pdf.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight); heightLeft -= pageHeight; while (heightLeft >= 0) { position = heightLeft - imgHeight; pdf.addPage(); pdf.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight); heightLeft -= pageHeight; } pdf.save('Customer_Interaction_Dashboard.pdf'); } catch (error) { console.error('Error generating PDF:', error); // Provide a user-friendly message if PDF generation fails alert('Failed to generate PDF. Please try again.'); } finally { // Remove the temporary wrapper document.body.removeChild(pdfContentWrapper); } } // --- Event Listeners --- // Tab switching if (dashboardTabBtn) { dashboardTabBtn.addEventListener('click', function() { switchTab('dashboard'); }); } if (dataConfigTabBtn) { dataConfigTabBtn.addEventListener('click', function() { switchTab('dataConfig'); }); } // Navigation buttons if (prevTabBtn) { prevTabBtn.addEventListener('click', function() { if (currentActiveTab === 'dataConfig') { switchTab('dashboard'); } }); } if (nextTabBtn) { nextTabBtn.addEventListener('click', function() { if (currentActiveTab === 'dashboard') { switchTab('dataConfig'); } }); } // Main metrics input change listener (for real-time updates) const mainMetricInputs = [ totalInteractionsInput, uniqueCustomersInput, totalHandleTimeMinutesInput, fcrInteractionsInput, positiveSentimentCountInput, negativeSentimentCountInput ]; mainMetricInputs.forEach(input => { if (input) { input.addEventListener('input', function() { updateInteractionMetricsFromInputs(); renderDashboard(); // Update dashboard in real-time }); } }); // Add/Update Channel button if (addUpdateChannelBtn) { addUpdateChannelBtn.addEventListener('click', addUpdateChannel); } // Clear Channel Form button if (clearChannelFormBtn) { clearChannelFormBtn.addEventListener('click', clearChannelForm); } // Add/Update Reason button if (addUpdateReasonBtn) { addUpdateReasonBtn.addEventListener('click', addUpdateReason); } // Clear Reason Form button if (clearReasonFormBtn) { clearReasonFormBtn.addEventListener('click', clearReasonForm); } // PDF download button if (downloadPdfBtn) { downloadPdfBtn.addEventListener('click', downloadPdf); } // --- Initial Load --- populateInputFields(); // Populate main metric inputs with initial data clearChannelForm(); // Initialize channel form clearReasonForm(); // Initialize reason form renderDashboard(); // Render dashboard with initial data renderExistingChannelsTable(); // Render existing channels in config tab renderExistingReasonsTable(); // Render existing reasons in config tab switchTab('dashboard'); // Ensure dashboard tab is active on load });
Scroll to Top