Skip to main content
Add one Bily component inside your existing React Router. It starts the SDK and tracks later route changes without duplicating the automatic initial page view. Do not add a raw Bily script tag anywhere else in the application. init() loads the script for you.

Install Bily

Track every route once

This example uses React Router. It remembers the initial URL so it does not send a second PageView, then ignores repeated calls for the same URL.
src/bily-tracking.tsx
Mount the component once in a component that your existing router already renders. This lets useLocation() observe committed routes without creating a second router.
src/AppRoutes.tsx
This setup expects react-router-dom to be installed and a router to exist above AppRoutes. Do not add another BrowserRouter, Router, or RouterProvider. Repeated init() calls with the same URL are safe. One component keeps ownership clear, while the URL guard prevents React development checks from creating duplicate route events.

Track successful actions

Call track() only after the user action succeeds.
src/LaunchCampaignButton.tsx

Verify React Router

Check the initial view, later routes, and action events without duplicates.

Use framework mode

Install Bily in a React Router framework mode or Remix root route.