Integration Guides
Tauri
Add OnyxMetric analytics to your Tauri app
Tauri v2 bundles your frontend into the app and serves it to the system webview. Put the script tag in the frontend's index.html, then allow https://app.onyxmetric.com in the app's Content Security Policy.
Copy your tracking snippet
In OnyxMetric, open your site's Site Settings and copy the tracking script. It looks like this:
<script src="https://app.onyxmetric.com/api/script.js?siteId=YOUR_SITE_ID" async></script>YOUR_SITE_ID is the numeric ID of your site.
Add the snippet to Tauri
- Paste the snippet into the
<head>of your frontend'sindex.html:
<script src="https://app.onyxmetric.com/api/script.js?siteId=YOUR_SITE_ID" async></script>- Allow the host in both
script-srcandconnect-src. Keepipc:andhttp://ipc.localhost, which Tauri needs for frontend-to-Rust calls:
{
"app": {
"security": {
"csp": {
"default-src": "'self'",
"script-src": ["'self'", "https://app.onyxmetric.com"],
"connect-src": ["ipc:", "http://ipc.localhost", "https://app.onyxmetric.com"]
}
}
}
}If app.security.csp is unset, Tauri applies no CSP and no change is needed. Route changes inside the app are tracked automatically.
Check that it works
Load your live site and click through a few pages. Pageviews show up in the OnyxMetric dashboard within seconds.
If nothing arrives:
- View the page source and search for
script.js?siteId=to confirm the tag is present. - In the browser's Network tab, check that
script.jsreturns200and that requests go to/api/track. - Turn off ad blockers, or proxy the script through your own domain.
- Read script troubleshooting for other causes.
Troubleshooting
- Works in
tauri devbut not in the built app: in development the frontend is served from your dev server (http://localhost:1420by default), a normal http origin. The built app uses a custom scheme, so check the CSP and test a production build. - CSP violation in the webview console: the message names the blocked directive. Add
https://app.onyxmetric.comthere. The script tag needs bothscript-srcandconnect-src. - Object vs string CSP:
app.security.csptakes either one policy string or the object form shown above. Do not mix the two.
Next steps
- Track custom events such as signups, purchases, and clicks.
- Identify users to tie sessions to accounts.
- Proxy the script through your own domain to get past ad blockers.
- Script attributes let you skip or mask URLs and tag events.