Skip to content

Commit 62fa8d5

Browse files
authored
Merge pull request #21 from aptabase/v2
V2
2 parents d852f2b + 8085ab1 commit 62fa8d5

63 files changed

Lines changed: 833 additions & 430 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package-lock.json
88
.vscode/settings.json
99
yarn.lock
1010

11+
/.tauri
1112
/target
1213
Cargo.lock
1314
node_modules/
14-
webview-dist

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@
4141
## 0.2.0
4242

4343
* BREAKING CHANGE: replaced the `init` function with a `Builder` struct, see README for example usage
44-
* Ability to set custom hosts for self hosted servers
44+
* Ability to set custom hosts for self hosted servers

Cargo.toml

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,26 @@ name = "tauri-plugin-aptabase"
33
version = "0.5.1"
44
license = "MIT"
55
description = "Tauri Plugin for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps"
6-
authors = [ "Guilherme Oenning" ]
6+
authors = ["Guilherme Oenning"]
77
edition = "2021"
8-
rust-version = "1.59"
8+
rust-version = "1.70"
99
readme = "README.md"
1010
repository = "https://github.com/aptabase/tauri-plugin-aptabase"
11-
exclude = ["/examples", "/webview-dist", "/webview-src", "node_modules"]
11+
exclude = ["/examples", "/webview-dist", "/webview-src", "/node_modules"]
12+
links = "tauri-plugin-aptabase"
1213

1314
[dependencies]
14-
tauri = { version = "1", features = ["os-api"] }
15-
tokio = "1"
16-
futures = "0"
17-
serde = "1.0"
18-
serde_json = "1.0"
19-
thiserror = "1.0"
20-
reqwest = { version = "0.11", features = ["json"] }
21-
time = { version = "0.3", features = ["formatting"]}
22-
os_info = "3"
23-
uuid = "1"
24-
rand = "0.8"
25-
log = "0.4"
15+
tauri = "2.2.5"
16+
tokio = "1.43.0"
17+
futures = "0.3.31"
18+
serde = "1.0.217"
19+
serde_json = "1.0.138"
20+
reqwest = { version = "0.12.12", features = ["json"] }
21+
time = { version = "0.3.37", features = ["formatting"] }
22+
os_info = "3.9.2"
23+
rand = "0.9.0"
24+
log = "0.4.25"
25+
sys-locale = "0.3.2"
26+
27+
[build-dependencies]
28+
tauri-plugin = { version = "2.0.4", features = ["build"] }

README.md

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,20 @@ Install the Core plugin by adding the following to your `Cargo.toml` file:
1212

1313
```toml
1414
[dependencies]
15-
tauri-plugin-aptabase = "0.4"
15+
tauri-plugin-aptabase = { git = "https://github.com/aptabase/tauri-plugin-aptabase", branch = "v2" }
1616
```
1717

1818
You can install the JavaScript Guest bindings using your preferred JavaScript package manager
1919

2020
```bash
21-
npm add @aptabase/tauri
21+
npm add https://github.com/aptabase/tauri-plugin-aptabase#v2
2222
```
2323

24-
> 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).
25-
2624
## Usage
2725

2826
First, you need to get your `App Key` from Aptabase, you can find it in the `Instructions` menu on the left side menu.
2927

30-
Then you need to register the core plugin with Tauri:
28+
Then register the plugin with Tauri:
3129

3230
`src-tauri/src/main.rs`
3331

@@ -40,11 +38,12 @@ fn main() {
4038
}
4139
```
4240

41+
And finally add `aptabase:allow-track-event` to your list Access Control List.
42+
4343
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`.
4444

4545
As an example, you can add `app_started` and `app_exited` events like this:
4646

47-
4847
```rust
4948
use tauri_plugin_aptabase::EventTracker;
5049

@@ -83,3 +82,35 @@ A few important notes:
8382
- Because of this, it's generally recommended to at least track an event at startup
8483
3. You do not need to await for the `trackEvent` function, it'll run in the background.
8584
3. Only strings and numbers values are allowed on custom properties
85+
86+
## Providing the APTABASE_KEY via .env
87+
88+
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
89+
in the `src-tauri` directory for the `dotevny_macro` crate to find it properly.
90+
91+
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.
92+
93+
```rust
94+
use tauri_plugin_aptabase::EventTracker;
95+
use dotenvy_macro::dotenv;
96+
97+
#[cfg_attr(mobile, tauri::mobile_entry_point)]
98+
/// This function sets up and runs a Rust application using the Tauri framework, with various plugins
99+
/// and event handlers.
100+
pub fn run() {
101+
tauri::Builder::default()
102+
.build(tauri::generate_context!())
103+
.plugin(tauri_plugin_aptabase::Builder::new(dotenv!("APTABASE_KEY")).build())
104+
.expect("Error when building tauri app")
105+
.run(|handler, event| match event {
106+
tauri::RunEvent::Exit { .. } => {
107+
handler.track_event("app_exited", None);
108+
handler.flush_events_blocking();
109+
}
110+
tauri::RunEvent::Ready { .. } => {
111+
handler.track_event("app_started", None);
112+
}
113+
_ => {}
114+
});
115+
}
116+
```

build.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const COMMANDS: &[&str] = &["track_event"];
2+
3+
fn main() {
4+
tauri_plugin::Builder::new(COMMANDS).build();
5+
}

examples/helloworld/README.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

examples/helloworld/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
<meta charset="UTF-8" />
55
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<title>Tauri + React + TS</title>
7+
<title>Tauri + Svelte</title>
88
</head>
99

1010
<body>
11-
<div id="root"></div>
12-
<script type="module" src="/src/main.tsx"></script>
11+
<div id="app"></div>
12+
<script type="module" src="/src/main.js"></script>
1313
</body>
1414
</html>

examples/helloworld/jsconfig.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"compilerOptions": {
3+
"moduleResolution": "Node",
4+
"target": "ESNext",
5+
"module": "ESNext",
6+
/**
7+
* svelte-preprocess cannot figure out whether you have
8+
* a value or a type, so tell TypeScript to enforce using
9+
* `import type` instead of `import` for Types.
10+
*/
11+
"importsNotUsedAsValues": "error",
12+
"isolatedModules": true,
13+
"resolveJsonModule": true,
14+
/**
15+
* To have warnings / errors of the Svelte compiler at the
16+
* correct position, enable source maps by default.
17+
*/
18+
"sourceMap": true,
19+
"esModuleInterop": true,
20+
"skipLibCheck": true,
21+
"forceConsistentCasingInFileNames": true,
22+
"baseUrl": ".",
23+
/**
24+
* Typecheck JS in `.svelte` and `.js` files by default.
25+
* Disable this if you'd like to use dynamic types.
26+
*/
27+
"checkJs": true
28+
},
29+
/**
30+
* Use global.d.ts instead of compilerOptions.types
31+
* to avoid limiting type declarations.
32+
*/
33+
"include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.svelte"]
34+
}

examples/helloworld/package.json

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,14 @@
1111
"tauri": "tauri"
1212
},
1313
"dependencies": {
14-
"react": "^18.2.0",
15-
"react-dom": "^18.2.0",
16-
"@tauri-apps/api": "^1.2.0",
14+
"@tauri-apps/api": "^2.1.1",
1715
"@aptabase/tauri": "file:../../"
1816
},
1917
"devDependencies": {
20-
"@types/node": "^18.7.10",
21-
"@types/react": "^18.0.15",
22-
"@types/react-dom": "^18.0.6",
23-
"@vitejs/plugin-react": "^3.0.0",
24-
"typescript": "^4.6.4",
25-
"vite": "^4.0.0",
26-
"@tauri-apps/cli": "^1.2.2"
18+
"@sveltejs/vite-plugin-svelte": "^1.0.1",
19+
"internal-ip": "^7.0.0",
20+
"svelte": "^3.49.0",
21+
"vite": "^3.0.2",
22+
"@tauri-apps/cli": "^2.1.0"
2723
}
2824
}
Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)