Tracking Events


Overview

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
    • the name of the event you want to track (e.g. "invoice" or "user-login-event")
  • value (optional)
    • numeric
    • the value of the event if applicable - for example:
      1. the invoice amount 105 representing $105
      2. the latency of a request 245 representing 245ms
  • uid (optional)
    • string
    • a unique identifier for the event should you wish to filter events
      1. For example the user_id for user-login-event events

Response

When successful the api will return a http status of 200

Any other status will include an error message as text

missing api_token field

Laravel Example

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;
  }
}

Usage

use BlueRadar;

class StoreController extends Controller
{
  public function store(StoreItem $item, Request $request)
  {
    // ...

    BlueRadar::put("store-purchase", $item->price, $request->user()->id);

    // ...
  }
}

CURL Example

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"

JS Example

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",
  }),
});

Python Example

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 Example

<?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);