High-performance webhook verification in Rust with Axum. Add visitor identification, bot detection, and smart signals to your Rust application in minutes.
Add the SDK to your project with your preferred package manager.
npm install axumyarn add axumpnpm add axumGet up and running with the minimal setup.
use axum::{body::Bytes, http::HeaderMap, routing::post, Router};async fn webhook(headers: HeaderMap, body: Bytes) -> &'static str { // verify headers["x-tracio-signature"] against body, then act println!("{}", String::from_utf8_lossy(&body)); "OK"}#[tokio::main]async fn main() { let app = Router::new().route("/webhook/tracio", post(webhook)); let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap(); axum::serve(listener, app).await.unwrap();}Production-ready patterns with error handling, loading states, and advanced configuration.
use axum::{body::Bytes, http::{HeaderMap, StatusCode}, routing::post, Router};use hmac::{Hmac, Mac};use sha2::Sha256;use serde::Deserialize;type HmacSha256 = Hmac<Sha256>;#[derive(Deserialize)]struct Bot { result: String,}#[derive(Deserialize)]struct Event { #[serde(rename = "visitorId")] visitor_id: String, bot: Bot,}// Recompute the HMAC-SHA256 over "<t>.<rawBody>" and compare it.fn verify(body: &[u8], header: &str, secret: &[u8]) -> bool { let (mut t, mut v1) = ("", ""); for kv in header.split(',') { match kv.split_once('=') { Some(("t", val)) => t = val, Some(("v1", val)) => v1 = val, _ => {} } } let mut mac = HmacSha256::new_from_slice(secret).unwrap(); mac.update(t.as_bytes()); mac.update(b"."); mac.update(body); match hex::decode(v1) { Ok(sig) => mac.verify_slice(&sig).is_ok(), Err(_) => false, }}async fn webhook(headers: HeaderMap, body: Bytes) -> Result<&'static str, StatusCode> { let secret = std::env::var("TRACIO_WEBHOOK_SECRET").unwrap_or_default(); let sig = headers .get("x-tracio-signature") .and_then(|v| v.to_str().ok()) .unwrap_or(""); if !verify(&body, sig, secret.as_bytes()) { return Err(StatusCode::UNAUTHORIZED); } let event: Event = serde_json::from_slice(&body).map_err(|_| StatusCode::BAD_REQUEST)?; if event.bot.result == "bot" { println!("flagging bot visitor {}", event.visitor_id); } Ok("OK")}#[tokio::main]async fn main() { let app = Router::new().route("/webhook/tracio", post(webhook)); let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap(); axum::serve(listener, app).await.unwrap();}All available options for initializing and configuring the SDK.
publicKeystringYour public key from the dashboard — safe to ship in the browserendpointstringCustom endpoint URL for proxy-routed deployments — an explicit URL wins over regionregionstringData region: us or eutimeoutMsnumberTimeout for the whole getResult() call, in millisecondslinkedIdstringYour internal account ID for the signed-in user, so visits sharing a device can be linkedtagstringFree-form label attached to the identification request, e.g. checkout or logindebugbooleanLogs the script lifecycle and network activity to the browser consolescriptUrlstringFull override for the agent script URL — for self-hosting or Subresource IntegrityGo deeper with the full API reference, webhook configuration, and advanced guides.
Full API reference, integration guides, and best practices.
Real-time event delivery, payload schema, and signature verification.
Configure real-time event notifications for every device identification.
Add device fingerprinting to your Rust application in under 5 minutes.