← All articles
Web & Frontend

Set up Google Analytics 4 with Tag Manager to track signups and sales

Send signups and purchases from Tag Manager to GA4 through dataLayer, mark key events, and check each one in DebugView before you trust a report.

When you finish, a test signup reaches Google Analytics 4 as a key event, and a test order fills the Purchase journey report with numbers you have checked. It takes eight steps in Tag Manager and GA4, plus a day or two before every report fills in. This is part 2 of a three-part series, and part 1 explains how Tag Manager runs code underneath, so this tutorial only uses it.

What you need

  • A GA4 property with a web data stream. The stream’s Measurement ID is the G- code that tells Google which stream a hit belongs to.
  • A Tag Manager web container that you can edit and publish.
  • A test page you can edit, with a signup form and a fake checkout. It must load the container snippet.
  • A way to accept your own cookie banner, if your site has one. GA4’s debug view shows nothing while analytics consent is denied (DebugView help).

You should have pasted a Google Analytics snippet into a site before. You don’t need to know how Tag Manager works inside; part 1 covers that.

How GA4 sees your site

Open your test page, open the browser console, and run this:

window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ event: "sign_up", method: "email" });

Then type dataLayer and press Enter. You’ll see an array with your object at the end. Nothing has reached Google yet, because dataLayer is a plain JavaScript array until a Tag Manager container reads it.

Once Tag Manager forwards it, GA4 stores it as an event, a named record of something that happened. The event carries parameters, the key-value details that come with it, here method: "email". GA4 records everything this way, page views included (automatically collected events).

Three sources of events

Your page sends events from three places. Enhanced measurement is a set of extra events the Google tag sends without code, which you switch on per data stream.

Source Examples Who sends it
Automatically collected first_visit, session_start, user_engagement (page in focus for at least 1 s) The Google tag, always
Enhanced measurement page_view (cannot be turned off), scroll (first time at 90%), click (outbound links only), view_search_results, file_download, form_start, form_submit The Google tag, per the stream’s settings
Your own events sign_up, purchase Your code, through dataLayer and a Tag Manager tag

Sources: automatically collected events and enhanced measurement.

Enhanced measurement already sends form_submit, but that event says a form was submitted. It can’t tell a created account from a submit that your server rejected. That’s why the signup gets its own event. Google’s events reference defines names such as sign_up and purchase, so use those names rather than inventing your own.

Sessions and users are counted from cookies

A session is a group of events from one browser. It starts on a page view when no session is active, ends after 30 minutes without activity (you can change that), and has no maximum length. The session_start event sets a ga_session_id (how sessions work).

A user in GA4 is a _ga cookie, not a person. The cookie lasts two years and holds a client ID, a random identifier for that browser. A second cookie, _ga_<container-id>, holds the session state (GA4 cookies). So one person on a phone and a laptop counts as two users, unless you also send a user_id when they sign in.

Safari makes this worse. It deletes cookies set by script after seven days without interaction with the site (WebKit tracking prevention). So a Safari visitor who returns after eight days can count as a new user. GA4 also estimates user and session counts with HyperLogLog++, usually within 1% of the exact figure (unique count approximation).

Rule: A GA4 user count is a count of cookies, so read it as an estimate of people, never as a head count.

The path one signup takes

Three Tag Manager terms appear in every step. A trigger is a rule that watches the messages pushed to dataLayer. A tag is the code that runs when its trigger matches. A variable reads a value, such as method, out of those messages.

your page code
   |  dataLayer.push({ event: "sign_up", method: "email" })
   v
dataLayer          one array per page, read first in, first out
   |
   v
trigger            Custom Event: event name equals sign_up
   |  fires
   v
GA4 Event tag      event name sign_up, parameter method (from a variable)
   |  sends the hit
   v
GA4 property       DebugView shows it in seconds
   |  processing
   v
reports            key events, custom dimensions, Purchase journey

Pushes that happen before the container loads wait in the array, and the container reads them in order once it starts (the data layer). The steps below build this path from top to bottom.

Step 1: Install Tag Manager and connect it to Google Analytics 4

Why. With one container on every page, each new event is a change in Tag Manager, not a release of your site.

Google changed this setup in 2023 and twice more in late 2026, so older guides show a different first tag (Tag Manager release notes):

  • 2023-09-05: the “GA4 Configuration” tag was renamed “Google tag”.
  • 2026-10-12: destination tags arrived. A destination tag sends data to a Google product, such as GA4, straight from the container without loading gtag.js (destination tags).
  • 2026-11-17: each Google tag becomes a Tag Manager container. Google upgrades installs it doesn’t support in January 2027.

One install is unsupported now. That’s the gtm.js container snippet plus a separate gtag('config', 'G-…') call on the same page (supported setups). So if your page has a hardcoded Google tag, decide which one sends to GA4, and send each hit from one place only.

What to do.

  1. In Tag Manager, copy the container snippets from the install screen and paste them into every page, as the screen tells you.
  2. Open Tags → New. Choose the “Google Analytics” destination tag, or the Google tag type if that’s what your container offers (GA4 setup in Tag Manager).
  3. Enter your Measurement ID, and set the trigger to Initialization – All Pages.
  4. Save, but don’t publish. Step 3 tests everything in Preview first.

What you should see. Nothing changes on the live site yet, because nothing is published.

Step 2: Send a custom sign_up event from your form

Why. The signup is the first action you want to count as success, and only your code knows when an account really exists.

What to do in your code. Push the event in the code that runs after your server confirms the new account, not in the submit button’s click handler. If the form itself needs work, Module 10 of Web Design for Developers covers labels, errors and field sizes.

window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
  event: "sign_up",
  method: "email"
});

The event key is what triggers match on. Any other key, such as method, is data that a variable can read. A push without event only stores values and fires nothing.

What to do in Tag Manager.

  1. Variables → New → Data Layer Variable. Set the name to method and save it as DLV - method.
  2. Triggers → New → Custom Event. Set the event name to sign_up (Custom Event trigger).
  3. Tags → New → “Google Analytics: GA4 Event”. Enter your Measurement ID and the event name sign_up. Add an event parameter named method with the value {{DLV - method}}, and attach the trigger from item 2 (GA4 Event tag).

What you should see. In Preview (step 3), the GA4 Event tag fires once on the sign_up message and on no other message.

Why a .* trigger fires on messages you never pushed

Suppose you want one trigger for every event, so you set the Custom Event trigger’s event name to .* and turn on regex matching. You load the page and push sign_up once.

How many sign_up events does GA4 receive? Make a guess before you read on.

Open Preview and look at the list of messages on the left. Expect something like this, though the labels may differ:

Consent Initialization
Initialization
Page View        (gtm.js)    GA4 Event tag fired
DOM Ready        (gtm.dom)   GA4 Event tag fired
Window Loaded    (gtm.load)  GA4 Event tag fired
sign_up                      GA4 Event tag fired

GA4 receives at least four sign_up events for one signup. The container pushes its own messages into the same dataLayer: gtm.js when it loads, then gtm.dom and gtm.load as the page finishes (trigger types and their order). A .* pattern matches all of them, and the tag sends the fixed name sign_up each time. Since 2026-10-08, each gtag('config') call also appears as a gtag.config message that a wildcard trigger can fire on (release notes).

Rule: In a Custom Event trigger, name the exact event, or anchor the regex to the names you mean, such as ^(sign_up|purchase)$.

Step 3: Check the event in Preview and DebugView

Why. Standard reports update hours later, so a broken tag can collect wrong data for a day before you notice. Preview and DebugView show each hit within seconds.

What to do.

  1. In Tag Manager, click Preview and enter your test page’s URL. Tag Assistant opens the page connected to your unpublished changes (Preview and debug).
  2. Accept your cookie banner, then sign up with a test address.
  3. In Tag Assistant, select the sign_up message. Your GA4 Event tag should be under the tags that fired, with method set to email.
  4. In GA4, open Admin → Data display → DebugView (DebugView). Your device’s timeline should show sign_up; click it to see method.

To confirm the push happened at all, run this in the page’s console:

window.dataLayer.filter((message) => message.event === "sign_up");

What you should see. The console prints an array with one object per sign_up push. If it’s empty, the tag never had anything to fire on, so fix the page code before you touch Tag Manager.

Debug mode is on automatically while Preview runs, and setting debug_mode: false does not turn it off. If DebugView stays empty while Tag Assistant shows the tag firing, check consent first. DebugView shows nothing when analytics consent is denied.

Step 4: Mark sign_up as a key event

Why. A key event is an event you mark as a success for the business. Engaged sessions count it, Source/Medium at event scope is reported for key events only, and you can create Google Ads conversions from key events (key events, engaged sessions, attribution scopes).

Google renamed “conversions” to “key events” on 2024-03-27, so a guide that says “mark as conversion” means this step (the rename).

What to do.

  1. In GA4, open Admin → Data display → Events.
  2. Click the star next to sign_up.
  3. Leave the counting method at Once per event (counting methods).

“Once per event” counts every sign_up, so a person who creates two accounts in one session counts twice. “Once per session” is the older method and would count them once. A change of method applies to future data only, so choose it before the data you care about arrives.

What you should see. The star next to sign_up is filled. purchase is already marked, because GA4 treats it as a key event automatically. A standard property allows 30 key events.

Step 5: Register custom dimensions for the parameters you report on

Why. GA4 receives your method parameter, but standard reports can only break data down by it once you register it as a custom dimension (custom dimensions).

Each custom dimension has a scope, which decides what one value describes:

Scope Comes from Example
Event An event parameter method on sign_up
User A user property A plan name you set for the user
Item A field inside the items array A custom field on each product

What to do.

  1. In GA4, open Admin → Data display → Custom definitions and create a custom dimension.
  2. Name it “Signup method”, choose the Event scope, and enter method as the event parameter.

What you should see. The dimension appears in the list at once, but data for it shows in reports 24 to 48 hours later.

Don’t register an ID, such as an order number or a user ID, as a dimension. Each value is a new row, and once a report passes its row limit, GA4 groups the remaining rows under “(other)” (the (other) row). A standard property allows 50 event-scoped, 25 user-scoped and 10 item-scoped custom dimensions (limits).

Step 6: Send the purchase funnel with GA4 ecommerce tracking

Why. GA4 builds its Purchase journey report from four events in order: view_item, add_to_cart, begin_checkout and purchase, after the session_start that opens the session (Purchase journey). Each needs an items array with the products involved.

What to do in your code. Call one function from each page, and make sure it clears the previous ecommerce data before each push. That’s the pattern in Google’s ecommerce guide for Tag Manager. Tag Manager merges every push into one data model, so without the ecommerce: null push, fields from the last ecommerce object can leak into the next event.

window.dataLayer = window.dataLayer || [];

function trackEcommerce(eventName, ecommerce) {
  window.dataLayer.push({ ecommerce: null }); // clear the previous ecommerce object
  window.dataLayer.push({ event: eventName, ecommerce: ecommerce });
}

const lamp = {
  item_id: "SKU_1001",
  item_name: "Desk lamp",
  price: 25.0,
  quantity: 1
};

// product page
trackEcommerce("view_item", { currency: "USD", value: 25.0, items: [lamp] });

// "Add to cart" button
trackEcommerce("add_to_cart", { currency: "USD", value: 25.0, items: [lamp] });

// first checkout page
trackEcommerce("begin_checkout", { currency: "USD", value: 25.0, items: [lamp] });

// order confirmation page, after payment succeeds
trackEcommerce("purchase", {
  transaction_id: "T-1001",
  currency: "USD",
  value: 25.0,
  tax: 2.0,
  shipping: 5.0,
  items: [lamp]
});

You can run the whole block in the console to test the tags. On a real site, each call goes on the page named in its comment. Notice four rules in the purchase call (events reference, transaction ID):

  • currency is required whenever you send value.
  • value excludes tax and shipping. Those go in their own fields, so the lamp’s value is 25, not 32.
  • transaction_id must be unique per order. GA4 drops a second purchase with the same ID, so a customer who reloads the confirmation page doesn’t double your revenue.
  • An empty transaction_id is worse than none. GA4 merges every purchase with an empty ID into one order.

Each items entry needs an item_id or an item_name, and one event can carry up to 200 items.

What to do in Tag Manager.

  1. Triggers → New → Custom Event. Set the event name to ^(view_item|add_to_cart|begin_checkout|purchase)$ and turn on regex matching. The anchors keep it from matching anything else, as step 2 showed.
  2. Tags → New → GA4 Event tag. Set the event name to {{Event}}, the built-in variable that holds the pushed event’s name.
  3. In the tag, open More Settings → Ecommerce, turn on Send Ecommerce data, and choose Data Layer as the source.
  4. Attach the trigger from item 1.

What you should see. Repeat step 3’s check. Tag Assistant shows the tag firing on each of the four messages. In DebugView, purchase shows its items, value and transaction_id.

Step 7: Send refunds and offline sales with the Measurement Protocol

Why. A refund happens on your server, days after the visitor left. The Measurement Protocol is a GA4 HTTP API for sending events from a server, so GA4 can subtract the refund from purchase revenue (Measurement Protocol). It adds events to your tagging; it doesn’t replace it.

To tie a server event to the browser that bought, you need that browser’s client ID. Tag Manager has had a built-in Client ID variable since 2025-12-11 (release notes). Send it to your server with the order, for example in a hidden form field, and store it next to the order.

What to do.

  1. In GA4, create an API secret, a key that lets your server send events to one data stream. Keep it on the server; anyone with it can send events to your property.
  2. Send the refund to the validation server first. The path starts with /debug/:
curl -s -X POST \
  "https://www.google-analytics.com/debug/mp/collect?measurement_id=$GA_MEASUREMENT_ID&api_secret=$GA_API_SECRET" \
  -H "Content-Type: application/json" \
  -d '{
    "client_id": "123456789.1700000000",
    "events": [{
      "name": "refund",
      "params": {
        "currency": "USD",
        "transaction_id": "T-1001",
        "value": 25.0
      }
    }]
  }'

Set GA_MEASUREMENT_ID and GA_API_SECRET in your shell first, and replace the client ID with the one you stored for order T-1001. A refund without items refunds the whole order; list items to refund part of it (ecommerce guide).

What you should see. The validation server answers with a list of validation messages, and an empty list means the payload passed (sending events). Then send the same request to /mp/collect, without /debug.

Check every new payload this way, because the live endpoint returns a 2xx status even when the payload is wrong. Four more limits from the protocol reference:

  • It can’t start sessions. session_start and first_visit are reserved names.
  • A session_id ties an event to a session only within 24 hours of that session.
  • You can backdate an event by up to 72 hours.
  • One request carries at most 25 events.

Step 8: Read the Purchase journey and Checkout journey reports

Why. These two reports show where buyers stop, which is what you collected the funnel for.

What to do. In GA4, open Reports → Monetization and choose Purchase journey. It shows each step from session_start to purchase, with how many users reached it and how many left. The Checkout journey report shows begin_checkout, add_shipping_info, add_payment_info and purchase (Checkout journey). This tutorial sends only the first and last, so that report stays incomplete until you add the middle two.

What you should see. Your test order appears once daily processing finishes, which takes about 12 hours (data freshness). Revenue shows as three metrics (ecommerce metrics):

  • Gross purchase revenue: the sum of purchase values.
  • Purchase revenue: gross purchase revenue minus refunds.
  • Total revenue: purchase revenue plus ad revenue.

So after step 7, your test order adds 25 to gross purchase revenue and 0 to purchase revenue.

Common errors and fixes

  • The payment gateway shows up as a referral. The buyer leaves for the gateway’s domain and comes back, so the sale is credited to the gateway, not the real source. Add the gateway’s domain under Admin → Data streams → your stream → Configure tag settings → List unwanted referrals, up to 50 entries (unwanted referrals). If you own both domains, set up cross-domain measurement instead.
  • The internal-traffic filter removed data for good. A data filter for your office IP addresses, once active, deletes the matching data permanently (internal traffic). Create it in the Testing state first, check which traffic it matches, and only then make it active.
  • GA4 revenue never matches your books. value excludes tax and shipping by design. Visitors who decline consent send no purchases, and the loss grows with the share who decline (consent). Refunds lower purchase revenue only if you send them as in step 7.
  • A new dimension shows “(not set)”. Daily data takes about 12 hours to process, and a new custom dimension takes 24 to 48 hours. Wait a full day before you treat a blank or “(not set)” row as a bug.
  • DebugView is empty but the tag fires. Analytics consent is denied in that browser. Accept the banner and reload.
  • sign_up counts are several times too high. A Custom Event trigger matches GTM’s own messages. Anchor or narrow it, as in step 2.

Limits, and what to build next

Know these limits before you design more tracking (limits, BigQuery export):

Item Standard property GA4 360
Event-scoped custom dimensions 50 125
User-scoped custom dimensions 25 100
Key events 30 50
Parameters per event 25 100
BigQuery daily export 1 million events 20 billion events

Tag Manager costs page weight. The library is about 33 KB compressed, and the median container about 50 KB; Custom HTML tags carry the most risk (tag best practices, 2021). If you only need the default measurement (automatic and enhanced events), the Google tag alone is enough, and you can skip Tag Manager (when to use Tag Manager).

If your page loads the tag only after the visitor accepts a cookie banner, visitors who decline send nothing at all. GA4 can model some of the missing behavior, but only with advanced consent mode and at least 1,000 consent-denied events a day for seven days (consent and modeling). A loader that waits for consent never sends those events, so the numbers you see come only from visitors who agreed. Module 11 of Web Design for Developers treats analytics the same way, as something that waits for consent.

Next, try a second funnel of your own: send begin_checkout, add_shipping_info, add_payment_info and purchase, and watch the Checkout journey report fill in. Part 3 of this series covers what to measure and how to read acquisition, search keywords from Search Console, retention and A/B tests.

If you want part 3 when it comes out, subscribe to the newsletter.

Comments

No comments yet. Ask a question or share what worked for you.

Leave a comment

Write a comment before you post.

Enter your name.

Never shown on the site.

Enter an email address like name@example.com.

Comments are checked before they appear. Fields marked * are required.

Keep reading

Related articles