<?php
require_once __DIR__.'/../includes/functions.php';
header('Content-Type: application/json');

try {
    $companyId = (int)($_POST['company_id'] ?? 0);
    $type = preg_replace('/[^a-zA-Z0-9_]/','',(string)($_POST['event_type'] ?? 'company_click'));
    $value = substr((string)($_POST['event_value'] ?? ''), 0, 190);
    if ($companyId <= 0) { throw new Exception('Missing company id'); }
    mj_company_event_track($companyId, $type, $value);
    echo json_encode(['ok'=>true]);
} catch (Throwable $e) {
    echo json_encode(['ok'=>false,'error'=>$e->getMessage()]);
}
