<?php
require_once __DIR__.'/../includes/functions.php';
header('Content-Type: application/json');
try{
  $id=(int)($_POST['listing_id']??0); $type=preg_replace('/[^a-zA-Z0-9_]/','',(string)($_POST['event_type']??'share')); $val=substr((string)($_POST['event_value']??''),0,190);
  if($id<=0) throw new Exception('Missing listing id');
  if($type==='share_click') $type='share';
  mj263_track_event($id,$type,$val);
  echo json_encode(['ok'=>true]);
}catch(Throwable $e){ echo json_encode(['ok'=>false,'error'=>$e->getMessage()]); }
