If your site is a JavaScript app with a build step, you can add the tracking snippet from your own code instead of pasting the script tag. The @behavly/browser package adds the same tag for you and gives you typed track and identify calls. Both ways record exactly the same things.
npm install @behavly/browserStart It
Call init once, with your site's write key from Tracking → Setup, in code that runs on every page:
import { init } from "@behavly/browser";
init({ pid: "YOUR_WRITE_KEY" });On the server it does nothing, so it is safe to import in Next.js, Nuxt and SvelteKit. Calling it again, or on a page that already has the script tag, adds nothing.
React And Next.js
Put the component in your root layout, once. In the Next.js App Router the layout can stay a server component:
import { BehavlyScript } from "@behavly/browser/react";
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>
{children}
<BehavlyScript pid="YOUR_WRITE_KEY" />
</body>
</html>
);
}Vue, Nuxt and SvelteKit examples are in the package's README.
There is no page view code to add. The snippet records every page on its own, including navigation inside a single-page app.
Send Events
import { track, identify } from "@behavly/browser";
track("signup", { plan: "pro" });
identify("person@example.com", { name: "Pat Example" });A call made before the snippet has loaded waits and is sent as soon as it starts. You rarely need identify: sign-ins are recognised on their own (see Identity). consent, reset, screen, flush, optOut and optIn work as they do on window.behavly.
Options
Each option sets one of the script tag's attributes, described in Install The Tracking Snippet:
| Option | Attribute |
|---|---|
allowLocalhost: true | data-allow-localhost="true" |
allowFileProtocol: true | data-allow-file-protocol="true" |
debug: true | data-debug="true" |
disableConsole: true | data-disable-console="true" |
allowedHostnames: ["example.io"] | data-allowed-hostnames="example.io" |
src: "https://a.example.com/t.js" | The address the snippet loads from, for your own subdomain. |



