Marketing

How to set up Google Analytics 4 with Google Tag Manager

Connect your GTM container, then create the GA4 tags in the right order so page views and purchases are counted once.

Where
Settings > Analytics, then Google Tag Manager
Time needed
About 30 minutes
You need
A GTM container ID and a GA4 Measurement ID
Safe to try
Preview mode tests everything before you publish

Google Tag Manager (GTM) lets you send your store's shopping activity to Google Analytics 4 (GA4) without touching any code. Matjr already pushes all the shopping events to GTM for you. You only need to connect your container and create a few tags. This guide shows the exact steps and the one mistake that doubles your page views.

Before you start

  • A Google account with access to Google Tag Manager and Google Analytics.
  • A GA4 property with a web data stream. Copy its Measurement ID, which looks like G-XXXXXXXXXX.
  • A GTM web container. Copy its ID, which looks like GTM-XXXXXXX.
  • About 30 minutes.

What your store sends to GTM

Your store sends these events to the GTM data layer, using the standard GA4 ecommerce format. The currency is your store currency (EGP, AED or BHD).

  • page_view: on every page, including when a shopper moves between pages without a full reload.
  • view_item, view_item_list, select_item: product and list browsing.
  • add_to_cart, remove_from_cart, view_cart: cart activity.
  • begin_checkout, add_shipping_info, add_payment_info, purchase: checkout steps and the order.
  • add_to_wishlist, search, sign_up, login: other shopper actions.
  • generate_lead: a newsletter signup.

The purchase value does not include shipping. Shipping is sent in its own field.

Step 1: Connect your GTM container to your store

  1. In Matjr, open Settings then Analytics.
  2. Paste your container ID (for example GTM-ABC1234) in Google Tag Manager ID.
  3. Save. Your store now loads this container on every page.

Important: do not use the default All Pages setup

Your store is a single-page app and it sends its own page_view event. If your GA4 tag also sends an automatic page view on All Pages or Initialization - All Pages, every visit is counted twice. Follow the setup below exactly.

Step 2: Create the Google tag without automatic page views

  1. In GTM, open Tags then New.
  2. Choose tag type Google tag.
  3. In Tag ID, enter your GA4 Measurement ID (G-XXXXXXXXXX).
  4. Open Configuration settings then Add parameter. Set the name to send_page_view and the value to false.
  5. Under Triggering, choose Initialization - All Pages. This is fine for this tag only, because it no longer sends page views.
  6. Name the tag GA4 - Google tag and save.

Step 3: Send page views from your store's own event

  1. Open Triggers then New. Choose Custom Event. Set Event name to page_view. Leave This trigger fires on as All Custom Events. Name it CE - page_view and save.
  2. Open Tags then New. Choose Google Analytics: GA4 Event.
  3. In Measurement ID, enter your G-XXXXXXXXXX ID.
  4. Set Event Name to page_view.
  5. Under Triggering, choose CE - page_view.
  6. Name the tag GA4 - page_view and save.

Step 4: Send the shopping events

  1. Open Triggers then New. Choose Custom Event.
  2. Set Event name to the line below, and tick Use regex matching:
    view_item|view_item_list|select_item|add_to_cart|remove_from_cart|view_cart|begin_checkout|add_shipping_info|add_payment_info|purchase|add_to_wishlist
  3. Name it CE - ecommerce events and save.
  4. Open Tags then New. Choose Google Analytics: GA4 Event.
  5. Enter your Measurement ID. Set Event Name to {{Event}}.
  6. Open More Settings then Ecommerce. Tick Send Ecommerce data and set Data source to Data Layer.
  7. Under Triggering, choose CE - ecommerce events.
  8. Name the tag GA4 - ecommerce and save.

Step 5: Send search, signup, login and newsletter events

Repeat Step 4 with a second trigger and a second tag. Use the regex search|sign_up|login|generate_lead as the event name, with Event Name set to {{Event}}. You do not need to tick Send Ecommerce data for these.

Step 6: Test before you publish

  1. In GTM, click Preview and enter your store address. Tag Assistant opens your store.
  2. Browse a product, add it to the cart and place a test order. In Tag Assistant, check that each event appears once and that the GA4 tags show Tags Fired.
  3. Check that page_view fires once per page, not twice.
  4. In GA4, open Admin then DebugView. You should see the same events arrive. Confirm purchase appears once per order, with the right value and currency.
  5. When everything looks right, click Submit in GTM, then Publish.

If you turn on Ask visitors for cookie consent in Settings then Analytics, your store still loads GTM on every page and still pushes all events to the dataLayer. Before GTM loads, your store sets the four Google Consent Mode v2 signals (ad_storage, analytics_storage, ad_user_data, ad_personalization) to denied. They change to granted when the shopper accepts, and stay denied if the shopper declines or has not chosen yet.

Google tags that respect Consent Mode, including the GA4 Google tag by default, then run without cookies until the shopper accepts. GA4 receives cookieless pings and may show modelled, lower numbers than your real traffic. Tags that do not support Consent Mode, such as custom HTML or third-party tags, need your own check. In the tag's Advanced Settings, open Consent Settings and add Additional consent checks that require analytics_storage or ad_storage.

Meta Pixel is different. It has its own field in Matjr and is held completely until the shopper accepts.

Do not add Meta Pixel in GTM

Meta Pixel has its own field in Settings then Analytics. Do not also add it as a tag in GTM, or every event is counted twice.

Common problems

  • Page views are double. Your Google tag still sends page views. Check that send_page_view is false, and that no other tag uses All Pages to send page_view.
  • No events in GA4. Check that the container ID in Matjr matches the container you are editing, and that you clicked Publish in GTM.
  • Consent and Preview. In Preview, events appear before the shopper accepts. Open the Consent tab in Tag Assistant to see whether each signal is denied or granted.
  • Revenue looks lower than your sales. Purchase value excludes shipping, and visitors who have not accepted cookies may be counted with modelled or lower numbers.

Frequently asked questions

Why are my page views doubled in GA4?

Your Google tag is sending automatic page views while your store also sends its own page_view event. Set send_page_view to false in the Google tag and send page_view only from a Custom Event trigger.

Do I add Meta Pixel in Google Tag Manager?

No. Meta Pixel has its own field in Settings > Analytics. Adding it in GTM as well counts every event twice.

Does GTM still work if I ask for cookie consent?

Yes. GTM loads on every page and events are always pushed. Google Consent Mode v2 starts as denied and becomes granted when the shopper accepts. Tags that respect Consent Mode, like the GA4 Google tag, run without cookies until then, so GA4 may show lower or modelled numbers. Meta Pixel is held until the shopper accepts.

Does the purchase value include shipping?

No. The purchase value excludes shipping. Shipping is sent in its own field.

Try it on your own store

Start your free trial. No credit card required.

Get Started