Skip to main content

Adding Google Analytics to Magento 2

Victoria Harbour, Hongkong

I already did a tutorial on adding Google Universal Analytics to Magento2. But currently I am not receiving any live analytics from the page. I want to go through the steps again and see if I can find the porblem.

To get started with GA4 first create a Google Mail account, open the GA Admin page and add your property.

Creating a Property

In Admin, look at the Account column to make sure that you've selected the right account. Then, in the Property column, click Create Property. Click Show Advanced Options (below the property-setup fields) and activate Create a Universal Analytics property:

Google Universal Analytics in Magento2

At this point, choose to create Both a Google Analytics 4 property and a Universal Analytics property. This option Sets up a parallel Google Analytics 4 property that collects data alongside your Universal Analytics property. Once you add the tag for the Google Analytics 4 property to your site, data will be sent to both properties.

How to identify each property: If you named your property "Example" in step 2, your Universal Analytics property will be named "Example (G-1234567)" Measurement ID and your Google Analytics 4 property will be named "Example - GA4 (98765432)" Property ID.

Take note of your Property’s Measurement ID:

Google Universal Analytics in Magento2

In the Google Analytics Admin section, click Property Settings for the UA property that you’ve created. Take note of your property’s G4 Property ID.

G-BHJLPFH0S1 280921109

Adding GA4 to Magento2

Magento’s built-in configurations allow you to easily connect to Google Analytics for general eCommerce tracking. Log in to your Magento 2 Admin Dashboard and navigate to:

Stores -> Configuration -> Sales -> Google API

Inside “Google Analytics”, change:

  • Enable to Yes
  • Account Type to Universal Analytics
  • Account Number to your property’s UA Measurement ID (It will be similar to G-XXXXXXXXXX)
  • Anonymize IP and Enable Content Experiments are disabled by default and generally aren’t needed. You may want to refer to Magento’s documentation to consider enabling these options.

Click Save Config and navigate to System -> Tools -> Cache Management and refresh your site cache.

Update Needed my version of Magento2 does not have the field Account Type. That will be the reason why I am not getting tracking from this page beside the Google Search console results. We will have to update Magento and then probably switch to Google Tag Manager.