Skip to main content

Google Tag Manager and Google Analytics 4

Set up Google Analytics 4 and Tag Manager to measure events and conversions

Sandra Álvarez avatar
Written by Sandra Álvarez
Updated today

Measure what really matters on your website. Connecting Google Analytics 4 (GA4) with Tag Manager not only lets you collect data — it also helps you understand how users interact with your site, what actions they take, and how to improve their experience. This gives you key insights to make smarter decisions and increase your conversions.

What you need before getting started

  • An active Google Tag Manager (GTM) account to manage tags, triggers, and variables.

  • A Google Analytics 4 account to collect and analyze data.

👉 Pro tip: Before creating anything new in Tag Manager, check if you already have duplicate or unused tags, triggers, or variables. These can interfere with proper data collection.


Step-by-step: Basic setup

1. Create the “GA4 Constant” variable

Go to the Variables section in Tag Manager.

Click New → Constant Variable.

In the Value field, enter your GA4 Measurement ID (example: G-XXXXXXXXXX).

Name the variable “GA4 Constant” and save.

2. Set up the GA4 tag

Go to Tags → New → Google Analytics: GA4 Configuration.

Select your measurement ID variable (“GA4 Constant”).

Add All Pages as the trigger.

Name the tag (“GA4 – Your Company Name”) and save.


Key variables for eCommerce

To properly track eCommerce events, you’ll need to create several variables in GTM:

  • GA4 – Ecommerce Items → ecommerce.items

  • GA4 – Ecommerce Coupon → ecommerce.coupon

  • GA4 – Ecommerce Currency → ecommerce.currency

  • GA4 – Ecommerce Transaction ID → ecommerce.transaction_id

  • GA4 – Ecommerce Value → ecommerce.value

  • accomodationID → accomodationID (note: it must be written with double “m”)

  • initCheckoutBookingPrice → initCheckoutBookingPrice

  • currency, locality, lowestPrice, promotionalCode, propertyName, transactionID, value

⚠️ Attention to detail: Use the exact names, even if they contain typos (e.g., “accomodationID”). Otherwise, the code will not work.


Setting up key events

Event “Add to cart”

Custom script in a Custom HTML tag.
Trigger: Custom event named initiateCheckout.
Tag: GA4 Event named add_to_cart, connected with the variable GA4 – Ecommerce Items.

Event “Item view”

Custom script that tracks when an accommodation is viewed.
Trigger: Custom event named viewAccomodationDetail.
Tag: GA4 Event named view_item.

Event “Purchase”

Custom script that records the purchase.
Trigger: Custom event named confirmBookingAccomodation.
Tag: GA4 Event named purchase, including parameters such as transaction_id, value, currency, coupon, and items.

👉 Best practice: Make sure each tag is linked to a unique trigger and that there are no duplicates.


Additional GA4 settings

Data retention: Go to Admin → Data Settings and change retention from 2 to 14 months.

Data collection: Enable Google Signals and granular location/device data collection.

Enhanced measurement: Enable the option in your data stream.

Site search tracking: Add the parameter FRMNombre in advanced settings to track search terms as the search_term event.


Quick checklist

Before finishing your setup, make sure you have:

  • Created all necessary variables.

  • Verified that names match exactly.

  • Checked for duplicate or outdated tags.

  • Tested in Preview Mode in Tag Manager to confirm that events fire correctly.


Frequently Asked Questions

What happens if I misspell a variable name?
The event won’t trigger, and no data will be sent to GA4. It’s crucial to use the exact names.

Can I use this setup on any website?
Yes, as long as your website has Google Tag Manager implemented and a GA4 property.

How can I check if the events work?
Use Preview Mode in GTM and review the Real-Time Events report in GA4.

Is it mandatory to set data retention to 14 months?
No, but it’s highly recommended to maintain a longer history and make decisions based on real trends.

What should I do if I already had previous tags in my GTM?
Check if they are duplicated or unused. If they interfere, delete them before configuring the new ones.


Conclusion

Setting up Google Analytics 4 with Tag Manager may seem technical at first, but once you master it, it opens up a world of insights about your users and your business. With events properly implemented, you’ll have reliable data to refine your strategy and boost your conversions.

👉 Next step: Activate Preview Mode in Tag Manager and check that each event fires correctly. This will let you validate the setup before publishing it.

Did this answer your question?