About five minutes, on the free plan, without a credit card.
1
Install the crate
The package on crates.io is openpanel_rust. Pin the minor version: the snippets below are written against the 0.4 API. anyhow is only a dev-dependency of the crate, so add it yourself if you want the error handling used in these examples, along with a Tokio runtime for the #[tokio::main] macro.
cargo add openpanel_rust@0.4
cargo add tokio --features full
cargo add anyhow
2
Point it at Privytics
Set these three variables in the environment your service starts with. The repository ships a .env_sample for reference. OPENPANEL_TRACK_URL must point at the Privytics ingestion endpoint, and the client id and secret come from your Privytics project settings.
# .env
OPENPANEL_TRACK_URL=https://api.privytics.com/track
OPENPANEL_CLIENT_ID=YOUR_CLIENT_ID
OPENPANEL_CLIENT_SECRET=YOUR_CLIENT_SECRET
3
Build a tracker and send an event
The crate is named openpanel_rust but its library target is openpanel_sdk, so that is what you import. In 0.4 the arguments to track() are the event name, an optional profile id, optional properties, optional groups, and an optional filter closure.
use openpanel_sdk::sdk::Tracker;
use std::collections::HashMap;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let tracker = Tracker::try_new_from_env()?.with_default_headers()?;
let mut properties = HashMap::new();
properties.insert("plan".to_string(), "pro".to_string());
tracker
.track(
"signup_completed".to_string(),
Some("user_123".to_string()),
Some(properties),
None,
None,
)
.await?;
Ok(())
}
4
Record revenue from the server
Revenue belongs on the backend, next to the webhook or the transaction that confirmed it, rather than on a checkout page that may never finish loading. revenue() takes an optional profile id, the amount as an i64, and optional properties.
tracker
.revenue(Some("user_123".to_string()), 4900, None)
.await?;