How to Set Up GA4 and Google Tag Manager for a SaaS App

A practical GA4 and Google Tag Manager setup for a new SaaS app: installing the container, tracking signups and purchases, testing, and avoiding common mistakes.

How to Set Up GA4 and Google Tag Manager for a SaaS App
Listen to this post 7 min

Analytics is my day job. I have spent over twenty years in digital marketing analytics and conversion work, and these days I run GA4 and Google Tag Manager setups for a large company. I also set up the same tools on my own small apps.

The setup for a new SaaS app is much smaller than an enterprise one, but the same mistakes show up at both sizes. This guide is the version I would want a founder to follow on day one.

Why use Google Tag Manager at all

You can paste the GA4 tag straight into your app. For a tiny site, that is fine. I still recommend Google Tag Manager (GTM) for a SaaS app because:

  • You can add or change tracking without asking your AI builder to edit code each time.
  • You can add other tags later (ad platforms, heatmaps) from one place.
  • Preview mode shows you exactly what fires and when, which makes testing much easier.

Step 1: Create your accounts

  1. In Google Analytics, create a GA4 property and a web data stream for your domain. Copy the Measurement ID. It starts with G-.
  2. In Google Tag Manager, create a container for your domain (type: Web). Copy the container ID. It starts with GTM-.

Step 2: Install the GTM container

GTM gives you two snippets: one for the head of the page and one right after the opening body tag. In a Lovable or other React app, these go in the main index.html file so they load on every page.

A prompt that works:

Add the Google Tag Manager container GTM-XXXXXXX to index.html.
Put the script snippet in the head and the noscript iframe right
after the opening body tag. Do not add any other analytics code.

That last sentence matters. AI tools sometimes helpfully add a second GA4 tag on their own, and then every page view gets counted twice.

Step 3: Add the GA4 tag in GTM

In GTM, create a new tag:

  • Tag type: Google Tag
  • Tag ID: your G- Measurement ID
  • Trigger: Initialization, All Pages

Save it, but do not publish yet.

Step 4: Handle page views in a single page app

Most AI-built apps are single page apps. The browser loads once, and moving between screens changes the URL without a full page load. If you do nothing, GA4 might only count the first page.

GA4 has a setting for this. In your data stream, open Enhanced Measurement, open the Page views settings, and make sure "Page changes based on browser history events" is on. For most React apps, that handles it.

Test it (Step 8) by clicking through several screens and confirming each one shows up as a page view.

Step 5: Decide which events matter

Do not track everything. Track the handful of actions that tell you whether your business is working. For a typical SaaS app, that list is short:

  1. sign_up: a new account was created
  2. login: a returning user signed in
  3. Your core action: the one thing users come to do (for example, project_created)
  4. begin_checkout: user clicked to upgrade
  5. purchase: payment completed

Where Google has a recommended event name (like sign_up, login, begin_checkout, and purchase), use it. GA4 understands those names and treats them better in reports.

Step 6: Push events to the data layer

The cleanest way to send these events is to have your app push them into the data layer, and let GTM pick them up. Prompt your builder like this:

When a user successfully signs up, push this to the data layer:
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ event: 'sign_up', method: 'email' });
Only push after the account is actually created, not on button click.

That last line is important. Firing on button click counts failed attempts as signups. Fire on success.

Then in GTM, for each event:

  1. Create a trigger: type Custom Event, event name sign_up.
  2. Create a tag: type Google Analytics: GA4 Event, your Measurement ID, event name sign_up, and add any parameters (like method).
  3. Attach the trigger to the tag.

Step 7: Track purchases correctly

If you use Stripe Checkout, the payment happens on Stripe's page, not yours. You cannot put tags there. You have two options:

  • Simple: Fire purchase on your success page. Pass the value and currency. Only fire it once, even if the user refreshes the page.
  • More accurate: Send the purchase from your server when the Stripe webhook confirms payment, using GA4's Measurement Protocol. This catches purchases even if the user closes the browser before the success page loads.

Start with the simple version. Move to the server version when the numbers start mattering for decisions.

One more thing: when users return from Stripe, GA4 may record checkout.stripe.com as a new referral source, which breaks your attribution. In your GA4 data stream settings, under the tag settings, add Stripe's checkout domain to the list of unwanted referrals.

Step 8: Test everything before you publish

Click Preview in GTM. It opens your site with Tag Assistant connected. Then:

  1. Click through several pages and confirm page views fire on each.
  2. Sign up with a test account and confirm sign_up fires once.
  3. Do your core action and confirm it fires.
  4. Run a test checkout and confirm purchase fires once with the right value.

At the same time, open GA4's DebugView (under Admin) to see events arrive. When everything looks right, publish the GTM container with a clear version name like "Initial GA4 setup."

Step 9: Settings people forget

  • Mark key events. In GA4, mark sign_up and purchase as key events so they show up as conversions in reports.
  • Data retention. GA4 defaults to a short retention period for detailed data. In Admin, under Data retention, change it to the longest option available.
  • Filter your own traffic. Define internal traffic by your IP address and activate the filter, so your testing does not inflate the numbers.
  • No personal data. Never send email addresses, names, or phone numbers to GA4. It is against Google's terms and creates privacy problems. A user ID from your database is fine if you need one.
  • Consent. Depending on where your users are, you may need a consent banner and Google's consent mode. If you have users in regions with strict privacy laws, look into this before launch.

What to look at after launch

For the first month, I watch a short list:

  • Signups per week, by traffic source
  • Percent of signups who complete the core action
  • Percent of active users who start checkout, and who finish it

You can build this as a funnel exploration in GA4 in a few minutes. Those three numbers tell you more about your product than any dashboard full of charts.

If you want me to look over your tracking setup before launch, a 1:1 office hour is a good fit for that.

Was this post helpful?
R
Robert Dixon
Founder of NoCode Outlaws. Ships SaaS with Lovable, Supabase and Stripe, and teaches founders to do the same in live cohorts.
Build with us. Free account gets the starter course and the weekly build notes.
Start free
See the next cohort

Send Feedback

What would you like to share?