- Add PublicCampaignsController for public campaign analytics
- Add public routes for /public/analytics/{slug} and /api/campaigns/{slug}
- Add public campaign analytics view with charts and KPIs
- Support for campaign sharing via custom slugs
- Real-time analytics with ApexCharts integration
1 line
1.9 KiB
JavaScript
1 line
1.9 KiB
JavaScript
export default()=>({charts:{},initChart(t,e={}){if("undefined"==typeof ApexCharts)return void console.error("ApexCharts library not loaded");const r=document.getElementById(t);if(!r)return void console.error(`Chart element with id "${t}" not found`);if(r.hasAttribute("_apexcharts_instance_"))return;const a={chart:{toolbar:{show:!1},animations:{enabled:!0}},colors:this.getChartColors(t),dataLabels:{enabled:!1},legend:{show:!0},grid:{show:!0}},s=this.mergeDeep(a,e);this.charts[t]=new ApexCharts(r,s),this.charts[t].render(),console.log(`Chart "${t}" initialized successfully`)},getChartColors(t){const e=document.getElementById(t);if(!e)return[];const r=e.getAttribute("data-colors");if(!r)return[];try{return JSON.parse(r).map(t=>t.startsWith("--")?getComputedStyle(document.documentElement).getPropertyValue(t):t)}catch(e){return console.error(`Error parsing colors for chart "${t}":`,e),[]}},mergeDeep(t,e){const r={...t};for(const t in e)e[t]&&"object"==typeof e[t]&&!Array.isArray(e[t])?r[t]=this.mergeDeep(r[t]||{},e[t]):r[t]=e[t];return r},updateChart(t,e){this.charts[t]&&this.charts[t].updateSeries(e)},destroyChart(t){this.charts[t]&&(this.charts[t].destroy(),delete this.charts[t])},createLineChart(t,e,r,a={}){const s={series:e,chart:{type:"line",height:350},xaxis:{categories:r},stroke:{curve:"smooth",width:3},...a};this.initChart(t,s)},createBarChart(t,e,r,a={}){const s={series:e,chart:{type:"bar",height:350},xaxis:{categories:r},plotOptions:{bar:{horizontal:!1,columnWidth:"55%"}},...a};this.initChart(t,s)},createPieChart(t,e,r={}){const a={series:e,chart:{type:"pie",height:350},labels:r.labels||[],...r};this.initChart(t,a)},createAreaChart(t,e,r,a={}){const s={series:e,chart:{type:"area",height:350},xaxis:{categories:r},stroke:{curve:"smooth"},fill:{opacity:.3},...a};this.initChart(t,s)},createRadarChart(t,e,r,a={}){const s={series:e,chart:{type:"radar",height:350},xaxis:{categories:r},stroke:{width:2},fill:{opacity:.2},...a};this.initChart(t,s)}}); |