Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Tauri Plugin Mixpanel
This plugin provides a Rust wrapper and TypeScript bindings for using Mixpanel analytics within your Tauri application. It leverages the mixpanel-rs
crate for the core Mixpanel interactions.
Features
- Track events with custom properties.
- Identify users with unique IDs.
- Manage user profiles.
- Persistent super properties.
- Offline persistence and automatic batching of events.
Install
Rust
Add the plugin to your Cargo.toml
dependencies:
[]
= { = "https://github.com/ahonn/mixpanel-rs", = "main" }
# Or from crates.io:
# tauri-plugin-mixpanel = "<version>"
Register the plugin in your main.rs
:
use ;
JavaScript/TypeScript
Install the frontend bindings using your preferred package manager:
# or
# or
Usage (TypeScript)
Import the bindings and use them in your frontend code :
import mixpanel from 'tauri-plugin-mixpanel-api';
async function setupAnalytics() {
await mixpanel.identify("user_12345");
await mixpanel.people.set({ "$name": "Alice", "plan": "Premium" });
await mixpanel.register({ "App Version": "1.2.0" });
await mixpanel.track("App Started", { "source": "Frontend" });
console.log("Mixpanel initialized and event tracked.");
}
setupAnalytics();
Usage (Rust)
You can interact with the Mixpanel instance directly from your Rust backend code using Tauri's state management and the MixpanelExt
trait.
First, ensure the plugin is registered as shown in the installation steps.
Accessing Mixpanel State
You can get the managed Mixpanel
state in several ways:
- In Tauri Commands: Use
tauri::State<'_, MixpanelState>
. - Usage Outside Commands Use
app.state::<MixpanelState>()
or theapp.handle().mixpanel()
extension method.
Example: Tracking from a Command
use State;
use ;
use json;
async
Example: Usage Outside Commands
To use the Mixpanel client from Rust code outside of a Tauri command (like in the setup
hook, event listeners, or background tasks), you need access to the Tauri AppHandle
. You can then use the MixpanelExt
trait to get the client.
This often involves cloning the AppHandle
and moving it into an async task.
use ;
use ;
use json;
Permissions
This plugin currently does not require any specific capabilities to be enabled in your tauri.conf.json
allowlist, as it interacts with the network via the Rust core, not directly from the webview.
Contributing
Contributions are welcome! Please open an issue or submit a pull request.
License
This project is licensed under the MIT License.