Qwik
Add Rybbit analytics to your Qwik app
A Qwik City app renders the whole document from src/root.tsx, which owns the <head> and <body> elements. Add the snippet to that <head> and it is on every route.
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 Qwik
Open src/root.tsx and add the tag inside <head>, after <RouterHead />:
import { component$ } from "@builder.io/qwik";
import { QwikCityProvider, RouterOutlet } from "@builder.io/qwik-city";
import { RouterHead } from "./components/router-head/router-head";
import "./global.css";
export default component$(() => {
return (
<QwikCityProvider>
<head>
<meta charset="utf-8" />
<RouterHead />
<script src="https://app.rybbit.io/api/script.js?siteId=YOUR_SITE_ID" defer></script>
</head>
<body lang="en">
<RouterOutlet />
</body>
</QwikCityProvider>
);
});src/components/router-head/router-head.tsx renders per-route head exports (title, meta, links). Keep the Rybbit tag in root.tsx so it does not depend on any route's head export.
Navigations through Qwik City's <Link> component are tracked automatically as pageviews.
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.
Track custom events
Call window.rybbit.event() from a $ event handler. Handlers only run in the browser, so window is always defined; guard against a blocked or still-loading script.
import { component$ } from "@builder.io/qwik";
export const SignupButton = component$(() => {
return (
<button
onClick$={() => {
if (window.rybbit) {
window.rybbit.event("signup_click", { location: "hero" });
}
}}
>
Sign up
</button>
);
});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.