E-commerce AI Sentiment Tracking Dashboard

E-commerce AI Sentiment Tracking Dashboard

Analyze customer feedback to understand sentiment trends.

No data analyzed. Please paste your review data in the 'Data Input' tab.

${r.product}

${r.sentiment}

${r.review}

`).join(''); renderChart(); } feather.replace(); }; const renderChart = () => { const ctx = document.getElementById('sentiment-chart').getContext('2d'); if (sentimentChart) sentimentChart.destroy(); sentimentChart = new Chart(ctx, { type: 'doughnut', data: { labels: ['Positive', 'Neutral', 'Negative'], datasets: [{ data: [state.analysis.sentimentCounts.Positive, state.analysis.sentimentCounts.Neutral, state.analysis.sentimentCounts.Negative], backgroundColor: ['#22c55e', '#a1a1aa', '#ef4444'] }] }, options: { responsive: true, plugins: { legend: { position: 'top' }, title: { display: true, text: 'Sentiment Breakdown' } } } }); }; // --- INITIALIZATION & EVENT HANDLERS --- function initialize() { analyzeBtn.addEventListener('click', analyzeData); downloadPdfBtn.addEventListener('click', generatePdf); feather.replace(); } const switchTab = (tabName) => { state.currentTab = tabName; Object.values(tabButtons).forEach(b => b.classList.remove('active')); Object.values(tabContents).forEach(c => c.classList.add('hidden')); if(tabButtons[tabName]) tabButtons[tabName].classList.add('active'); if(tabContents[tabName]) tabContents[tabName].classList.remove('hidden'); }; Object.keys(tabButtons).forEach(k => tabButtons[k]?.addEventListener('click', () => switchTab(k))); // --- PDF GENERATION --- async function generatePdf() { if (!state.analysis) return; const { jsPDF } = window.jspdf; document.getElementById('pdf-report-date').textContent = `Generated: ${new Date().toLocaleString()}`; document.getElementById('pdf-summary-grid').innerHTML = `

Overall Sentiment

${state.analysis.overall}

Positive

${state.analysis.percentages.positive.toFixed(1)}%

Negative

${state.analysis.percentages.negative.toFixed(1)}%
`; document.getElementById('pdf-chart-img').src = sentimentChart.toBase64Image(); const tableHTML = `${state.analysis.reviewedData.slice(0, 5).map(r => ``).join('')}
ProductReview SnippetSentiment
${r.product}${r.review.substring(0, 50)}...${r.sentiment}
`; document.getElementById('pdf-table-container').innerHTML = tableHTML; const pdfContainer = document.getElementById('pdf-container'); pdfContainer.classList.remove('invisible', '-left-[9999px]'); try { const canvas = await html2canvas(document.getElementById('pdf-report'), { scale: 2 }); const imgData = canvas.toDataURL('image/jpeg', 0.9); const pdf = new jsPDF({ orientation: 'p', unit: 'px', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = (canvas.height * pdfWidth) / canvas.width; pdf.addImage(imgData, 'JPEG', 0, 0, pdfWidth, pdfHeight); pdf.save('Sentiment_Analysis_Report.pdf'); } catch (error) { console.error("PDF generation failed:", error); } finally { pdfContainer.classList.add('invisible', '-left-[9999px]'); } } initialize(); });
Scroll to Top