AI app builders
Add Loogika to v0
An app built by v0 is a Next.js app. It has neither one index.html file nor a project setting where head code can go. You load Loogika from the root layout, app/layout.tsx, with a next/script tag, because that layout wraps every page. Either v0 adds the tag after a prompt or you edit the file in the Code tab, and then you publish.
Last updated .
What do you need before you start?
You need the script address with your site ID. Open Site Settings in the Loogika dashboard and look at the tag on the Tracking Script tab. The address is the src value of that tag, and your 12-character site ID comes after siteId=:
https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID
How do you ask v0 to add the Loogika script?
Paste the prompt below into the chat, with your own site ID in the address:
Add the Loogika analytics script to the root layout (app/layout.tsx) using next/script with strategy="afterInteractive", so it loads on every page:
https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID
Check the diff afterwards. v0 should have placed the <Script> component in app/layout.tsx. A page file or a component file is the wrong place for it.
How do you add the script yourself in app/layout.tsx?
Open app/layout.tsx from the Code tab, which sits in the preview toolbar. Add the Script component inside <body>, as in the example below. Press Cmd+S or Ctrl+S to save.
import Script from "next/script";
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
{children}
<Script
src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID"
strategy="afterInteractive"
/>
</body>
</html>
);
}
You do not need the defer attribute from the plain tag here. The strategy setting of next/script decides when the script loads.
How do you publish the change?
You find Publish in the upper right corner of the chat. Click it and choose Publish to Production. Saving a file refreshes the preview only, and the live site stays unchanged until you run Publish to Production. In a project connected to GitHub, v0 first merges a pull request, and the production deployment runs after that.
Loogika tracks moves between pages through <Link> and router.push() as pageviews automatically. SPA Navigation in Site Settings controls that, and it is on for a new site.
How do you check that Loogika is installed?
Load the production site in a fresh browser tab and visit a few pages. The pageviews show up in the Loogika dashboard within a few seconds. If nothing arrives, open the page source and look for script.js?siteId=, then see the script troubleshooting page.
How do you track events in a v0 app?
Events are sent with window.loogika.event(), and the call belongs in a client component. Put a guard around it. A v0 component may render on the server, and the Loogika script only loads once hydration is done. Hydration is the step where React takes over the HTML that the server sent.
"use client";
export function SignupButton() {
const handleClick = () => {
if (typeof window !== "undefined" && window.loogika) {
window.loogika.event("signup_click", { location: "hero" });
}
};
return <button onClick={handleClick}>Sign up</button>;
}
The example is a file such as components/signup-button.tsx. The page about custom events covers event names, properties and their limits.
What if v0 rewrites the layout later?
A later prompt can make v0 generate app/layout.tsx again without the script. Add the line "app/layout.tsx must always contain the Loogika Script tag" to the custom instructions of the project. Check the page source again after large changes.
Where does the script go in a Pages Router project?
A project with a pages/ folder in place of app/ uses the Pages Router. Put the Script component in pages/_app.tsx in that case. The Next.js guide shows that setup.