Guide
Lovable Analytics in WordPress: How to Keep Data
Analytics scripts in a Lovable app live in index.html or in React code, and neither comes across as a WordPress theme file. After you convert, you add the tracking snippet again on the WordPress side, in the block theme or through a small plugin. Keep the same property and the same measurement ID so your history stays in one place. Then check the paths, because WordPress URLs can differ from the Lovable routes.
Why the tracking code disappears
A Lovable app is React and TypeScript. Analytics is usually one of three things: a <script> tag in index.html, a snippet injected by a component, or a small hook that fires a page view on route change. All three are JavaScript that belongs to the React app.
The IQDesk converter produces a WordPress block theme: templates, template parts, patterns, theme.json and your images. It does not carry over custom React state, event handlers, third-party widgets or API calls. A tracking snippet falls in that group. Nothing is lost in your source project, but the theme will not contain it.
That is not a problem to solve in the theme files alone. WordPress already has normal places to put a script, and page views work differently there: every click is a real page load, so you do not need a route-change listener at all.
Find what you were running on Lovable
Before you add anything, look at the export and write down what was there. Open the project folder you got from GitHub sync or from the ZIP download. If you have not pulled the code yet, see how to export Lovable code.
Search the project for the usual markers. A plain text search across the folder is enough.
index.html— the most common spot for a plain analytics or tag manager snippet.src/main.tsxorsrc/App.tsx— an init call made once when the app mounts.- A hook or component — something that watches the router and sends a page view on each route change.
- Environment variables — look for names starting with
VITE_, such as a measurement ID. These were baked into the build, so the value is also visible in the built files. - Consent code — a cookie banner component that gated the script. You will need an equivalent in WordPress if you serve users in the EU or UK.
Add the snippet to WordPress
You have two sane options. A plugin is easier to keep across theme changes. Editing the theme keeps the site free of extra plugins. Both are fine for a single snippet.
If you use a plugin, install one that adds header and footer scripts, paste the snippet in the header field, and save. Nothing else is needed. If you prefer the theme, add a small function that prints the snippet in the head.
- Copy the snippet from your analytics provider, not from the Lovable code, so you get the current version.
- Open the theme folder of the converted theme and find
functions.php. If the file is not there, create it. - Hook the snippet into
wp_headwith a function that echoes the script tag. Keep the measurement ID identical to the one you used on Lovable. - Upload the theme again through
Appearance → Themes → Add New → Upload Theme, or edit the file over SFTP on your host. - Load the site in a private window and confirm in your provider's realtime view that a hit arrives.
- Repeat for a second page so you can see that page views are recorded with the right path.
Make the data comparable after the switch
Keeping the same property is the first half. The second half is making sure the URLs line up. On Lovable, a route is defined in src/App.tsx or in src/routes. In WordPress, the same page has a slug set per page, and the overall shape comes from Settings → Permalinks. If /about-us becomes /about, your reports show two different pages for the same content.
Fix this before you launch, not after. Either set the WordPress slugs to match the old routes, or redirect the old paths to the new ones. The converter reads public/_redirects and carries those rules over, and the complete conversion guide covers where they land.
Expect some numbers to move even with everything set up correctly. A WordPress page is a server round trip, while the old app changed views in the browser. Bounce rate, pages per session and time on page are measured differently once that changes. Treat the switch date as a line in your charts rather than a regression.
- Annotate the launch date in your analytics tool so later comparisons make sense.
- Keep one property, not a new one, unless you genuinely want a clean break.
- Check the home page path, set under
Settings → Reading → "Your homepage displays", appears as/and not as/home. - Uncheck "Discourage search engines from indexing this site" under
Settings → Readingbefore launch, or your traffic data will stay flat for the wrong reason.
Events and forms need a second look
Page views are the easy part. Custom events are not. Anything you tracked with an onClick handler in React is gone, because the handler is gone. The converter is explicit about this: custom event handlers are not converted. The full list is on supported features.
In WordPress you rebuild those events with whatever your analytics tool offers. Most providers can track outbound links, file downloads and button clicks from the dashboard without touching code. Start there before you write anything custom.
Form submissions are the case most people care about. If your contact form became a Contact Form 7 form during conversion, the plugin fires its own DOM event when a submission succeeds. You can listen for that and send a conversion. See Contact Form 7's documentation for the current event name. If you run a store, WooCommerce has its own purchase tracking, usually handled by the analytics integration for your provider.
Verify before and after in Playground
The IQDesk review screen puts the converted site next to the original inside WordPress Playground, in the browser. That is the right moment to compare page structure and paths, so you spot a renamed slug before it reaches production. Analytics itself will not fire usefully in Playground, since the site is not on your domain, so test the snippet only on a real install.
Conversion, review and the theme download are free, and every account includes two free AI-fix attempts. You can run your project through the converter and check the page list without paying anything.
If something in the theme needs to change for your tracking, say a missing wrapper or a button that should be a real link, the AI fix agent can read the source project and edit the theme. There is a limit of 2,000 characters per instruction and 20 tool steps per fix, so keep each request to one concrete change.
A short checklist before launch
Run through this once on the live domain, not on staging. Five minutes here saves a month of broken reports.
- Snippet present on every page, checked by viewing source on the home page and one inner page.
- Measurement ID matches the one used on the Lovable site.
- Slugs match or redirect, so old URLs do not turn into 404s in your reports.
- Indexing is allowed in
Settings → Reading. - Realtime shows your visit from a device that is not blocked by your own filters.
- Key events rebuilt: form submission, main call-to-action click, outbound links.
- Consent banner in place, if you had one on Lovable, and the script respects it.
FAQ
Does the Lovable to WordPress converter keep my analytics code?
No. The converter produces a block theme with templates, patterns, theme.json and images. Third-party scripts, custom React state and event handlers are not converted. You add the tracking snippet again on the WordPress side, either through a header-and-footer script plugin or in the theme's functions.php.
Should I create a new analytics property when I move to WordPress?
Usually not. Keeping the same property and the same measurement ID keeps your history in one place. Annotate the launch date instead, so you can explain any step change in the numbers. Create a new property only if you want a deliberate clean break.
Why do my engagement numbers change after the move?
A Lovable React app changes views in the browser, while WordPress loads a new page from the server on every click. Analytics tools measure sessions, pages per session and time on page differently in those two cases. The traffic is the same; the measurement is not.
How do I track contact form submissions in WordPress?
If your form was converted to Contact Form 7, the plugin fires a browser event when a submission succeeds. You can listen for that event and send a conversion to your analytics tool. Check Contact Form 7's documentation for the current event name.
Where was the analytics code in my Lovable project?
Most often in index.html as a plain script tag. It can also be an init call in src/main.tsx or src/App.tsx, or a hook that sends a page view on route change. Search the exported project for your provider's name or measurement ID to find it.