Marketing Reporting Dashboard

Marketing Reporting Dashboard

A summary of marketing spend, revenue, and return on investment.

Monthly Marketing Spend vs. Revenue

Cost Per Acquisition (CPA) by Channel

Campaign ROI Distribution

$${metrics.totalRevenue.toLocaleString()}

Overall ROI

${metrics.overallRoi.toFixed(1)}%

Average CPA

$${metrics.avgCpa.toFixed(2)}

`; renderChartsForTab('dashboard'); }; const renderConfigTab = () => { const configPane = document.getElementById('config-tab'); if(!configPane) return; configPane.innerHTML = `

Configure Reporting Data

Edit the JSON data below to update the dashboard.

`; document.getElementById('data-config-input').value = JSON.stringify(reportingData, null, 2); document.getElementById('update-dashboard-btn').addEventListener('click', handleUpdateDashboard); }; // --- CHART RENDERING --- const renderChartsForTab = (tabId) => { if (tabId !== 'dashboard') return; destroyCharts(); chartInstances.line = new Chart(document.getElementById('line-chart').getContext('2d'), { type: 'line', data: { labels: reportingData.monthlyPerformance.labels, datasets: [ { label: 'Spend ($)', data: reportingData.monthlyPerformance.spend, borderColor: 'rgba(249, 115, 22, 1)', yAxisID: 'y', tension: 0.3 }, { label: 'Revenue ($)', data: reportingData.monthlyPerformance.revenue, borderColor: 'rgba(22, 163, 74, 1)', yAxisID: 'y1', tension: 0.3 } ] }, options: { responsive: true, maintainAspectRatio: true, scales: { y: { type: 'linear', display: true, position: 'left', title: { display: true, text: 'Spend ($)'} }, y1: { type: 'linear', display: true, position: 'right', grid: { drawOnChartArea: false }, title: { display: true, text: 'Revenue ($)'} } } } }); chartInstances.bar = new Chart(document.getElementById('bar-chart').getContext('2d'), { type: 'bar', data: { labels: reportingData.cpaByChannel.labels, datasets: [{ label: 'CPA ($)', data: reportingData.cpaByChannel.data, backgroundColor: 'rgba(14, 165, 233, 0.6)' }] }, options: { responsive: true, maintainAspectRatio: true } }); chartInstances.pie = new Chart(document.getElementById('pie-chart').getContext('2d'), { type: 'pie', data: { labels: reportingData.campaignRoi.labels, datasets: [{ label: 'ROI (%)', data: reportingData.campaignRoi.data, backgroundColor: ['#0ea5e9', '#f97316', '#16a34a', '#9333ea'] }] }, options: { responsive: true, maintainAspectRatio: true } }); }; // --- NAVIGATION & EVENT HANDLING --- const showTab = (tabIndex) => { currentTab = tabIndex; const tabId = tabs[tabIndex]; document.querySelectorAll('.tab-pane').forEach(pane => pane.classList.add('hidden')); document.getElementById(`${tabId}-tab`).classList.remove('hidden'); document.querySelectorAll('.tab-btn').forEach(btn => btn.classList.remove('active')); document.querySelector(`.tab-btn[data-tab='${tabId}']`).classList.add('active'); prevBtn.style.visibility = (currentTab === 0) ? 'hidden' : 'visible'; nextBtn.style.visibility = (currentTab >= tabs.length - 2) ? 'hidden' : 'visible'; downloadPdfBtn.style.visibility = (tabId === 'config') ? 'hidden' : 'visible'; if (tabId === 'dashboard') { renderDashboardTab(); } }; tabNavigation.addEventListener('click', (e) => { if (e.target.matches('.tab-btn')) { const tabId = e.target.dataset.tab; const tabIndex = tabs.indexOf(tabId); showTab(tabIndex); } }); nextBtn.addEventListener('click', () => { if (currentTab < tabs.length - 1) showTab(currentTab + 1); }); prevBtn.addEventListener('click', () => { if (currentTab > 0) showTab(currentTab - 1); }); const handleUpdateDashboard = () => { const configInput = document.getElementById('data-config-input'); const errorDiv = document.getElementById('json-error'); const errorMessage = document.getElementById('json-error-message'); try { const newData = JSON.parse(configInput.value); reportingData = newData; errorDiv.classList.add('hidden'); renderDashboardTab(); alert('Dashboard updated successfully!'); showTab(0); } catch (error) { errorMessage.textContent = 'Invalid JSON format. ' + error.message; errorDiv.classList.remove('hidden'); } }; // --- PDF GENERATION --- downloadPdfBtn.addEventListener('click', () => { const { jsPDF } = window.jspdf; const pdfContainer = document.getElementById('pdf-content-container'); const activeTabElement = document.getElementById('dashboard-tab'); if (!pdfContainer || !activeTabElement) return; const clone = activeTabElement.cloneNode(true); pdfContainer.innerHTML = ''; pdfContainer.appendChild(clone); html2canvas(pdfContainer, { scale: 2, useCORS: true, logging: false, width: pdfContainer.scrollWidth, height: pdfContainer.scrollHeight }) .then(canvas => { const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = pdf.internal.pageSize.getHeight(); const imgWidth = canvas.width; const imgHeight = canvas.height; const ratio = imgWidth / imgHeight; let finalImgHeight = pdfWidth / ratio; let heightLeft = finalImgHeight; let position = 0; pdf.text(`Marketing Reporting Dashboard`, 40, 40); pdf.addImage(imgData, 'PNG', 0, 60, pdfWidth, finalImgHeight); heightLeft -= (pdfHeight - 60); while (heightLeft > 0) { position = heightLeft - finalImgHeight; pdf.addPage(); pdf.addImage(imgData, 'PNG', 0, position, pdfWidth, finalImgHeight); heightLeft -= pdfHeight; } pdf.save(`Marketing_Reporting_Report.pdf`); pdfContainer.innerHTML = ''; }).catch(err => { console.error("PDF generation failed:", err); alert("Sorry, there was an error creating the PDF."); }); }); // --- INITIALIZATION --- createTabs(); renderAllTabs(); showTab(0); });
Scroll to Top