Customer Adoption Dashboard Customer Adoption Dashboard Dashboard Data Configuration Overall Customer Adoption Metrics Total Customers 0 New Customers (Last 30 Days) 0 Monthly Active Users (MAU) 0 Overall Adoption Rate 0.00% Onboarding Completion Rate 0.00% Retention Rate (Last 30 Days) 0.00% Churn Rate (Last 30 Days) 0.00% Key Feature Adoption Feature Name Users Engaged Adoption Rate (%) Download Dashboard as PDF Configure Customer Data Total Customers: New Customers (Last 30 Days): Monthly Active Users (MAU): Onboarding Completions (from New Customers): Previous Period Active Users: Cancelled/Inactive Users (Last 30 Days): Manage Key Features Adoption Feature Name: Users Engaged with Feature: Clear Feature Form Add Feature Existing Features Feature Name Users Engaged Actions Previous Next Retention Rate (Last 30 Days) ${displayRetentionRate.textContent} Churn Rate (Last 30 Days) ${displayChurnRate.textContent} Key Feature Adoption Feature Name Users Engaged Adoption Rate (%) ${featureAdoptionHtml} `; // 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_Adoption_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 = [ totalCustomersInput, newCustomersLast30DaysInput, monthlyActiveUsersInput, onboardingCompletionsInput, prevPeriodActiveUsersInput, cancelledInactiveUsersInput ]; mainMetricInputs.forEach(input => { if (input) { input.addEventListener('input', function() { updateCustomerMetricsFromInputs(); renderDashboard(); // Update dashboard in real-time }); } }); // Add/Update Feature button if (addUpdateFeatureBtn) { addUpdateFeatureBtn.addEventListener('click', addUpdateFeature); } // Clear Feature Form button if (clearFeatureFormBtn) { clearFeatureFormBtn.addEventListener('click', clearFeatureForm); } // PDF download button if (downloadPdfBtn) { downloadPdfBtn.addEventListener('click', downloadPdf); } // --- Initial Load --- populateInputFields(); // Populate main metric inputs with initial data clearFeatureForm(); // Initialize feature form renderDashboard(); // Render dashboard with initial data renderExistingFeaturesTable(); // Render existing features in config tab switchTab('dashboard'); // Ensure dashboard tab is active on load });