Tauri
Add Rybbit analytics to your Tauri app
Tauri v2 bundles your frontend into the app and serves it to the system webview. Install the @rybbit/js SDK in the frontend (or put the snippet in its index.html), then allow https://app.rybbit.io in the app.security.csp block of src-tauri/tauri.conf.json.
Get your tracking snippet
In your Rybbit dashboard, open Site Settings → Tracking Script and copy your snippet. It looks like this:
<script src="https://app.rybbit.io/api/script.js?siteId=YOUR_SITE_ID" defer></script>YOUR_SITE_ID is the numeric ID of your site. If you self-host Rybbit, app.rybbit.io is the domain of your own instance.
Add the snippet to Tauri
Tauri's security guide advises against loading remote scripts such as CDN-hosted files. The SDK keeps all executable code inside the bundle, so it is the recommended method.
- Install the package in your frontend project:
npm install @rybbit/js- Initialise it once in the frontend entry file (
src/main.tsor equivalent):
import rybbit from "@rybbit/js";
await rybbit.init({
analyticsHost: "https://app.rybbit.io/api",
siteId: "YOUR_SITE_ID",
});- Allow the analytics host in
connect-src. Keepipc:andhttp://ipc.localhost, which Tauri needs for frontend-to-Rust calls:
{
"app": {
"security": {
"csp": {
"default-src": "'self'",
"connect-src": ["ipc:", "http://ipc.localhost", "https://app.rybbit.io"]
}
}
}
}- Paste the snippet into the
<head>of your frontend'sindex.html:
<script src="https://app.rybbit.io/api/script.js?siteId=YOUR_SITE_ID" defer></script>- Allow the host in both
script-srcandconnect-src:
{
"app": {
"security": {
"csp": {
"default-src": "'self'",
"script-src": ["'self'", "https://app.rybbit.io"],
"connect-src": ["ipc:", "http://ipc.localhost", "https://app.rybbit.io"]
}
}
}
}If app.security.csp is unset, Tauri applies no CSP and neither change is needed. Route changes inside the app are tracked automatically: the tracker wraps history.pushState and history.replaceState and listens for popstate and hashchange.
Verify installation
Open your live site in a new tab and click through a few pages. Within a few seconds the pageviews appear in the Rybbit dashboard.
If nothing shows up:
- View the page source and search for
script.js?siteId=to confirm the snippet is on the page. - Open the browser Network tab and check that
script.jsreturns200and thatPOSTrequests go to/api/track. - Disable ad blockers, or set up a proxy so the script loads from your own domain.
- See the script troubleshooting guide for other common causes.
Troubleshooting
- Works in
tauri devbut not in the built app on macOS, Linux or iOS: in development the frontend is served from your dev server (http://localhost:1420by default), which is a normal http origin. Production builds serve it fromhttp://tauri.localhoston Windows and Android but from the custom schemetauri://localhoston macOS, Linux and iOS. Rybbit's tracking endpoints answer CORS preflights forhttp://andhttps://origins only, so requests fromtauri://localhostare blocked by the webview. On Windows and Android,app.windows[].useHttpsScheme: trueswitches the origin tohttps://tauri.localhost; both forms work. - CSP violation in the webview console: the message names the blocked directive. Add
https://app.rybbit.iothere; the SDK only needsconnect-src, the script tag also needsscript-src. - Object vs string CSP:
app.security.cspaccepts either a single policy string or the object form shown above. Do not mix the two.
Next steps
- Track custom events such as signups, purchases and button clicks.
- Identify users to connect sessions to accounts.
- Proxy the script through your own domain to bypass ad blockers.
- Script attributes let you skip or mask URLs and tag events.