Skip to content
Every tutorial here is 100% free — and always will be
LSLovableStudent

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

  1. Create a Google Analytics 4 property and copy its Measurement ID (starts with G-).
  2. 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.

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

Website made, maintained and hosted by PromptSites.com

PromptSites logo