tauri-plugin-better-posthog

Crates.iotauri-plugin-better-posthog
lib.rstauri-plugin-better-posthog
version0.1.3
created_at2025-12-20 08:55:47.019563+00
updated_at2026-01-25 09:26:02.943839+00
descriptionTauri integration with PostHog
homepage
repositoryhttps://github.com/niusia-ua/better-posthog-rust
max_upload_size
id1996236
size162,405
Nazar Antoniuk (niusia-ua)

documentation

README

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() {
  // Initialize the client (keep the guard alive for the application lifetime).
  let _guard = better_posthog::init(better_posthog::ClientOptions {
    api_key: Some("phc_your_api_key".into()),
    ..Default::default()
  });

  // Register the plugin.
  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", {
  // other options...

  // Route all events through the Rust backend.
  before_send: [
    // Keep this function last.
    (captureResult) => {
      if (captureResult) {
        const { event, properties } = captureResult;
        captureEvent(event, properties).catch(console.error);
      }
      // Return `null` to prevent `posthog-js` from sending directly.
      return null;
    },
  ],
});

License

MIT

Commit count: 22

cargo fmt