An AI-assisted code editor linked to a tagging server that distributes data to four platforms: server-side tracking for a Lovable site

Published by Thomas dans la catégorie Tracking on 18.11.2026 Last update : 18.11.2026 à 16h07


Table of content

Custom websites built with AI are everywhere. Web agencies deliver Lovable-built sites in a matter of days, and marketing teams create their own pages by prompt, with no CMS involved. The same question keeps coming up: can you measure a "vibe-coded" site as well as a WordPress or Shopify one? Our answer is yes, and often better. Clean code, a dataLayer written at the source and a built-in backend make an ideal foundation for top-tier server-side tracking, as long as the AI is given clear rules.

In short

  • Lovable generates a React application: after the first load, navigation happens without page reloads. Every page change must be sent to the dataLayer.

  • The A-Track architecture: consent banner and Consent Mode v2, web Google Tag Manager, then a server GTM container hosted by Stape on a subdomain of your site, which distributes to GA4, Google Ads, Meta, LinkedIn, Microsoft Ads and Brevo.

  • Forms go through Lovable's backend: the lead reaches Brevo through the API, with its source, and the conversion is sent server to server.

  • The tagging plan becomes a rule for the AI, written into the Lovable project instructions.

  • An AI that codes fast can also break measurement fast: daily monitoring is part of the setup.

Why an AI-built site is good ground for tracking

On a traditional CMS, measurement is often built in layers: one plugin for GA4, another for the Meta pixel, a theme injecting its own scripts, a form nobody quite knows how it sends its data. A Lovable site has none of that. The code belongs to the project, it can be versioned (GitHub sync) and it follows a precise specification.

  • A single entry point: Google Tag Manager is the only way in for tags. No plugin adds a script behind your back.

  • Events at the right moment: the code sends the event at the exact moment the action succeeds, for instance when the backend confirms the form was saved, not on a mere button click.

  • A built-in backend: Lovable Cloud provides a database and server functions (edge functions, built on Supabase technology). That is the basis for server-to-server measurement, independent of the browser.

Vibe coding also comes with three pitfalls of its own:

  1. Page views: without configuration, a single-page application counts one page view per visit, or duplicates instead.

  2. Scripts added "to be helpful": ask it to "add Google Analytics" and the AI will happily hard-code the gtag script or a Meta pixel into index.html, outside GTM and before any consent.

  3. Silent regressions: a prompt that rebuilds a component can delete a dataLayer push without anyone noticing. The form still works, but conversions stop.

The A-Track architecture for a Lovable site

Our reference setup comes down to six building blocks. It works just as well for a corporate site as for a lead generation platform.

  1. Consent: a CMP (CookieYes, Cookiebot, OneTrust, etc.) loads first. It passes the visitor's choice to Google through Consent Mode v2, to Microsoft through UET Consent Mode, and to the measurement server.

  2. Web GTM: a single container, loaded from your subdomain with Stape's Custom Loader. No other measurement script in the code.

  3. dataLayer: the React code pushes the events defined in the tagging plan (page_view, generate_lead, sign_up, phone and email clicks), each with a unique event_id.

  4. Server GTM on Stape: hosted in a European zone, on a subdomain such as metrics.your-site.ch. It receives events, strips unnecessary data, deduplicates and distributes. See our article on GA4 server-side with Stape.

  5. Destinations: GA4, Google Ads, Meta (Conversions API), LinkedIn (Conversions API), Microsoft Ads and Brevo.

  6. Backend: the server function that saves a form creates the contact in Brevo through the API and sends the conversion to the measurement server, with the same event_id as the browser.

Page views: handling navigation without reloads

Older Lovable projects are React (Vite) applications rendered in the browser. Since 13 May 2026, new projects use TanStack Start with server-side rendering, which solves most indexing issues. In both cases, once the first page has loaded, navigation is still handled by the browser: no page reloads, and the Google tag does not notice the URL change on its own.

Our rule: one page view mechanism, not two.

  • The application router pushes a page_view event on every route change, with the URL, title, language and page type.

  • In GA4, automatic tracking of browser history changes (enhanced measurement) is turned off, otherwise every navigation counts twice. Google describes these options in its single-page application documentation.

  • In staging, we check that one navigation produces exactly one page view, including the first page after server rendering.

Forms and Brevo: the lead goes through the server

On a Lovable site, a well-built form does not write to a third party straight from the browser. It calls a server function, which saves the request and calls the Brevo API with a key stored in the project secrets, never in the visible code.

Keeping the source of every lead

  • On arrival, the site reads the UTMs and click IDs (gclid, gbraid, wbraid, fbclid, li_fat_id, msclkid).

  • With consent, they are stored first-party and attached to the form. Without consent, only the channel-level source is kept, with no personal identifier.

  • The server function saves them as Brevo contact attributes (source, campaign, channel): your teams know where every request came from, in Brevo and in the CRM.

Sending the conversion without losing or duplicating it

  • The browser pushes generate_lead to the dataLayer after the backend's positive response.

  • The server function sends the same event to the measurement server, with the same event_id. The ad platforms deduplicate the two signals. If a blocker stops the browser, the server signal takes over, always within the limits of consent.

  • On the Brevo side, Stape's Brevo tag for server GTM tracks page views and the events your automation workflows need, only if the visitor accepted marketing cookies.

The measurement server receives a conversion and passes it to each platform in its own format.

  • Google Ads: conversion tag served by the server, enhanced conversions for leads (hashed email address), then import of qualified leads from Brevo or the CRM. See our article on the Google Ads Data Manager.

  • Meta: Conversions API with event_id deduplication and the _fbp and _fbc cookies preserved. Details in our article on Meta CAPI server-side.

  • LinkedIn: Conversions API, especially useful in B2B to feed qualified leads back. See our article on LinkedIn CAPI.

  • Microsoft Ads: UET tag with its Consent Mode, msclkid kept for attribution and offline conversion imports.

GA4 and Search Console: connecting measurement and visibility

  • GA4: one property, one web stream, key events limited to what matters (leads, sign-ups, contacts), custom dimensions (language, page type, form) and internal traffic excluded. The AI assistant channel deserves tracking too: see our article on AI traffic in GA4.

  • Search Console: the domain is verified through DNS, the sitemap submitted and the property linked to GA4. Lovable now offers an SEO review and a Search Console integration in the editor. To see what Google actually receives, Search Console's URL Inspection tool remains the reference.

Search Console does not go through server-side: it measures organic visibility on Google's side. It complements the setup, it does not replace it.

Measurement subdomain and Safari: the setting that makes the difference

The measurement server answers on a subdomain of your site, created with a simple DNS record, while the site itself stays hosted by Lovable. Safari, however, caps at 7 days the cookies set by a server whose IP address does not match the site's. Two solutions:

  • Same origin or Own CDN: if your domain runs through a CDN you control (Cloudflare, for example), the measurement server is served by the same infrastructure as the site. This is the most robust option (Stape documentation).

  • Cookie Keeper: otherwise, Stape's Cookie Keeper stores and restores measurement cookies, for visitors who have consented.

On the data side, Stape hosts the container in the European Union, whose member states offer an adequate level of protection under the FADP. The server also lets you clean data before it is sent to Google. Transfers to the ad platforms still need to be documented in your privacy policy (see our FADP and GDPR guide).

Giving the AI rules: the tagging plan inside Lovable

This is the heart of our method for AI-built sites. Measurement must not depend on the memory of whoever writes the prompt: it must be a rule the AI applies on its own.

  • Project instructions: Lovable lets you save persistent instructions, up to 10,000 characters per project, alongside instructions shared across the whole workspace.

  • AGENTS.md file: at the project root, it lists the technical rules the AI rereads every session, including the measurement files never to change without approval.

  • Contributor access: A-Track joins the project as a contributor and reviews any change that touches measurement.

  • For web agencies: measurement rules go into the workspace instructions, so every new client site starts with the right naming.

Sample A-Track rules for a Lovable project

  • No measurement script or pixel outside Google Tag Manager.

  • Every form pushes generate_lead with form_id and event_id, only after the backend's positive response.

  • Every route change pushes a single page_view.

  • Never put an email address or any personal data in a URL.

  • When rebuilding a component, keep every existing dataLayer push.

  • The Content Security Policy (CSP) allows the measurement subdomain.

After launch: monitor every day

On a site built by prompt, the code changes often, and fast. Every day we monitor event volumes, the gap between leads received in Brevo and conversions counted in GA4 and Google Ads, the consent rate and the absence of tags before consent. An alert goes out as soon as a metric drops. We explain this approach in our article on monitoring server-side tracking.

Where to start

  1. Remove from the code any measurement script added outside GTM.

  2. Write the tagging plan and add it to the Lovable project instructions.

  3. Route forms through a server function connected to Brevo, with the lead's source.

  4. Deploy server GTM on Stape on your subdomain, then connect GA4, Google Ads, Meta, LinkedIn, Microsoft Ads and Brevo.

  5. Test in Safari, then set up daily monitoring.

An AI-built site is not a compromise on data. Properly framed, it is one of the cleanest foundations for reliable, compliant server-side tracking.

Is your site built with Lovable or another AI tool?

A-Track checks your page views, forms, consent and the conversions sent to Google Ads, Meta, LinkedIn and Brevo, then tells you what to fix first.

Free flash audit within 48 hours, for businesses and web agencies alike.

Request my flash audit

Related services

Tracking & Compliance

Server-side tracking and FADP / GDPR compliance: around 40% more data recovered on average (measured across 100+ installations), from CHF 1,200.

Tracking & Compliance Audits

Tracking audit, FADP and GDPR compliance audit, data governance audit. Custom quote.

Annual Maintenance

Your tracking monitored and your compliance kept up to date, from CHF 900 a year.

Questions fréquemment posées

Can you run server-side tracking on a site built with Lovable?

▾
Yes. A Lovable site is a React application with a built-in backend (Lovable Cloud). We install web Google Tag Manager, a server GTM container hosted by Stape on a subdomain of the site, and server-to-server events sent from the backend functions.

Three points need attention: page views for navigation without page reloads, a consent banner that loads first, and a measurement subdomain configured for Safari.

How do you stop Lovable's AI from breaking your tracking?

▾
Write the tagging plan into the Lovable project instructions and an AGENTS.md file: event naming, no script outside Google Tag Manager, and existing dataLayer pushes to keep whenever a component is rebuilt.

Add daily monitoring: event volumes, the gap between leads received and conversions counted, and tags firing before consent. A regression is then spotted within a day, not a month.

How do you send leads from a Lovable form to Brevo with their source?

▾
The form calls a server function in the project, which creates or updates the contact through the Brevo API. The API key stays in the project secrets, never in the site's visible code.

The UTMs and click IDs read on arrival are attached to the form, with consent, then stored as contact attributes (source, campaign, channel). Without consent, only the channel-level source is kept, with no personal identifier.

How do you measure page views of a Lovable site in GA4?

▾
After the first load, navigation on a Lovable site happens without page reloads. The application router must therefore push a page_view event to the dataLayer on every route change, with the URL, title and language.

Keep a single mechanism: if the router sends page views, turn off GA4's automatic tracking of browser history changes, otherwise every navigation is counted twice.

Can we track AJAX forms without a thank you page?

▾
Yes, this is a specialty of the implementation via GTM. We listen for the form's "success" in the code or the Data Layer to trigger the conversion, without needing a specific URL.

Should I use a custom subdomain (e.g., data.mysite.com)?

▾
Yes, it is strongly recommended for server-side. Hosted on your own subdomain, the tracking server can set first-party cookies through HTTP headers. They generally last longer than cookies set in JavaScript, which Safari (ITP) caps at 7 days.

They are not immune to restrictions, though: Safari and Firefox keep evolving their protections (Safari can also cap these cookies, for example when the server's IP address is not close to your website's), some blockers filter these subdomains, and a refusal of consent remains a refusal.

Basic or advanced consent mode: which should you choose?

▾
It is a trade-off between conversion modelling and legal exposure, and it belongs to the controller.

In basic mode, no tag loads before the visitor makes a choice. You lose part of the modelling, but nothing goes to the advertising platform until the person has decided.

In advanced mode, cookieless signals are sent before the choice. Modelling is better, but several European doctrinal positions treat that prior transmission as high risk, which is why we generally recommend basic mode on the French and German markets.

If you choose advanced mode anyway, three precautions apply. Announce the behaviour explicitly in your banner text. Record the decision in writing, with its date and its author. And check that no tag sends user data, even hashed, before consent. A risk taken knowingly and traced is not the same thing as a risk taken blindly.