pub struct TelemetryDeck {
pub app_id: String,
pub namespace: Option<String>,
pub salt: Option<String>,
pub default_params: HashMap<String, String>,
pub session_id: String,
/* private fields */
}Expand description
TelemetryDeck API client
This is the main entry point for sending telemetry signals to TelemetryDeck. The client handles session management, user identifier hashing, and HTTP communication.
§Examples
§Basic Usage
use telemetrydeck_wasm::TelemetryDeck;
let client = TelemetryDeck::new("YOUR-APP-ID");
client.send("userLogin", Some("user@example.com"), None, None, None);§With Configuration
use telemetrydeck_wasm::TelemetryDeck;
use std::collections::HashMap;
let client = TelemetryDeck::new_with_config(
"YOUR-APP-ID",
Some("my-tenant".to_string()), // namespace
Some("random-salt-64-chars".to_string()), // salt
HashMap::new(), // default params
);§Platform Support
- Native: Uses
reqwest+tokio::spawn - WASM: Uses
reqwasm+spawn_local
§Privacy
- User identifiers are always SHA-256 hashed
- Optional salt is concatenated after user ID before hashing
- Session IDs are random UUIDs
Fields§
§app_id: StringYour TelemetryDeck App ID
namespace: Option<String>Optional namespace for multi-tenant deployments
When set, signals are sent to /v2/namespace/{namespace}/
instead of /v2/.
salt: Option<String>Optional salt for user identifier hashing
The salt is concatenated after the user identifier before
SHA-256 hashing: hash(user_id + salt).
§Security Note
It is recommended to use a cryptographically random salt of at least 64 characters. The salt should be unique per application but consistent across all users of the same application.
default_params: HashMap<String, String>Default parameters appended to all outgoing signals
These are merged with per-signal parameters.
The library version is automatically added as telemetryClientVersion.
session_id: StringCurrent session identifier (UUID v4)
Generated automatically when the client is created.
Can be reset using TelemetryDeck::reset_session.
Implementations§
Source§impl TelemetryDeck
impl TelemetryDeck
Sourcepub fn new_with_config(
app_id: &str,
namespace: Option<String>,
salt: Option<String>,
params: HashMap<String, String>,
) -> Self
pub fn new_with_config( app_id: &str, namespace: Option<String>, salt: Option<String>, params: HashMap<String, String>, ) -> Self
Create a new instance with the specified application id and configuration
§Examples
use telemetrydeck_wasm::TelemetryDeck;
use std::collections::HashMap;
// Create client with namespace for multi-tenant deployment
let client = TelemetryDeck::new_with_config(
"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
Some("my-namespace".to_string()),
None,
HashMap::new(),
);
// Create client with salt for enhanced user hashing
let client = TelemetryDeck::new_with_config(
"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
None,
Some("your-64-char-random-salt-here".to_string()),
HashMap::new(),
);
// Create client with default parameters
let mut defaults = HashMap::new();
defaults.insert("environment".to_string(), "production".to_string());
let client = TelemetryDeck::new_with_config(
"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
None,
None,
defaults,
);Sourcepub fn reset_session(&mut self, new_session_id: Option<String>)
pub fn reset_session(&mut self, new_session_id: Option<String>)
Reset the session id for future signals
Source§impl TelemetryDeck
impl TelemetryDeck
Sourcepub fn send(
&self,
signal_type: &str,
client_user: Option<&str>,
payload: Option<HashMap<String, String>>,
is_test_mode: Option<bool>,
float_value: Option<f64>,
)
pub fn send( &self, signal_type: &str, client_user: Option<&str>, payload: Option<HashMap<String, String>>, is_test_mode: Option<bool>, float_value: Option<f64>, )
Send a telemetry signal (fire-and-forget)
This method spawns an async task using tokio::spawn and never returns errors.
The signal is sent in the background without blocking. Use send_sync
if you need error handling.
§Parameters
signal_type- The type/name of the signal (e.g., “userLogin”, “buttonClick”)client_user- Optional user identifier. Will be SHA-256 hashed automatically. IfNone, defaults to “rust”.payload- Optional key-value parameters to attach to the signalis_test_mode- Whether to mark this as a test signal. Defaults tofalseifNone.float_value- Optional floating-point value (useful for metrics like revenue, duration, etc.)
§Examples
use telemetrydeck_wasm::TelemetryDeck;
let client = TelemetryDeck::new("YOUR-APP-ID");
// Simple signal
client.send("buttonClick", None, None, None, None);
// With user
client.send("userLogin", Some("user@example.com"), None, None, None);
// With float value for revenue tracking
client.send("purchase", Some("user123"), None, None, Some(49.99));use telemetrydeck_wasm::TelemetryDeck;
use std::collections::HashMap;
let client = TelemetryDeck::new("YOUR-APP-ID");
let mut params = HashMap::new();
params.insert("screen".to_string(), "settings".to_string());
params.insert("action".to_string(), "toggle".to_string());
client.send("userAction", Some("user"), Some(params), None, None);§Platform Note
On native platforms, this requires a tokio runtime to be running.
Sourcepub async fn send_sync(
&self,
signal_type: &str,
client_user: Option<&str>,
payload: Option<HashMap<String, String>>,
is_test_mode: Option<bool>,
float_value: Option<f64>,
) -> Result<(), Box<dyn Error>>
pub async fn send_sync( &self, signal_type: &str, client_user: Option<&str>, payload: Option<HashMap<String, String>>, is_test_mode: Option<bool>, float_value: Option<f64>, ) -> Result<(), Box<dyn Error>>
Send a telemetry signal and return errors if any occur
This method waits for the HTTP request to complete and returns a Result.
Use this when you need to know if the signal was sent successfully.
§Parameters
signal_type- The type/name of the signal (e.g., “userLogin”, “buttonClick”)client_user- Optional user identifier. Will be SHA-256 hashed automatically. IfNone, defaults to “rust”.payload- Optional key-value parameters to attach to the signalis_test_mode- Whether to mark this as a test signal. Defaults tofalseifNone.float_value- Optional floating-point value (useful for metrics like revenue, duration, etc.)
§Returns
Ok(())if the signal was sent successfully (HTTP 2xx status)Err(...)if sending failed (network error, HTTP error, serialization error, etc.)
§Examples
use telemetrydeck_wasm::TelemetryDeck;
let client = TelemetryDeck::new("YOUR-APP-ID");
// Handle errors explicitly
match client.send_sync("criticalEvent", Some("user"), None, None, None).await {
Ok(()) => println!("Signal sent successfully"),
Err(e) => eprintln!("Failed to send: {}", e),
}
// Or use ? operator
client.send_sync("anotherEvent", None, None, None, None).await?;