npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

tauri-plugin-mixpanel-api

v0.1.0

Published

Tauri plugin API for Mixpanel analytics

Readme

Tauri Plugin Mixpanel

crates.io documentation

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 (People operations: set, set_once, increment, append, etc.).
  • Manage user groups.
  • Time events.
  • Persistent super properties.
  • Offline persistence and automatic batching of events.

Install

Rust

Add the plugin to your Cargo.toml dependencies:

[dependencies]
tauri-plugin-mixpanel = { git = "https://github.com/ahonn/mixpanel-rs", branch = "main" }
# Or from crates.io:
# tauri-plugin-mixpanel = "<version>"

Register the plugin in your main.rs:

use tauri_plugin_mixpanel::{self, Config};

fn main() {
    let mixpanel_token = "YOUR_MIXPANEL_TOKEN"; // Replace with your actual token
    let mixpanel_config = Some(Config {
        // Optional: Configure batch size, flush interval, etc.
        // See mixpanel-rs docs for details: https://docs.rs/mixpanel-rs
        ..Default::default()
    });

    tauri::Builder::default()
        .plugin(tauri_plugin_mixpanel::Builder::new(mixpanel_token, mixpanel_config).build())
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

JavaScript/TypeScript

Install the frontend bindings using your preferred package manager:

npm install @tauri-apps/api tauri-plugin-mixpanel-api
# or
yarn add @tauri-apps/api tauri-plugin-mixpanel-api
# or
pnpm add @tauri-apps/api tauri-plugin-mixpanel-api

Usage (TypeScript)

import { mixpanel, MixpanelError } from 'tauri-plugin-mixpanel-api';

async function setupMixpanel() {
  try {
    // Identify the user
    await mixpanel.identify('user-123');

    // Set some user profile properties (Mixpanel People)
    await mixpanel.people.set({
      $email: '[email protected]',
      plan: 'Premium',
    });

    // Register super properties (sent with every event)
    await mixpanel.register({
      appName: 'My Tauri App',
      appVersion: '1.0.0',
    });

    // Track an event
    await mixpanel.track('App Launched', { source: 'desktop' });

    // Time an event
    mixpanel.time_event('Data Processing');
    // ... perform data processing ...
    await mixpanel.track('Data Processing'); // This will include the duration

    // Set user groups
    await mixpanel.set_group('company', 'company-abc');
    await mixpanel.add_group('project', 'project-xyz');

  } catch (error) {
    if (error instanceof MixpanelError) {
      console.error('Mixpanel Error:', error.message);
    } else {
      console.error('Unknown Error:', error);
    }
  }
}

setupMixpanel();

// --- Example: Tracking a button click ---
const myButton = document.getElementById('my-button');
myButton?.addEventListener('click', async () => {
  try {
    await mixpanel.track('Button Clicked', { buttonId: 'my-button' });
    console.log('Button click tracked');
  } catch (error) {
     if (error instanceof MixpanelError) {
      console.error('Mixpanel Error:', error.message);
    } else {
      console.error('Unknown Error:', error);
    }
  }
});

// --- Example: Get Distinct ID ---
async function logDistinctId() {
    const distinctId = await mixpanel.get_distinct_id();
    console.log('Current Mixpanel Distinct ID:', distinctId);
}

logDistinctId();

// --- Resetting (e.g., on logout) ---
async function logoutUser() {
    // Perform logout actions...

    // Reset Mixpanel (clears distinct ID and super properties)
    await mixpanel.reset();
    console.log('Mixpanel reset.');
}

API

The TypeScript API mirrors the standard Mixpanel JavaScript library methods closely. Refer to the guest-js/index.ts file and the official Mixpanel JavaScript Library Reference for detailed method descriptions.

Key methods include:

  • mixpanel.identify(distinctId)
  • mixpanel.track(eventName, properties?)
  • mixpanel.register(properties)
  • mixpanel.register_once(properties, defaultValue?)
  • mixpanel.unregister(propertyName)
  • mixpanel.get_distinct_id()
  • mixpanel.get_property(propertyName)
  • mixpanel.reset()
  • mixpanel.time_event(eventName)
  • mixpanel.set_group(groupKey, groupId)
  • mixpanel.add_group(groupKey, groupId)
  • mixpanel.remove_group(groupKey, groupId)
  • mixpanel.people.set(properties)
  • mixpanel.people.set_once(properties)
  • mixpanel.people.unset(properties)
  • mixpanel.people.increment(properties, amount?)
  • mixpanel.people.append(listName, value)
  • mixpanel.people.remove(listName, value)
  • mixpanel.people.union(listName, values)
  • mixpanel.people.delete_user()

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.