|
@@ -370,6 +370,15 @@ function publicCampaignStats() {
stats: window.publicCampaignStatsData.stats,
init() {
+ // Initialize with empty data to prevent Alpine errors
+ this.stats = {
+ overview: { total_clicks: 0, unique_clicks: 0, unique_ips: 0, avg_response_time: 0 },
+ by_country: [],
+ by_device: [],
+ by_browser: [],
+ by_referral: [],
+ daily_hits: []
+ };
this.loadStats();
},
@@ -428,16 +437,22 @@ function publicCampaignStats() {
const ctx = document.getElementById('daily-hits-chart');
if (!ctx) return;
+ // Destroy existing chart if it exists
+ if (window.dailyHitsChart) {
+ window.dailyHitsChart.destroy();
+ }
+
// Use real daily hits data from database
const dailyData = this.stats.daily_hits || [];
if (dailyData.length === 0) {
// Show empty state if no data
- ctx.getContext('2d').clearRect(0, 0, ctx.width, ctx.height);
- ctx.getContext('2d').fillStyle = '#666';
- ctx.getContext('2d').font = '16px Arial';
- ctx.getContext('2d').textAlign = 'center';
- ctx.getContext('2d').fillText('No data available for the selected period', ctx.width / 2, ctx.height / 2);
+ const canvas = ctx.getContext('2d');
+ canvas.clearRect(0, 0, ctx.width, ctx.height);
+ canvas.fillStyle = '#666';
+ canvas.font = '16px Arial';
+ canvas.textAlign = 'center';
+ canvas.fillText('No data available for the selected period', ctx.width / 2, ctx.height / 2);
return;
}
@@ -447,7 +462,7 @@ function publicCampaignStats() {
});
const values = dailyData.map(d => parseInt(d.hits));
- new Chart(ctx, {
+ window.dailyHitsChart = new Chart(ctx, {
type: 'line',
data: {
labels: labels,
@@ -494,10 +509,15 @@ function publicCampaignStats() {
const ctx = document.getElementById('country-chart');
if (!ctx) return;
+ // Destroy existing chart if it exists
+ if (window.countryChart) {
+ window.countryChart.destroy();
+ }
+
const countries = (this.stats.by_country || []).slice(0, 5); // Limit to top 5
const colors = ['#556ee6', '#f1b44c', '#34c38f', '#f46a6a', '#50a5f1'];
- new Chart(ctx, {
+ window.countryChart = new Chart(ctx, {
type: 'doughnut',
data: {
labels: countries.map(c => c.country_name || c.country_code),
@@ -531,8 +551,13 @@ function publicCampaignStats() {
const ctx = document.getElementById('device-chart');
if (!ctx) return;
+ // Destroy existing chart if it exists
+ if (window.deviceChart) {
+ window.deviceChart.destroy();
+ }
+
const devices = this.stats.by_device || [];
- new Chart(ctx, {
+ window.deviceChart = new Chart(ctx, {
type: 'bar',
data: {
labels: devices.map(d => d.device_type),
@@ -558,6 +583,11 @@ function publicCampaignStats() {
const ctx = document.getElementById('browser-chart');
if (!ctx) return;
+ // Destroy existing chart if it exists
+ if (window.browserChart) {
+ window.browserChart.destroy();
+ }
+
const browsers = (this.stats.by_browser || []).slice(0, 6); // Limit to top 6
const colors = ['#556ee6', '#f1b44c', '#34c38f', '#f46a6a', '#50a5f1', '#6c757d'];
@@ -569,7 +599,7 @@ function publicCampaignStats() {
return name;
});
- new Chart(ctx, {
+ window.browserChart = new Chart(ctx, {
type: 'pie',
data: {
labels: cleanBrowsers,
diff --git a/public/assets/css/public.min.css b/public/assets/css/public.min.css
new file mode 100644
index 0000000..e69de29
|