diff --git a/.gitignore b/.gitignore index 4f9a09c..9863270 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ package-lock.json .vscode/settings.json yarn.lock +/.tauri /target Cargo.lock node_modules/ -webview-dist \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 5519f02..0ff3b31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,4 +41,4 @@ ## 0.2.0 * BREAKING CHANGE: replaced the `init` function with a `Builder` struct, see README for example usage -* Ability to set custom hosts for self hosted servers \ No newline at end of file +* Ability to set custom hosts for self hosted servers diff --git a/Cargo.toml b/Cargo.toml index 4178f4b..a207e16 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,23 +3,26 @@ name = "tauri-plugin-aptabase" version = "0.5.1" license = "MIT" description = "Tauri Plugin for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps" -authors = [ "Guilherme Oenning" ] +authors = ["Guilherme Oenning"] edition = "2021" -rust-version = "1.59" +rust-version = "1.70" readme = "README.md" repository = "https://github.com/aptabase/tauri-plugin-aptabase" -exclude = ["/examples", "/webview-dist", "/webview-src", "node_modules"] +exclude = ["/examples", "/webview-dist", "/webview-src", "/node_modules"] +links = "tauri-plugin-aptabase" [dependencies] -tauri = { version = "1", features = ["os-api"] } -tokio = "1" -futures = "0" -serde = "1.0" -serde_json = "1.0" -thiserror = "1.0" -reqwest = { version = "0.11", features = ["json"] } -time = { version = "0.3", features = ["formatting"]} -os_info = "3" -uuid = "1" -rand = "0.8" -log = "0.4" +tauri = "2.2.5" +tokio = "1.43.0" +futures = "0.3.31" +serde = "1.0.217" +serde_json = "1.0.138" +reqwest = { version = "0.12.12", features = ["json"] } +time = { version = "0.3.37", features = ["formatting"] } +os_info = "3.9.2" +rand = "0.9.0" +log = "0.4.25" +sys-locale = "0.3.2" + +[build-dependencies] +tauri-plugin = { version = "2.0.4", features = ["build"] } diff --git a/README.md b/README.md index d2d79a7..d0d96ac 100644 --- a/README.md +++ b/README.md @@ -12,22 +12,20 @@ Install the Core plugin by adding the following to your `Cargo.toml` file: ```toml [dependencies] -tauri-plugin-aptabase = "0.4" +tauri-plugin-aptabase = { git = "https://github.com/aptabase/tauri-plugin-aptabase", branch = "v2" } ``` You can install the JavaScript Guest bindings using your preferred JavaScript package manager ```bash -npm add @aptabase/tauri +npm add https://github.com/aptabase/tauri-plugin-aptabase#v2 ``` -> This plugin is only compatible with Tauri v1. To use it on a Tauri v2 app, [follow the instructions on our v2 branch](https://github.com/aptabase/tauri-plugin-aptabase/blob/v2). - ## Usage First, you need to get your `App Key` from Aptabase, you can find it in the `Instructions` menu on the left side menu. -Then you need to register the core plugin with Tauri: +Then register the plugin with Tauri: `src-tauri/src/main.rs` @@ -40,11 +38,12 @@ fn main() { } ``` +And finally add `aptabase:allow-track-event` to your list Access Control List. + You 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`. As an example, you can add `app_started` and `app_exited` events like this: - ```rust use tauri_plugin_aptabase::EventTracker; @@ -83,3 +82,35 @@ A few important notes: - Because of this, it's generally recommended to at least track an event at startup 3. You do not need to await for the `trackEvent` function, it'll run in the background. 3. Only strings and numbers values are allowed on custom properties + +## Providing the APTABASE_KEY via .env + +It'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 +in the `src-tauri` directory for the `dotevny_macro` crate to find it properly. + +Add 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. + +```rust +use tauri_plugin_aptabase::EventTracker; +use dotenvy_macro::dotenv; + +#[cfg_attr(mobile, tauri::mobile_entry_point)] +/// This function sets up and runs a Rust application using the Tauri framework, with various plugins +/// and event handlers. +pub fn run() { + tauri::Builder::default() + .build(tauri::generate_context!()) + .plugin(tauri_plugin_aptabase::Builder::new(dotenv!("APTABASE_KEY")).build()) + .expect("Error when building tauri app") + .run(|handler, event| match event { + tauri::RunEvent::Exit { .. } => { + handler.track_event("app_exited", None); + handler.flush_events_blocking(); + } + tauri::RunEvent::Ready { .. } => { + handler.track_event("app_started", None); + } + _ => {} + }); +} +``` diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..b6b7b1a --- /dev/null +++ b/build.rs @@ -0,0 +1,5 @@ +const COMMANDS: &[&str] = &["track_event"]; + +fn main() { + tauri_plugin::Builder::new(COMMANDS).build(); +} diff --git a/examples/helloworld/README.md b/examples/helloworld/README.md deleted file mode 100644 index 102e366..0000000 --- a/examples/helloworld/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Tauri + React + Typescript - -This template should help get you started developing with Tauri, React and Typescript in Vite. - -## Recommended IDE Setup - -- [VS Code](https://code.visualstudio.com/) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer) diff --git a/examples/helloworld/index.html b/examples/helloworld/index.html index 194012b..fad1c5d 100644 --- a/examples/helloworld/index.html +++ b/examples/helloworld/index.html @@ -4,11 +4,11 @@ -