How do I install Google Tag Manager?
Last checked 31 Aug 2026
Short answer
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.
Setup steps
- Create a container in Google Tag Manager and copy the two snippets it gives you (one for
<head>, one right after<body>). - Ask Lovable:
"Add my Google Tag Manager container GTM-XXXXXXX to the site, with the head snippet in the document head and the noscript snippet right after the opening body tag, on every page."
Why GTM instead of individual scripts
If you expect to add or swap tracking tools over time (analytics, ad pixels, conversion tracking), GTM lets you manage them from the Tag Manager interface without asking Lovable to edit code each time. For a single, permanent tracking script, adding it directly (see /questions/how-do-i-connect-google-analytics) is simpler.
Single-page app note
Same caveat as GA4: Lovable apps navigate client-side, so GTM's default "Page View" trigger only fires on the first load. Set up a custom trigger listening for route changes, or ask Lovable to push a dataLayer event on each route change:
"Push an event to the dataLayer named 'route_change' whenever the route changes, so I can use it as a trigger in Tag Manager."
Verifying it works
Use GTM's built-in Preview mode against your published or preview URL — it shows exactly which tags fired and what data layer values they saw.
What usually goes wrong
- Only adding the head snippet and skipping the body/noscript snippet — fine for most tags, but technically incomplete per Google's instructions.
- Tags configured in GTM but never published (GTM has its own separate "Publish" step distinct from Lovable's Publish).
- Duplicate tracking because both a direct GA snippet and a GTM-managed GA tag are live at once — pick one path.
- Ad blockers and browser tracking protection affecting a portion of visitors regardless of setup.
Sources
Was this answer helpful?
Related questions
- 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 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.
- 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 connect an email marketing platform?Ask Lovable to send new subscribers or events to your email platform's API (Mailchimp, ConvertKit, Klaviyo, etc.) via a server function using an API key stored as a secret.