<?php
/**
 * Script pour créer les tables analytics
 */

require_once 'config/db.php';

try {
    // Create analytics_visits table
    executeQuery("
        CREATE TABLE IF NOT EXISTS analytics_visits (
            id INT AUTO_INCREMENT PRIMARY KEY,
            page_url VARCHAR(500) NOT NULL,
            page_title VARCHAR(255),
            referrer VARCHAR(500),
            screen_resolution VARCHAR(20),
            language VARCHAR(10),
            user_agent TEXT,
            ip_address VARCHAR(45),
            session_id VARCHAR(255),
            timestamp DATETIME NOT NULL,
            created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ");

    // Create analytics_events table
    executeQuery("
        CREATE TABLE IF NOT EXISTS analytics_events (
            id INT AUTO_INCREMENT PRIMARY KEY,
            event_type VARCHAR(50) NOT NULL,
            event_category VARCHAR(100),
            event_action VARCHAR(100),
            event_label VARCHAR(255),
            event_value INT DEFAULT 0,
            page_url VARCHAR(500),
            page_title VARCHAR(255),
            referrer VARCHAR(500),
            screen_resolution VARCHAR(20),
            language VARCHAR(10),
            user_agent TEXT,
            ip_address VARCHAR(45),
            session_id VARCHAR(255),
            timestamp DATETIME NOT NULL,
            created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ");

    // Create analytics_performance table
    executeQuery("
        CREATE TABLE IF NOT EXISTS analytics_performance (
            id INT AUTO_INCREMENT PRIMARY KEY,
            page_url VARCHAR(500) NOT NULL,
            load_time INT,
            dom_ready_time INT,
            page_size INT,
            navigation_type VARCHAR(50),
            timestamp DATETIME NOT NULL,
            created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ");

    echo "Tables analytics créées avec succès!";

} catch (Exception $e) {
    echo "Erreur: " . $e->getMessage();
}
?>