Spaces:
Running
Running
Download script.js from TraceMDM/performancedashboard: direct link, hf CLI and curl.
- Browser
- Download file 14.9 kB
-
https://huggingface.co/spaces/TraceMDM/performancedashboard/resolve/main/script.js
- Command line
-
hf download hf://spaces/TraceMDM/performancedashboard/script.js
-
curl -L -o script.js https://huggingface.co/spaces/TraceMDM/performancedashboard/resolve/main/script.js
14.9 kB
| document.addEventListener('DOMContentLoaded', function() { | |
| const data = [ | |
| { location: 'Chadwell', metric: 'Avg CPC', baseline: '3.47', current: '1.80', trend: 'Improved' }, | |
| { location: 'Chadwell', metric: 'Cost per Conversion', baseline: '3.42', current: 'Lower or Stable', trend: 'Improved' }, | |
| { location: 'Ellicott City ER', metric: 'Avg CPC', baseline: '1.77', current: '1.80', trend: 'Stable' }, | |
| { location: 'Ellicott City ER', metric: 'Cost per Conversion', baseline: '5.81', current: 'Lower', trend: 'Improved' }, | |
| { location: 'Bay Beach', metric: 'Avg CPC', baseline: '3.19', current: '2.79', trend: 'Improved' }, | |
| { location: 'Bay Beach', metric: 'Cost per Conversion', baseline: '7.42', current: 'Lower', trend: 'Improved' }, | |
| { location: 'Beltsville', metric: 'Avg CPC', baseline: '1.96', current: '2.00', trend: 'Stable' }, | |
| { location: "Dr Dan's", metric: 'Avg CPC', baseline: '19.92', current: 'Much Lower', trend: 'Improved' }, | |
| { location: 'Hoffman', metric: 'Avg CPC', baseline: '3.60', current: '3.50', trend: 'Stable' }, | |
| { location: 'Mixed Pet', metric: 'Avg CPC', baseline: '10.43', current: 'Lower', trend: 'Improved' }, | |
| { location: 'Colonial', metric: 'Avg CPC', baseline: '9.15', current: 'Slightly Lower', trend: 'Improved' }, | |
| { location: 'Jackson Square', metric: 'Avg CPC', baseline: '6.21', current: 'Lower', trend: 'Improved' } | |
| ]; | |
| // Create two tables - one for CPC and one for Conversion metrics | |
| const cpcData = data.filter(item => item.metric === 'Avg CPC'); | |
| const conversionData = data.filter(item => item.metric === 'Cost per Conversion'); | |
| // Create CPC table | |
| const cpcTable = document.createElement('div'); | |
| cpcTable.className = 'mt-8 bg-white rounded-xl shadow-md overflow-hidden'; | |
| cpcTable.innerHTML = ` | |
| <div class="px-6 py-4 border-b border-gray-200"> | |
| <h2 class="text-xl font-semibold text-gray-800">CPC Performance</h2> | |
| </div> | |
| <div class="overflow-x-auto"> | |
| <table class="min-w-full divide-y divide-gray-200"> | |
| <thead class="bg-gray-50"> | |
| <tr> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Location</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">October Baseline</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Current (Nov-Dec)</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Trend</th> | |
| </tr> | |
| </thead> | |
| <tbody class="bg-white divide-y divide-gray-200" id="cpc-table"> | |
| ${cpcData.map(item => ` | |
| <tr class="hover:bg-gray-50"> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">${item.location}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${item.baseline}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${item.current}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm ${item.trend === 'Improved' ? 'trend-improved' : item.trend === 'Stable' ? 'trend-stable' : 'trend-worsened'} font-semibold"> | |
| <i data-feather="${item.trend === 'Improved' ? 'trending-up' : item.trend === 'Stable' ? 'minus' : 'trending-down'}" class="inline mr-1"></i> | |
| ${item.trend} | |
| </td> | |
| </tr> | |
| `).join('')} | |
| </tbody> | |
| </table> | |
| </div> | |
| `; | |
| // Create Conversion table | |
| const conversionTable = document.createElement('div'); | |
| conversionTable.className = 'mt-8 bg-white rounded-xl shadow-md overflow-hidden'; | |
| conversionTable.innerHTML = ` | |
| <div class="px-6 py-4 border-b border-gray-200"> | |
| <h2 class="text-xl font-semibold text-gray-800">Conversion Performance</h2> | |
| </div> | |
| <div class="overflow-x-auto"> | |
| <table class="min-w-full divide-y divide-gray-200"> | |
| <thead class="bg-gray-50"> | |
| <tr> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Location</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">October Baseline</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Current (Nov-Dec)</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Trend</th> | |
| </tr> | |
| </thead> | |
| <tbody class="bg-white divide-y divide-gray-200" id="conversion-table"> | |
| ${conversionData.map(item => ` | |
| <tr class="hover:bg-gray-50"> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">${item.location}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${item.baseline}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${item.current}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm ${item.trend === 'Improved' ? 'trend-improved' : item.trend === 'Stable' ? 'trend-stable' : 'trend-worsened'} font-semibold"> | |
| <i data-feather="${item.trend === 'Improved' ? 'trending-up' : item.trend === 'Stable' ? 'minus' : 'trending-down'}" class="inline mr-1"></i> | |
| ${item.trend} | |
| </td> | |
| </tr> | |
| `).join('')} | |
| </tbody> | |
| </table> | |
| </div> | |
| `; | |
| // Remove the original table container | |
| const originalTable = document.querySelector('.mt-12.bg-white.rounded-xl.shadow-md.overflow-hidden'); | |
| if (originalTable) { | |
| originalTable.remove(); | |
| } | |
| // Insert the new tables | |
| const main = document.querySelector('main'); | |
| main.insertBefore(cpcTable, document.querySelector('.mt-12')); | |
| main.insertBefore(conversionTable, document.querySelector('.mt-12')); | |
| // Create summary cards | |
| const cardsContainer = document.querySelector('.grid'); | |
| // Avg CPC Summary | |
| const avgCPCData = data.filter(item => item.metric === 'Avg CPC'); | |
| const improvedCPC = avgCPCData.filter(item => item.trend === 'Improved').length; | |
| const cpcCard = document.createElement('div'); | |
| cpcCard.className = 'bg-white rounded-xl shadow-card p-6'; | |
| cpcCard.innerHTML = ` | |
| <div class="flex justify-between items-start"> | |
| <div> | |
| <p class="text-sm font-medium text-gray-500">Avg CPC</p> | |
| <h3 class="mt-1 text-2xl font-semibold text-gray-900">${avgCPCData.length} Locations</h3> | |
| </div> | |
| <div class="p-3 rounded-lg bg-blue-100 text-blue-600"> | |
| <i data-feather="dollar-sign"></i> | |
| </div> | |
| </div> | |
| <div class="mt-6"> | |
| <div class="flex items-center justify-between mb-2"> | |
| <span class="text-sm font-medium text-gray-500">Improved</span> | |
| <span class="text-sm font-semibold text-green-600">${improvedCPC} (${Math.round((improvedCPC/avgCPCData.length)*100)}%)</span> | |
| </div> | |
| <div class="w-full bg-gray-200 rounded-full h-2"> | |
| <div class="bg-green-500 h-2 rounded-full" style="width: ${(improvedCPC/avgCPCData.length)*100}%"></div> | |
| </div> | |
| </div> | |
| `; | |
| cardsContainer.appendChild(cpcCard); | |
| // Cost per Conversion Summary | |
| const convData = data.filter(item => item.metric === 'Cost per Conversion'); | |
| const improvedConv = convData.filter(item => item.trend === 'Improved').length; | |
| const convCard = document.createElement('div'); | |
| convCard.className = 'bg-white rounded-xl shadow-card p-6'; | |
| convCard.innerHTML = ` | |
| <div class="flex justify-between items-start"> | |
| <div> | |
| <p class="text-sm font-medium text-gray-500">Cost per Conversion</p> | |
| <h3 class="mt-1 text-2xl font-semibold text-gray-900">${convData.length} Locations</h3> | |
| </div> | |
| <div class="p-3 rounded-lg bg-purple-100 text-purple-600"> | |
| <i data-feather="activity"></i> | |
| </div> | |
| </div> | |
| <div class="mt-6"> | |
| <div class="flex items-center justify-between mb-2"> | |
| <span class="text-sm font-medium text-gray-500">Improved</span> | |
| <span class="text-sm font-semibold text-green-600">${improvedConv} (${Math.round((improvedConv/convData.length)*100)}%)</span> | |
| </div> | |
| <div class="w-full bg-gray-200 rounded-full h-2"> | |
| <div class="bg-green-500 h-2 rounded-full" style="width: ${(improvedConv/convData.length)*100}%"></div> | |
| </div> | |
| </div> | |
| `; | |
| cardsContainer.appendChild(convCard); | |
| // Overall Performance | |
| const overallCard = document.createElement('div'); | |
| overallCard.className = 'bg-white rounded-xl shadow-card p-6'; | |
| overallCard.innerHTML = ` | |
| <div class="flex justify-between items-start"> | |
| <div> | |
| <p class="text-sm font-medium text-gray-500">Overall Performance</p> | |
| <h3 class="mt-1 text-2xl font-semibold text-gray-900">${data.length} Metrics</h3> | |
| </div> | |
| <div class="p-3 rounded-lg bg-green-100 text-green-600"> | |
| <i data-feather="bar-chart-2"></i> | |
| </div> | |
| </div> | |
| <div class="mt-6 space-y-4"> | |
| <div> | |
| <div class="flex items-center justify-between mb-1"> | |
| <span class="text-sm font-medium text-gray-500">Improved</span> | |
| <span class="text-sm font-semibold text-green-600">${data.filter(item => item.trend === 'Improved').length}</span> | |
| </div> | |
| <div class="w-full bg-gray-200 rounded-full h-2"> | |
| <div class="bg-green-500 h-2 rounded-full" style="width: ${(data.filter(item => item.trend === 'Improved').length/data.length)*100}%"></div> | |
| </div> | |
| </div> | |
| <div> | |
| <div class="flex items-center justify-between mb-1"> | |
| <span class="text-sm font-medium text-gray-500">Stable</span> | |
| <span class="text-sm font-semibold text-yellow-500">${data.filter(item => item.trend === 'Stable').length}</span> | |
| </div> | |
| <div class="w-full bg-gray-200 rounded-full h-2"> | |
| <div class="bg-yellow-400 h-2 rounded-full" style="width: ${(data.filter(item => item.trend === 'Stable').length/data.length)*100}%"></div> | |
| </div> | |
| </div> | |
| </div> | |
| `; | |
| cardsContainer.appendChild(overallCard); | |
| // Add strategic insights section | |
| const insightsData = [ | |
| { location: 'Chadwell', improved: 'CPC down ~48 percent, higher engagement', constrained: 'Call tracking not enabled', next: 'Enable call tracking and scale service campaigns' }, | |
| { location: 'Ellicott City ER', improved: 'Efficiency improved, calls rebounded', constrained: 'Temporary pharmacy policy pause', next: 'Restore budget and add call-only emergency ads' }, | |
| { location: 'Bay Beach', improved: 'Higher call and direction volume, CPC down', constrained: 'Impression share capped', next: 'Scale budget and launch remarketing' }, | |
| { location: 'Beltsville', improved: 'Improved traffic quality', constrained: 'Funnel optimization needed', next: 'Landing page and tracking improvements' }, | |
| { location: "Dr Dan's", improved: 'CPC significantly reduced', constrained: 'Tracking limitations', next: 'Fix tracking and relaunch campaigns' }, | |
| { location: 'Hoffman', improved: 'Higher engagement time', constrained: 'Low booking actions', next: 'Shift budget to booking-intent ads' }, | |
| { location: 'Mixed Pet', improved: 'Lower CPC and deeper sessions', constrained: 'Weak calls to action', next: 'Deploy booking-first landing pages' }, | |
| { location: 'Colonial', improved: 'Stable performance', constrained: 'UX and engagement issues', next: 'UX audit and simplified booking path' }, | |
| { location: 'Jackson Square', improved: 'Stable engagement', constrained: 'Limited scale and tracking', next: 'Improve tracking and cautiously scale' } | |
| ]; | |
| const insightsContainer = document.createElement('div'); | |
| insightsContainer.className = 'mt-12 bg-white rounded-xl shadow-md overflow-hidden'; | |
| insightsContainer.innerHTML = ` | |
| <div class="px-6 py-4 border-b border-gray-200"> | |
| <h2 class="text-xl font-semibold text-gray-800">Strategic Insights</h2> | |
| </div> | |
| <div class="overflow-x-auto"> | |
| <table class="min-w-full divide-y divide-gray-200"> | |
| <thead class="bg-gray-50"> | |
| <tr> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Location</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">What Improved</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">What Was Constrained</th> | |
| <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">What's Next</th> | |
| </tr> | |
| </thead> | |
| <tbody class="bg-white divide-y divide-gray-200" id="insights-table"> | |
| ${insightsData.map(item => ` | |
| <tr class="hover:bg-gray-50"> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">${item.location}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${item.improved}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${item.constrained}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${item.next}</td> | |
| </tr> | |
| `).join('')} | |
| </tbody> | |
| </table> | |
| </div> | |
| `; | |
| document.querySelector('main').appendChild(insightsContainer); | |
| // Refresh feather icons after dynamic content is added | |
| feather.replace(); | |
| }); |