GA4 custom event from server side, can someone tell me how i can do the following code in php?



PHP Snippet 1:

$ip = str_replace('.', '', $_SERVER['REMOTE_ADDR']);
$data = array(
                'client_id' => $ip,
                'user_id' => '123',
                'events' => array(
                    'name' => 'event_serverside'
                )
            );
$datastring = json_encode($data);
$post_url = 'https://www.google-analytics.com/mp/collect?api_secret=xxxxxxxxxx&measurement_id=xxxxxxxxx';
$ch = curl_init($post_url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $datastring);
curl_setopt($ch, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($ch, CURLOPT_POST, TRUE);
$result = curl_exec($ch);