Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

How to Add Google Analytics to Your Magento Store

This guide shows how to connect Google Analytics to Magento, so you can see how many people visit your shop.

Domains and DNS2 min read21 steps

What is Google Analytics?

Google Analytics is a free tool from Google. It counts visitors on your website and shows where they come from and what they look at. Magento is a program used to run online shops.

The current version of Google Analytics is called GA4. It gives you a Measurement ID that starts with G-. This ID tells Google which site the numbers belong to.

Step 1: Get your Measurement ID

  1. Sign in to Google Analytics with your Google account.
  2. Click Admin (the gear icon).
  3. Create an account and a property for your store, if you do not have one.
  4. Under Data collection, choose Data streams.
  5. Add a Web stream and type your store address.
  6. Copy the Measurement ID, such as G-XXXXXXXXXX.

Step 2: Add it in Magento

Magento 2 has a built-in Google Analytics setting. Newer versions may use the Google Tag Manager or an extension for GA4.

  1. Log in to your Magento admin panel.
  2. Click Stores in the left menu, then Configuration.
  3. Open Sales and choose Google API.
  4. Open the Google Analytics section.
  5. Set Enable to Yes.
  6. Paste your Measurement ID in the account box.
  7. Click Save Config.
  8. Go to System, then Cache Management, and click Flush Magento Cache.

If your Magento version has no GA4 option, add the tracking code another way:

  1. Go to Content, then Design, then Configuration.
  2. Edit your store view and open HTML Head.
  3. Paste the Google tag code in Scripts and Style Sheets.
  4. Click Save Configuration and flush the cache.

Back up your store before you paste code. A typing error can break the page.

Step 3: Check it works

  1. Open your store in another browser tab.
  2. In Google Analytics, open Reports and then Realtime.
  3. You should see yourself as a visitor within a minute or two.

If nothing shows

  • Check the Measurement ID for typing mistakes.
  • Flush the cache again.
  • Turn off ad blockers when testing.
Tip: Menu names can change between Magento versions. Need help? Open a ticket at https://secure.hostvento.com/submitticket.php.

Quick recap

  • Create a GA4 property and copy the Measurement ID.
  • In Magento, go to Stores, Configuration, Sales, Google API.
  • Enable Analytics, paste the ID, save and flush the cache.
  • Check Realtime in Google Analytics.