<?php
header('Access-Control-Allow-Origin: *');

// Database connection (MySQL)
$host = "localhost";
$dbname = "uklb_tracking";
$username = "lbnwco_private";
$password = "s4^63b0Nd";

try {
    $pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    die("Database connection failed: " . $e->getMessage());
}

// Get visitor data (no cookies, no IP tracking)
$page_url = $_POST['page_url'] ?? '';
$referrer = $_POST['referrer'] ?? '';
$user_agent = $_SERVER['HTTP_USER_AGENT'] ?? '';

// Basic country detection (without IP logging)
$country = $_POST['country'] ?? 'Unknown';
$fingerprint = $_POST['fingerprint'] ?? '';
// Store in database
$stmt = $pdo->prepare("INSERT INTO analytics (page_url, referrer, country, user_agent, fingerprint) VALUES (?, ?, ?, ?, ?)");
$stmt->execute([$page_url, $referrer, $country, $user_agent, $fingerprint]);

echo json_encode(["status" => "success"]);
?>
