Skip to content

Rust SDK

AnalyticsManager is a thread-safe singleton struct that sends analytics events to the Vortex platform from any Rust environment.

GitHub: Vortex-Analytics-IO/Rust-SDK

Supported features:

  • Immediate and batched event tracking
  • Automatic retry when the server becomes available
  • Persistent device and session identification
  • Thread-safe queue management

Add the following to your Cargo.toml:

[dependencies]
vortex_analytics = { git = "https://github.com/Vortex-Analytics-IO/Rust-SDK" }

The crate internally depends on:

CratePurpose
reqwestBlocking HTTP client with JSON support
serde / serde_jsonSerialization
uuidDevice and session ID generation
chronoTimestamps

AnalyticsManager is a singleton accessed via AnalyticsManager::instance(). Initialize it once in main() before sending any events.

use vortex_analytics::AnalyticsManager;
fn main() {
AnalyticsManager::instance().init(
"my_app", // tenant_id
"https://in.vortexanalytics.io", // url
"Windows", // platform
"1.0.0", // app_version
true, // auto_batching
10, // flush_interval_sec
);
// ... your application logic ...
AnalyticsManager::instance().shutdown();
}

Enable verbose output to see internal debug information:

AnalyticsManager::instance().set_verbose(true);
  1. Loads or generates a persistent device identifier (stored in a local analytics.id file)
  2. Creates a new session ID
  3. Spawns a background thread to check server health
  4. Enables or disables analytics based on server availability
  5. Automatically tracks an app_started event

If the server is unreachable, events are safely queued until connectivity is restored.


AnalyticsManager::instance().track_event_string("app_started", "");
AnalyticsManager::instance().track_event_string("menu_opened", "settings");
use std::collections::HashMap;
use serde_json::Value;
let mut props = HashMap::new();
props.insert("level".to_string(), Value::from(5));
props.insert("difficulty".to_string(), Value::from("Hard"));
props.insert("time".to_string(), Value::from(123.4));
AnalyticsManager::instance().track_event("level_completed", props);

Use manual batching when you want explicit control over when events are sent (e.g. at the end of a match).

use std::collections::HashMap;
use serde_json::Value;
// Queue events
AnalyticsManager::instance().batched_track_event_string("EnemyKilled", "");
let mut props = HashMap::new();
props.insert("item".to_string(), Value::from("MagicSword"));
props.insert("rarity".to_string(), Value::from("Epic"));
AnalyticsManager::instance().batched_track_event("ItemCrafted", props);
// Send all queued events in a single request (spawns a background thread)
AnalyticsManager::instance().flush_manual_batch();

Enable auto_batching in init():

  • track_event / track_event_string calls are queued automatically
  • The queue flushes every flush_interval_sec seconds
  • If the server is unreachable, events stay queued until connectivity is restored

Attach persistent metadata to every event the manager sends.

use std::collections::HashMap;
use serde_json::Value;
// Set custom data — included in all subsequent events
let mut custom = HashMap::new();
custom.insert("user_id".to_string(), Value::from(123));
custom.insert("tier".to_string(), Value::from("gold"));
AnalyticsManager::instance().set_custom_data(Some(custom));
// Remove custom data
AnalyticsManager::instance().set_custom_data(None);
  • Empty custom data is not included in request payloads
  • The map is automatically serialized to JSON

AnalyticsManager cannot detect application shutdown automatically. You must call shutdown() when your app exits to flush any buffered events.

use vortex_analytics::AnalyticsManager;
fn main() {
AnalyticsManager::instance().init(
"my_app",
"https://in.vortexanalytics.io",
"Windows",
"1.0.0",
false,
10,
);
// ... your application logic ...
AnalyticsManager::instance().shutdown();
}

For signal-based shutdown (e.g. Ctrl+C), use a crate like ctrlc:

ctrlc::set_handler(|| {
AnalyticsManager::instance().shutdown();
std::process::exit(0);
}).expect("Error setting Ctrl-C handler");