Last active
March 12, 2025 19:55
-
-
Save shash7/38e6299075b0d601032317b08460cf01 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function ops($event_name, $data) { | |
$url = "https://api.operational.co/api/v1/ingest"; | |
$token = "YOUR_API_KEY"; // get a free one from operational.co | |
$args = array( | |
'body' => json_encode(array_merge(['name' => $event_name, 'notify' => true], $data)), | |
'headers' => array( | |
'Authorization' => 'Bearer ' . $token, | |
'Content-Type' => 'application/json' | |
), | |
'method' => 'POST', | |
); | |
$response = wp_remote_post($url, $args); | |
if (is_wp_error($response)) { | |
$error_message = "Error sending event: " . $response->get_error_message(); | |
error_log($error_message); | |
} else { | |
$response_body = wp_remote_retrieve_body($response); | |
error_log("Event sent successfully: " . print_r($response_body, true)); | |
} | |
} | |
/* | |
* How to use | |
*/ | |
/* | |
$data = [ | |
'avatar' => '✏️', // optional, set a emoji, | |
'content' => 'hello!' // optional, can be any string | |
]; | |
ops('profile_update', $data); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment