{"id":13800754,"url":"https://github.com/aptabase/tauri-plugin-aptabase","last_synced_at":"2025-05-02T07:31:55.992Z","repository":{"id":147015193,"uuid":"617996289","full_name":"aptabase/tauri-plugin-aptabase","owner":"aptabase","description":"Tauri Plugin for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps","archived":false,"fork":false,"pushed_at":"2024-04-29T03:59:33.000Z","size":649,"stargazers_count":35,"open_issues_count":1,"forks_count":4,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-10-29T22:56:39.636Z","etag":null,"topics":["analytics","aptabase","privacy","tauri"],"latest_commit_sha":null,"homepage":"https://aptabase.com","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aptabase.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-23T14:41:14.000Z","updated_at":"2024-10-07T17:56:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"14f76add-2ff5-4232-a616-230f376f78c5","html_url":"https://github.com/aptabase/tauri-plugin-aptabase","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aptabase%2Ftauri-plugin-aptabase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aptabase%2Ftauri-plugin-aptabase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aptabase%2Ftauri-plugin-aptabase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aptabase%2Ftauri-plugin-aptabase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aptabase","download_url":"https://codeload.github.com/aptabase/tauri-plugin-aptabase/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224305839,"owners_count":17289446,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["analytics","aptabase","privacy","tauri"],"created_at":"2024-08-04T00:01:15.971Z","updated_at":"2025-05-02T07:31:55.987Z","avatar_url":"https://github.com/aptabase.png","language":"Rust","funding_links":[],"categories":["Development"],"sub_categories":["Plugins"],"readme":"![Aptabase](https://aptabase.com/og.png)\n\n# Tauri Plugin for Aptabase\n\nThis plugin allows you to instrument your app with events that can be analyzed in Aptabase, an Open Source, Privacy-First, and Simple Analytics for Mobile, Desktop, and Web Apps.\n\n## Install\n\nInstall the Core plugin by adding the following to your `Cargo.toml` file:\n\n`src-tauri/Cargo.toml`\n\n```toml\n[dependencies]\ntauri-plugin-aptabase = \"1.0.0\"\n```\n\n```toml\n[dependencies]\ntauri-plugin-aptabase = { git = \"https://github.com/aptabase/tauri-plugin-aptabase\" }\n```\n\nYou can install the JavaScript Guest bindings using your preferred JavaScript package manager\n\n```bash\nnpm add @aptabase/tauri\n```\n\n```bash\nnpm add https://github.com/aptabase/tauri-plugin-aptabase\n```\n\n## Usage\n\nFirst, you need to get your `App Key` from Aptabase, you can find it in the `Instructions` menu on the left side menu.\n\nThen register the plugin with Tauri:\n\n`src-tauri/src/main.rs`\n\n```rust\n#[tokio::main]\nasync fn main() {\n    tauri::Builder::default()\n        .plugin(tauri_plugin_aptabase::Builder::new(\"\u003cYOUR_APP_KEY\u003e\").build()) // 👈 this is where you enter your App Key\n        .run(tauri::generate_context!())\n        .expect(\"error while running tauri application\");\n}\n```\n\nAnd finally add `aptabase:allow-track-event` to your list Access Control List.\n\nYou can then start sending events from Rust by importing the `tauri_plugin_aptabase::EventTracker` trait and calling the `track_event` method on `App`, `AppHandle` or `Window`. \n\nAs an example, you can add `app_started` and `app_exited` events like this:\n\n```rust\nuse tauri_plugin_aptabase::EventTracker;\n\n#[tokio::main]\nasync fn main() {\n    tauri::Builder::default()\n        .plugin(tauri_plugin_aptabase::init(\"\u003cYOUR_APP_KEY\u003e\".into()))\n        .setup(|app| {\n            app.track_event(\"app_started\", None);\n            Ok(())\n        })\n        .build(tauri::generate_context!())\n        .expect(\"error while running tauri application\")\n        .run(|handler, event| match event {\n            tauri::RunEvent::Exit { .. } =\u003e {\n                handler.track_event(\"app_exited\", None);\n                handler.flush_events_blocking();\n            }\n            _ =\u003e {}\n        })\n}\n```\n\nThe `trackEvent` function is also available through the JavaScript guest bindings:\n\n```js\nimport { trackEvent } from \"@aptabase/tauri\";\n\ntrackEvent(\"save_settings\") // An event with no properties\ntrackEvent(\"screen_view\", { name: \"Settings\" }) // An event with a custom property\n```\n\nA few important notes:\n\n1. The plugin will automatically enhance the event with some useful information, like the OS, the app version, and other things.\n2. You're in control of what gets sent to Aptabase. This plugin does not automatically track any events, you need to call `trackEvent` manually.\n    - Because of this, it's generally recommended to at least track an event at startup\n3. You do not need to await for the `trackEvent` function, it'll run in the background.\n3. Only strings and numbers values are allowed on custom properties\n\n## Providing the APTABASE_KEY via .env\n\nIt's possible to load the APTABASE_KEY from a .env file at compile time using the `dotenvy_macro` crate. The `.env` file needs to be\nin the `src-tauri` directory for the `dotevny_macro` crate to find it properly.\n\nAdd the `use` declaration to where you are building the tauri app (likely `lib.rs` for Tauri v2), and then call it where you would put the key.\n\n```rust\nuse tauri_plugin_aptabase::EventTracker;\nuse dotenvy_macro::dotenv;\n\n#[cfg_attr(mobile, tauri::mobile_entry_point)]\n/// This function sets up and runs a Rust application using the Tauri framework, with various plugins\n/// and event handlers.\npub fn run() {\n    tauri::Builder::default()\n        .build(tauri::generate_context!())\n        .plugin(tauri_plugin_aptabase::Builder::new(dotenv!(\"APTABASE_KEY\")).build())\n        .expect(\"Error when building tauri app\")\n        .run(|handler, event| match event {\n            tauri::RunEvent::Exit { .. } =\u003e {\n                handler.track_event(\"app_exited\", None);\n                handler.flush_events_blocking();\n            }\n            tauri::RunEvent::Ready { .. } =\u003e {\n                handler.track_event(\"app_started\", None);\n            }\n            _ =\u003e {}\n        });\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faptabase%2Ftauri-plugin-aptabase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faptabase%2Ftauri-plugin-aptabase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faptabase%2Ftauri-plugin-aptabase/lists"}