true, 'filters' => [ 'sources' => [ ['value' => 'google', 'label' => 'google'], ['value' => 'facebook', 'label' => 'facebook'], ['value' => 'instagram', 'label' => 'instagram'], ['value' => 'email', 'label' => 'email'], ['value' => 'direct', 'label' => 'direct'], ], 'mediums' => [ ['value' => 'cpc', 'label' => 'cpc'], ['value' => 'organic', 'label' => 'organic'], ['value' => 'social', 'label' => 'social'], ['value' => 'email', 'label' => 'email'], ['value' => 'referral', 'label' => 'referral'], ], 'campaigns' => [ ['value' => 'summer_promo_2025', 'label' => 'summer_promo_2025'], ['value' => 'weekend_special', 'label' => 'weekend_special'], ['value' => 'anniversary_event', 'label' => 'anniversary_event'], ['value' => 'valentines_day', 'label' => 'valentines_day'], ['value' => 'new_menu_launch', 'label' => 'new_menu_launch'], ], 'terms' => [ ['value' => 'restaurant_zaragoza', 'label' => 'restaurant_zaragoza'], ['value' => 'best_restaurant', 'label' => 'best_restaurant'], ['value' => 'dinner_reservation', 'label' => 'dinner_reservation'], ['value' => 'romantic_dinner', 'label' => 'romantic_dinner'], ], 'contents' => [ ['value' => 'banner_top', 'label' => 'banner_top'], ['value' => 'sidebar_ad', 'label' => 'sidebar_ad'], ['value' => 'story_post', 'label' => 'story_post'], ['value' => 'newsletter_link', 'label' => 'newsletter_link'], ] ] ]; } /** * Return demo tracking data with realistic distribution */ protected function getDemoData() { $trackings = []; $now = date('Y-m-d H:i:s'); $currentMonth = date('Y-m'); // Define campaigns with their properties $campaigns = [ [ 'campaign' => 'summer_promo_2025', 'source' => 'google', 'medium' => 'cpc', 'term' => 'restaurant_zaragoza', 'content' => 'banner_top', 'weight' => 35 // 35% of traffic ], [ 'campaign' => 'weekend_special', 'source' => 'facebook', 'medium' => 'social', 'term' => 'best_restaurant', 'content' => 'story_post', 'weight' => 25 ], [ 'campaign' => 'anniversary_event', 'source' => 'instagram', 'medium' => 'social', 'term' => 'romantic_dinner', 'content' => 'story_post', 'weight' => 20 ], [ 'campaign' => null, // Direct traffic 'source' => 'direct', 'medium' => 'none', 'term' => null, 'content' => null, 'weight' => 10 ], [ 'campaign' => 'new_menu_launch', 'source' => 'email', 'medium' => 'email', 'term' => null, 'content' => 'newsletter_link', 'weight' => 7 ], [ 'campaign' => 'valentines_day', 'source' => 'google', 'medium' => 'organic', 'term' => 'dinner_reservation', 'content' => null, 'weight' => 3 ] ]; // Generate 180 tracking records over the past 30 days $totalTrackings = 180; $id = 1; for ($i = 0; $i < $totalTrackings; $i++) { // Select campaign based on weight $campaign = $this->selectWeightedCampaign($campaigns); // Generate random date in current month $daysAgo = rand(0, 29); $hoursAgo = rand(0, 23); $minutesAgo = rand(0, 59); $dateCreated = date('Y-m-d H:i:s', strtotime("-{$daysAgo} days -{$hoursAgo} hours -{$minutesAgo} minutes")); // 40% of trackings result in bookings $hasBooking = (rand(1, 100) <= 40); $trackings[] = [ 'id' => $id++, 'restaurant_id' => 1, 'booking_id' => $hasBooking ? rand(1000, 9999) : null, 'utm_source' => $campaign['source'], 'utm_medium' => $campaign['medium'], 'utm_campaign' => $campaign['campaign'], 'utm_term' => $campaign['term'], 'utm_content' => $campaign['content'], 'user_agent' => $this->getRandomUserAgent(), 'ip_address' => $this->getRandomIP(), 'date_created' => $dateCreated ]; } // Sort by date_created desc usort($trackings, function($a, $b) { return strcmp($b['date_created'], $a['date_created']); }); // Calculate statistics $stats = $this->calculateDemoStats($trackings, $currentMonth); return [ 'success' => true, 'trackings' => $trackings, 'stats' => $stats, 'filters_applied' => [ 'period' => $currentMonth, 'utm_source' => 'all', 'utm_medium' => 'all', 'utm_campaign' => 'all', 'utm_term' => 'all', 'utm_content' => 'all' ] ]; } /** * Select a campaign based on weighted distribution */ protected function selectWeightedCampaign($campaigns) { $rand = rand(1, 100); $cumulative = 0; foreach ($campaigns as $campaign) { $cumulative += $campaign['weight']; if ($rand <= $cumulative) { return $campaign; } } return $campaigns[0]; // Fallback } /** * Calculate statistics for demo data */ protected function calculateDemoStats($trackings, $currentMonth) { $total_trackings = count($trackings); $confirmed_bookings = 0; $total_party = 0; $by_source = []; $by_medium = []; $by_campaign = []; foreach ($trackings as $tracking) { // Count bookings if ($tracking['booking_id']) { $confirmed_bookings++; $total_party += rand(2, 6); // Random party size 2-6 } // Group by source $source = $tracking['utm_source'] ?: 'Direct'; if (!isset($by_source[$source])) { $by_source[$source] = 0; } $by_source[$source]++; // Group by medium $medium = $tracking['utm_medium'] ?: 'None'; if (!isset($by_medium[$medium])) { $by_medium[$medium] = 0; } $by_medium[$medium]++; // Group by campaign $campaign = $tracking['utm_campaign'] ?: 'None'; if (!isset($by_campaign[$campaign])) { $by_campaign[$campaign] = 0; } $by_campaign[$campaign]++; } // Sort by count descending arsort($by_source); arsort($by_medium); arsort($by_campaign); $conversion_rate = $total_trackings > 0 ? round(($confirmed_bookings / $total_trackings) * 100, 2) : 0; $avg_party_size = $confirmed_bookings > 0 ? round($total_party / $confirmed_bookings, 1) : 0; $dateStart = $currentMonth . '-01 00:00:00'; $dateEnd = date('Y-m-t', strtotime($currentMonth . '-01')) . ' 23:59:59'; return [ 'total_trackings' => $total_trackings, 'confirmed_bookings' => $total_trackings + 100, //$confirmed_bookings, 'conversion_rate' => $conversion_rate, 'avg_party_size' => $avg_party_size, 'by_source' => $by_source, 'by_medium' => $by_medium, 'by_campaign' => $by_campaign, 'period_start' => $dateStart, 'period_end' => $dateEnd ]; } /** * Get random user agent */ protected function getRandomUserAgent() { $userAgents = [ 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36', 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1', 'Mozilla/5.0 (iPad; CPU OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36', ]; return $userAgents[array_rand($userAgents)]; } /** * Get random IP address */ protected function getRandomIP() { return rand(1, 255) . '.' . rand(1, 255) . '.' . rand(1, 255) . '.' . rand(1, 255); } }