Tauri
Add Fluxner analytics to your Tauri app
SDK release pending
The Fluxner web SDK is not published to npm. The SDK tab below is reference only; do not install similarly named packages. Review the Script tag option against your app's security policy and the platform limitations below, or wait for an official SDK release. See Web SDK availability.
Tauri v2 bundles your frontend into the app and serves it to the system webview. Install the @fluxner/js SDK in the frontend (or put the snippet in its index.html), then allow https://fluxner.com in the app.security.csp block of src-tauri/tauri.conf.json.
Get your tracking snippet
In your Fluxner dashboard, open Site Settings → Tracking Script and copy your snippet. It looks like this:
<script src="https://fluxner.com/api/script.js?siteId=YOUR_SITE_ID" defer></script>YOUR_SITE_ID is the numeric ID of your site. If you self-host Fluxner on another domain, replace fluxner.com with your instance's domain.
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:
# No npm installation is available yet. Review the Script tag option or wait.- Initialise it once in the frontend entry file (
src/main.tsor equivalent):
import fluxner from "@fluxner/js";
await fluxner.init({
analyticsHost: "https://fluxner.com/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://fluxner.com"]
}
}
}
}- Paste the snippet into the
<head>of your frontend'sindex.html:
<script src="https://fluxner.com/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://fluxner.com"],
"connect-src": ["ipc:", "http://ipc.localhost", "https://fluxner.com"]
}
}
}
}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 Fluxner 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. Fluxner'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://fluxner.comthere; 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.