Add Google Analytics (GA4) to Magento 2 the easy way
Installing Google Analytics 4 to any site involves a few steps which range from creating an account in GA4 to adding a Javasript snippet in your Magento 2 store. While some can't be skipped, others can be automated by using our ready Google Analytics 4 extension for Magento 2
Nowadays installing and running an analytics tool like Google Analytics 4 ins't that starightforward, except for the cumbersome installation process, you have to take care for GDPR compliance, Google Consent Mode V2 signals, Google Ads remarkering, a complex process of collecting all GA4 events and more.
There are multiple ways to install Google Analytics and the top 3 include:
1. Manual installation via native gtag code
Installing manually involves adding a small piece of Javascript code into your pages like the one shown below:
In this snippet, you should replace G-XXXXXXX with your actual GA4 Property Measurement ID.
2. Installation via Google Tag Manager
Installing via Google Tag Manager requires adding a small Javascript snippet containing a code that loads Google Tag Manager library into your Magento 2 store. From then on, all tracking is done via tags/triggers and variables in Google Tag Manager itself.
In this snippet you should replace GTM-XXXXXXX with your GTM Container ID.
3. By using a third party ready extension for Magento 2
The previous 2 methods are free and easy to implement but all they do is just physical installation of the analytics tools and libraries. Getting GA4 Enhanced Ecommerce data involves a complex process of collecting GA4 events and/or proper dataLayer[] object initialization.
This method involves a ready third party extension for Magento 2 that does the hard job. With our Google Analytics extension for Magento 2 you can install Google Analytics 4 and Google Tag Manager easily and without doing any code and without any developer skills.
We have designed our extension to be powerful, yet easy to use, configure and adjust. It will not only install GA4 and GTM but it will also configure Google Tag Manager automatically, it will collect ALL Google Analytics 4 events and inflate your GA4 Property with accurate reports that can be used for better marketing decisions.
Installing the extension
Installation is based Composer (Composer is a tool for dependency management in PHP) on running 3 commands in your console:
Once modules are installed, you can run: bin/magento setup:upgrade
If all went correctly, you shall see the module installed and will be able to access the configuration screen under Stores / Configuration / Anowave / Google Tag Manager GA4
Configuring extension and Google Tag Manager
The process is fully automated and you can configure Google Tag Manager directly from the extension's configuration screen and within seconds. To do so, go to Stores / Configuration / Anowave / Google Tag Manager GA4 / Google Tag Manager API panel.
In this panel click "Sign in with Google" and authorize the extension with the correct permissions so it can create tags in your Google Tag Manager account. Once done, you will be redirected back to configuration screen. Scroll down to the Google Tag Manager API again and select the checkboxes shown in order to create tags, triggers and variables + Google Tag. When all checked, click Save config.
If all went correctly, you shall get a confirmation that Google Tag Manager is configured correctly. Note that at this point the GTM container is configured but not published. This is for you to do, go to GTM and click Publish.
At this point, the module is fully configured and both Google Analytics 4 and Google Tag Manager installed. Within 24 hours you should start seeing data in your GA4 Property.