( ′∀`)σ≡σ☆))Д′)レ(゚∀゚;)ヘ=З=З=Зε≡(ノ´_ゝ`)ノ
<?php
// tools/track_usage_ajax.php
// Public AJAX endpoint for tracking tool usage events from the client side
header('Content-Type: application/json');
// Include analytics helper (which includes db_connect.php)
require_once __DIR__ . '/includes/analytics_helper.php';
// Get JSON input
$input = json_decode(file_get_contents('php://input'), true);
if (!$input) {
echo json_encode(['status' => 'error', 'message' => 'Invalid JSON input']);
exit;
}
$tool = isset($input['tool']) ? $input['tool'] : null;
$category = isset($input['category']) ? $input['category'] : 'unknown';
$action = isset($input['action']) ? $input['action'] : 'view';
$metadata = isset($input['metadata']) ? $input['metadata'] : [];
if (!$tool) {
echo json_encode(['status' => 'error', 'message' => 'Tool identifier is required']);
exit;
}
// Track usage
$success = track_tool_usage($tool, $category, $action, $metadata);
if ($success) {
echo json_encode(['status' => 'success']);
} else {
echo json_encode(['status' => 'error', 'message' => 'Database tracking failed']);
}
?>