Skip to content

Rust SDK - Configuration

use funnelmob::{FunnelMob, Configuration, Environment};
let config = Configuration::builder("com.example.myapp", "fm_live_abc123")
.environment(Environment::Production)
.build()
.unwrap();
let sdk = FunnelMob::new(config).unwrap();
use funnelmob::{Configuration, Environment, LogLevel};
let config = Configuration::builder("com.example.myapp", "your_api_key")
.environment(Environment::Production) // or Environment::Sandbox
.log_level(LogLevel::Debug) // None, Error, Warning, Info, Debug, Verbose
.flush_interval_ms(30000) // Auto-flush interval (min: 1000ms)
.max_batch_size(100) // Events per batch (1-100)
.build()
.unwrap();

For convenience, use the singleton pattern:

use funnelmob::{FunnelMob, Configuration};
// Initialize once at startup
let config = Configuration::builder("com.example.app", "api_key")
.build()
.unwrap();
FunnelMob::initialize(config).unwrap();
// Access anywhere
if let Some(sdk) = FunnelMob::shared() {
sdk.track_event("page_view").unwrap();
}
// Check if enabled
if sdk.is_enabled() {
println!("SDK is tracking events");
}
// Disable tracking (e.g., for GDPR compliance)
sdk.set_enabled(false);
// Re-enable
sdk.set_enabled(true);
// Get identifiers
println!("Session ID: {}", sdk.session_id());
println!("Device ID: {}", sdk.device_id());
// Manual flush
sdk.flush().unwrap();
// Shutdown
sdk.destroy();

Enable the async feature for async/await compatibility:

use funnelmob::{FunnelMob, Configuration};
#[tokio::main]
async fn main() {
let config = Configuration::builder("com.example.app", "api_key")
.build()
.unwrap();
let sdk = FunnelMob::new(config).unwrap();
sdk.track_event_async("app_start").await.unwrap();
sdk.flush_async().await.unwrap();
sdk.destroy_async().await;
}
use funnelmob::{FunnelMobError, ValidationError};
match sdk.track_event("") {
Ok(()) => println!("Event tracked"),
Err(FunnelMobError::Validation(ValidationError::EventNameRequired)) => {
println!("Event name is required");
}
Err(e) => println!("Error: {}", e),
}