To track events from anywhere in your stack simply make a HTTP request to the following endpoint
PUT https://api.blueradar.net/event
This endpoint requires the following:
site_id
(required)
string
api_token
(required)
string
event
(required)
string
value
(optional)
numeric
105
representing $105245
representing 245msuid
(optional)
string
user_id
for user-login-event
eventsWhen successful the api will return a http status of 200
Any other status will include an error message as text
missing api_token field
use Carbon\Carbon;
use Illuminate\Support\Facades\Http;
class BlueRadar
{
static function put(string $event, ?float $value = null, ?string $uid = null)
{
$siteId = env("BLUERADAR_SITE_ID");
$apiToken = env("BLUERADAR_SITE_API_TOKEN");
if (!$siteId || !$apiToken) {
return null;
}
$res = Http::put("https://api.blueradar.net/event", [
"site_id" => $siteId,
"api_token" => $apiToken,
"event" => $event,
"value" => $value,
"uid" => $uid,
]);
if (!$res->successful()) {
throw new \Exception(
"Server responded with {$res->status()} for query '{$event}'"
);
}
return true;
}
}
use BlueRadar;
class StoreController extends Controller
{
public function store(StoreItem $item, Request $request)
{
// ...
BlueRadar::put("store-purchase", $item->price, $request->user()->id);
// ...
}
}
curl -X PUT https://api.blueradar.net/event \
-d site_id="YOUR_SITE_ID" \
-d api_token="YOUR_API_TOKEN" \
-d event="YOUR_EVENT_NAME" \
-d value=YOUR_NUMERIC_VALUE \
-d uid="YOUR_UNIQUE_ID"
fetch("https://api.blueradar.net/event", {
method: "PUT",
body: new URLSearchParams({
site_id: "YOUR_SITE_ID",
api_token: "YOUR_API_TOKEN",
event: "YOUR_EVENT_NAME",
value: YOUR_NUMERIC_VALUE,
uid: "YOUR_UNIQUE_ID",
}),
});
import requests
data = {
'site_id': 'YOUR_SITE_ID',
'api_token': 'YOUR_API_TOKEN',
'event': 'YOUR_EVENT_NAME',
'value': YOUR_NUMERIC_VALUE,
'uid': 'YOUR_UNIQUE_ID',
}
response = requests.put('https://api.blueradar.net/event', data=data)
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.blueradar.net/event");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type" => "application/x-www-form-urlencoded",
]);
curl_setopt(
$ch,
CURLOPT_POSTFIELDS,
"site_id=YOUR_SITE_ID&api_token=YOUR_API_TOKEN&event=YOUR_EVENT_NAME&value=YOUR_NUMERIC_VALUE&uid=YOUR_UNIQUE_ID"
);
$response = curl_exec($ch);
curl_close($ch);