mixpanel-rs
An unofficial Rust crate for interacting with the Mixpanel API, inspired by the official Node.js library.
Features
- Track events (
track
,track_batch
) - Manage user profiles (People API:
set
,set_once
,increment
,append
,union
,remove
,unset
,delete_user
) - Manage group profiles (Groups API:
set
,set_once
,remove
,union
,delete_group
) - Configurable API endpoint and behavior (debug, test mode)
Installation
Add mixpanel-rs
to your Cargo.toml
dependencies:
[]
= "<latest-version>" # Replace with the actual latest version
= { = "1", = ["full"] }
= "1.0"
# Optional: for loading env vars from .env
= "0.15"
Usage
Initialization
First, get your Project Token and optionally your API Secret from your Mixpanel project settings.
use ;
use env;
use dotenv;
// Load .env file if present
dotenv.ok;
let project_token = var
.expect;
// API Secret is needed for import endpoints
let api_secret = var.ok;
// Optional configuration
let config = Config ;
let mp = init;
Tracking Events
use ;
use json;
use HashMap;
# let project_token = "token";
# let mp = init;
async
People API
use ;
use json;
use HashMap;
# let project_token = "token";
# let mp = init;
async
Error Handling
The API methods return mixpanel_rs::Result<T>
, which is an alias for std::result::Result<T, mixpanel_rs::Error>
. Handle potential errors like network issues or API errors.
# use ;
# let project_token = "token";
# let mp = init;
async
Tauri Integration
Need to use Mixpanel in your Tauri application? Check out the dedicated tauri-plugin-mixpanel
package within this repository. It provides seamless integration between mixpanel-rs
and your Tauri frontend and backend.
Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
License
This project is licensed under the MIT License.