JavaScript frameworks
Add Loogika to Remix
In Remix, app/root.tsx produces the complete HTML document. You add the Loogika tag to the head in that file, and the script reaches every route of the app. Client-side navigation is counted as pageviews without extra code.
Last updated .
What do you need before you start?
Copy your script tag from Site Settings in Loogika, under the Tracking Script tab. It looks like this, with your own 12-character site ID in place of YOUR_SITE_ID:
<script src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID" defer></script>
React Router v7 is the successor to Remix. If your Remix v2 app has moved to it, follow the React Router guide instead of this page.
How do you add Loogika to app/root.tsx?
The file to edit is app/root.tsx, which a JavaScript project names app/root.jsx. Place the tag inside its head, after <Meta /> and <Links />, then restart the dev server.
import { Links, Meta, Outlet, Scripts, ScrollRestoration } from "@remix-run/react";
export default function App() {
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Links />
<script src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID" defer></script>
</head>
<body>
<Outlet />
<ScrollRestoration />
<Scripts />
</body>
</html>
);
}
Does Loogika track client-side navigation in Remix?
Yes. Remix renders the first page on the server and handles later navigation in the browser. Loogika records the first page when the script loads and each later route change as a new pageview.
Route tracking depends on the SPA Navigation setting in Site Settings, which is on by default. The script waits 500 milliseconds after a route change before it sends the pageview.
With SPA Navigation turned off, you record route changes yourself. Call window.loogika.pageview() from an effect in the root component that runs when the value of useLocation() changes. Skip the first run of that effect, because the script has already counted the landing page.
How do you track custom events in Remix?
Routes and components can both call window.loogika.event() with an event name and optional properties. Remix renders components on the server as well, where window does not exist, so check for it first.
export default function OfferRoute() {
const handleClick = () => {
if (typeof window !== "undefined" && window.loogika) {
window.loogika.event("offer_claimed", { feature: "Special Offer" });
}
};
return <button onClick={handleClick}>Claim Offer</button>;
}
The example is a route file at app/routes/offer.tsx. The custom events guide explains event names, properties and their limits.
How do you check that Loogika is installed?
Bring up your app in a separate browser tab and browse a few routes. The pageviews show up in the Loogika dashboard within a few seconds.
If nothing arrives, open the page source and find script.js?siteId=. The browser Network tab should show script.js with status 200 and requests to /api/track. The script troubleshooting page covers ad blockers and wrong site IDs.