How do I connect Google Analytics?
Last checked 31 Aug 2026
Short answer
Ask Lovable to add your Google Analytics measurement ID as a script/tag in the site's head, or install it via Google Tag Manager for more flexibility.
Quick setup
- Create a Google Analytics 4 property and copy its Measurement ID (starts with
G-). - Ask Lovable to add it:
"Add Google Analytics tracking to the whole site using measurement ID G-XXXXXXX."
Lovable will add the GA4 script to the app's shared layout/head so it loads on every page.
Single-page app considerations
Because Lovable apps are React single-page apps (or TanStack Start apps with client-side routing), GA4's default pageview tracking can miss route changes that don't trigger a full page load. Ask Lovable to fire a pageview event on route change specifically:
"Make sure a Google Analytics pageview event fires every time the route changes, not just on initial load."
Verifying it works
Use GA4's Realtime report while browsing your published (or preview) site — events should appear within a minute or two. If nothing shows up, check the browser console for script errors before assuming GA is misconfigured.
Privacy and consent
If you have EU/UK visitors, check whether you need a cookie consent banner before analytics scripts fire — GA4 sets cookies by default. This is a compliance decision for you to make, not something Lovable decides automatically.
What usually goes wrong
- Measurement ID pasted into a component instead of the shared head/layout, so only one page gets tracked.
- Ad blockers blocking GA on a meaningful share of visitors — treat GA numbers as directional, not exact.
- Testing in preview mode where analytics may be excluded or blocked; verify on the published site too.
- Using a Universal Analytics ID (old format, starting with
UA-) — that product is retired; you need a GA4 property.
See also /questions/how-do-i-install-google-tag-manager if you'd rather manage multiple tracking scripts through one tag manager instead of adding each individually.
Sources
Was this answer helpful?
Related questions
- AnswerHow do I install Google Tag Manager?Ask Lovable to add your GTM container snippet to the site's shared head and body, then manage individual tags (analytics, ads, pixels) from within Tag Manager itself.
- AnswerHow do I connect an API to Lovable?Describe the API and what you want it to do in Chat; Lovable will typically wire the call through a server function (Edge Function) so any API key stays off the client.
- AnswerHow do I connect Meta Pixel?Ask Lovable to add your Meta Pixel ID as a script in the site's shared head, and fire a PageView (or custom) event on each route change since Lovable apps are single-page apps.
- AnswerHow do I use webhooks?Webhooks let external services notify your Lovable app when something happens; ask Lovable to create a server function URL as the webhook endpoint, and configure that URL in the third-party service.