tauri-plugin-telemetry 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright © 2026 lispking
4
+
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the “Software”), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,160 @@
1
+ # Tauri Plugin for Telemetry
2
+
3
+ A backend-agnostic analytics/telemetry plugin for Tauri v2 apps. Send events to
4
+ **any** backend that implements the ingest protocol — point the plugin at your
5
+ own backend with `InitOptions.host`.
6
+
7
+ ## Install
8
+
9
+ Add the Rust crate to `src-tauri/Cargo.toml`:
10
+
11
+ ```toml
12
+ [dependencies]
13
+ tauri-plugin-telemetry = "0.1.0"
14
+ ```
15
+
16
+ ```toml
17
+ [dependencies]
18
+ tauri-plugin-telemetry = { git = "https://github.com/lispking/tauri-plugin-telemetry" }
19
+ ```
20
+
21
+ Install the JavaScript guest bindings with your preferred package manager:
22
+
23
+ ```bash
24
+ npm add tauri-plugin-telemetry
25
+ ```
26
+
27
+ ```bash
28
+ npm add https://github.com/lispking/tauri-plugin-telemetry
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ Register the plugin with Tauri, pointing it at your analytics backend via
34
+ `InitOptions.host`:
35
+
36
+ `src-tauri/src/main.rs`
37
+
38
+ ```rust
39
+ use tauri_plugin_telemetry::{Builder, InitOptions};
40
+
41
+ #[tokio::main]
42
+ async fn main() {
43
+ let opts = InitOptions {
44
+ host: Some("https://analytics.myapp.com".into()), // your backend
45
+ ..Default::default()
46
+ };
47
+
48
+ tauri::Builder::default()
49
+ .plugin(Builder::new("my-app-key-123").with_options(opts).build())
50
+ .run(tauri::generate_context!())
51
+ .expect("error while running tauri application");
52
+ }
53
+ ```
54
+
55
+ Then add `telemetry:allow-track-event` to your Access Control List.
56
+
57
+ Send events from Rust via the `EventTracker` trait:
58
+
59
+ ```rust
60
+ use tauri_plugin_telemetry::EventTracker;
61
+
62
+ #[tokio::main]
63
+ async fn main() {
64
+ tauri::Builder::default()
65
+ .plugin(/* ...as above... */)
66
+ .setup(|app| {
67
+ app.track_event("app_started", None);
68
+ Ok(())
69
+ })
70
+ .build(tauri::generate_context!())
71
+ .expect("error while running tauri application")
72
+ .run(|handler, event| match event {
73
+ tauri::RunEvent::Exit { .. } => {
74
+ handler.track_event("app_exited", None);
75
+ handler.flush_events_blocking();
76
+ }
77
+ _ => {}
78
+ })
79
+ }
80
+ ```
81
+
82
+ The `trackEvent` function is also available through the JavaScript guest bindings:
83
+
84
+ ```js
85
+ import { trackEvent } from "tauri-plugin-telemetry";
86
+
87
+ trackEvent("save_settings") // An event with no properties
88
+ trackEvent("screen_view", { name: "Settings" }) // An event with a custom property
89
+ ```
90
+
91
+ A few important notes:
92
+
93
+ 1. The plugin automatically enriches each event with useful information: OS,
94
+ app version, locale, and other system properties.
95
+ 2. You're in control of what gets sent. No events are tracked automatically —
96
+ call `trackEvent` manually (it's recommended to at least track one event at
97
+ startup).
98
+ 3. You don't need to await `trackEvent`; it runs in the background.
99
+ 4. Only string and number values are allowed in custom properties.
100
+
101
+ ## Providing the APP_KEY via .env
102
+
103
+ You can load the App Key from a `.env` file at compile time using the
104
+ `dotenvy_macro` crate. The `.env` file must be in the `src-tauri` directory.
105
+
106
+ ```rust
107
+ use tauri_plugin_telemetry::{Builder, EventTracker, InitOptions};
108
+ use dotenvy_macro::dotenv;
109
+
110
+ #[cfg_attr(mobile, tauri::mobile_entry_point)]
111
+ pub fn run() {
112
+ let opts = InitOptions {
113
+ host: Some("https://analytics.myapp.com".into()),
114
+ ..Default::default()
115
+ };
116
+
117
+ tauri::Builder::default()
118
+ .build(tauri::generate_context!())
119
+ .plugin(Builder::new(dotenv!("APP_KEY")).with_options(opts).build())
120
+ .expect("Error when building tauri app")
121
+ .run(|handler, event| match event {
122
+ tauri::RunEvent::Exit { .. } => {
123
+ handler.track_event("app_exited", None);
124
+ handler.flush_events_blocking();
125
+ }
126
+ tauri::RunEvent::Ready { .. } => {
127
+ handler.track_event("app_started", None);
128
+ }
129
+ _ => {}
130
+ });
131
+ }
132
+ ```
133
+
134
+ For AI/LLM integration instructions, see [llms.txt](./llms.txt)
135
+
136
+ ## Using a custom backend (self-hosting)
137
+
138
+ The plugin can point at any backend that implements its ingest protocol. The
139
+ relevant `InitOptions` fields:
140
+
141
+ ```rust
142
+ use tauri_plugin_telemetry::{Builder, InitOptions};
143
+
144
+ let opts = InitOptions {
145
+ // Your analytics backend base URL. Required to enable tracking.
146
+ host: Some("https://analytics.myapp.com".into()),
147
+ // All of the following are optional and default to the values shown.
148
+ api_path: Some("/v1/events".into()), // default: /v1/events
149
+ app_key_header: Some("App-Key".into()), // default: App-Key
150
+ sdk_name: Some("myapp@1.0.0".into()), // default: <crate>@<version>
151
+ ..Default::default()
152
+ };
153
+
154
+ tauri::Builder::default()
155
+ .plugin(Builder::new("my-app-key-123").with_options(opts).build())
156
+ .run(tauri::generate_context!())
157
+ .expect("error while running tauri application");
158
+ ```
159
+
160
+ Inspired by the [Aptabase](https://aptabase.com/) analytics platform, which is a great option if you don't want to self-host.
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "tauri-plugin-telemetry",
3
+ "version": "0.1.1",
4
+ "private": false,
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "type": "module",
9
+ "description": "Backend-agnostic analytics/telemetry plugin for Tauri v2 apps. Redirect events to any backend.",
10
+ "author": "Guilherme Oenning",
11
+ "browser": "webview-dist/index.js",
12
+ "main": "webview-dist/index.js",
13
+ "types": "webview-dist/index.d.ts",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/lispking/tauri-plugin-telemetry.git"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/lispking/tauri-plugin-telemetry/issues"
20
+ },
21
+ "homepage": "https://github.com/lispking/tauri-plugin-telemetry",
22
+ "scripts": {
23
+ "build": "rollup -c ./webview-src/rollup.config.js",
24
+ "watch": "rollup -c ./webview-src/rollup.config.js -w",
25
+ "prepublishOnly": "npm run build",
26
+ "pretest": "npm run build"
27
+ },
28
+ "files": [
29
+ "README.md",
30
+ "LICENSE",
31
+ "webview-dist",
32
+ "package.json"
33
+ ],
34
+ "devDependencies": {
35
+ "@rollup/plugin-node-resolve": "^16.0.3",
36
+ "@rollup/plugin-typescript": "^12.3.0",
37
+ "@rollup/plugin-terser": "^1.0.0",
38
+ "rollup": "^4.62.2",
39
+ "typescript": "^6.0.3"
40
+ },
41
+ "dependencies": {
42
+ "@tauri-apps/api": "^2.11.1",
43
+ "tslib": "^2.8.1"
44
+ }
45
+ }
@@ -0,0 +1,5 @@
1
+ type Props = {
2
+ [key: string]: string | number;
3
+ };
4
+ export declare function trackEvent(name: string, props?: Props): Promise<void>;
5
+ export {};
@@ -0,0 +1 @@
1
+ async function e(e,n){await async function(e,n={},r){return window.__TAURI_INTERNALS__.invoke(e,n,r)}("plugin:telemetry|track_event",{name:e,props:n})}"function"==typeof SuppressedError&&SuppressedError;export{e as trackEvent};
@@ -0,0 +1,11 @@
1
+ declare namespace _default {
2
+ let input: string;
3
+ namespace output {
4
+ let dir: string;
5
+ let entryFileNames: string;
6
+ let format: string;
7
+ let exports: string;
8
+ }
9
+ let plugins: import("rollup").Plugin<any>[];
10
+ }
11
+ export default _default;