tauri-plugin-better-posthog
Tauri integration with PostHog.
Installation
npm install posthog-js tauri-plugin-better-posthog
cargo add better-posthog tauri-plugin-better-posthog
Backend Setup
Initialize the PostHog client and register the plugin in your Tauri application:
fn main() {
let _guard = better_posthog::init(better_posthog::ClientConfig {
api_key: Some("phc_your_api_key".to_string()),
..Default::default()
});
tauri::Builder::default()
.plugin(tauri_plugin_better_posthog::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
Frontend Setup
Configure posthog-js to route all events through the Rust backend:
import posthog from "posthog-js";
import { captureEvent } from "tauri-plugin-better-posthog";
posthog.init("dummy_api_key", {
before_send: [
(captureResult) => {
if (captureResult) {
const { event, properties } = captureResult;
captureEvent(event, properties).catch(console.error);
}
return null;
},
],
});
License
MIT