OnyxMetric
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

  1. Paste the snippet into the <head> of your frontend's index.html:
index.html
<script src="https://app.onyxmetric.com/api/script.js?siteId=YOUR_SITE_ID" async></script>
  1. Allow the host in both script-src and connect-src. Keep ipc: and http://ipc.localhost, which Tauri needs for frontend-to-Rust calls:
src-tauri/tauri.conf.json
{
  "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.js returns 200 and 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 dev but not in the built app: in development the frontend is served from your dev server (http://localhost:1420 by 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.com there. The script tag needs both script-src and connect-src.
  • Object vs string CSP: app.security.csp takes either one policy string or the object form shown above. Do not mix the two.

Next steps

On this page