3

I want to configure Google Analytics 4 in my Magento 2.4.4-p2 version.

Is there any way to configure it in Magento 2.4.4-p2?

I know Magento already provides this functionality in 2.4.6 but I want to configure it in 2.4.4-p2.

Here is the script for Google Analytics:

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-DNJN1PF3CS"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'G-XXXXXXX');
</script>

I'm looking for this type of script for Google Analytics 4

I don't want to use 3rd party Extension, Also I review the Magento2.4.6 code and Found There is New Module Magento_GoogleGtag For Google Analytics 4.

4 Answers 4

1

There is a free module available by Yireo that supports Google Analytics 4. It supports versions 2.3.7 or higher and 2.4.1 or higher.

This module is a great module and highly recommended by the Magento community. You can take a look at: https://github.com/yireo/Yireo_GoogleTagManager2

2
  • I don't want to use 3rd Party module I have updated the answer can you please check. ? Commented Jun 20, 2023 at 12:40
  • @RonakRathod I didn't need to add GA4 manually like what you mentioned. However, I still strongly recommend using Yireo Google Tag Manager for several reasons. Firstly, it was developed by a Magento master with high-quality code. Secondly, it has contributions from well-known contributors in the Magento community. Thirdly, since it is open source and available on GitHub, you can view their code directly.
    – Tu Van
    Commented Jun 20, 2023 at 15:04
1

As you may already be aware, Magento provides Google Analytics 4 integration starting from Magento 2.4.6. However, there are two ways to achieve this

integration:

Recommended method:

  1. Utilize a third-party extension that is available for all Magento extensions. Personally, I use the WeltPixel GA4 extension, which can be found at the following link: https://www.weltpixel.com/google-analytics-enhanced-ecommerce-tag-manager-magento-2.html

Not Recommended method:

  1. Extract the extension code from the vendor folder of Magento 2.4.6 and place it in your Magento setup's app/code directory, ensuring that you include the required libraries.

To identify the necessary libraries and basic requirements, refer to the composer.json file of the Magento Google Analytics extension.

I hope this clarifies the steps required for integrating Google Analytics 4 into Magento 2.4.4

4
  • I don't want to use 3rd Party module I have updated the answer can you please check. ? Commented Jun 20, 2023 at 12:40
  • @RonakRathod then try second method from my answer, I think that will works for you. Commented Jun 20, 2023 at 12:42
  • Yes try this but there is one option that is missing "Enable Content Experiments" and that field is rendered on "Magento_GoogleOptimizer" module so there is a chance to miss something. Commented Jun 20, 2023 at 12:53
  • @RonakRathod You need to take below modules, Magento_GoogleAdwords, Magento_GoogleAnalytics, Magento_GoogleGtag, Magento_GoogleOptimizer Commented Jun 20, 2023 at 12:59
1

I checked and found it on the Google Analytics Platform just i need to add this script to Every page

<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-XXXXXXXXXX');
</script>

enter image description here

1
1

Although Magento does provide the GA4 functionality it's not that extended. You still need to connect GTM separately and create all the events there.

So I'd recommend using the ready-made Magefan GTM Extension for Magento. It come switch the pre-built GTM tags, triggers and variables. All you need is just tweak a few options and the import the generated JSON file to your GTM account.

It's super easy to install and use. Here's the commands you can use to install it:

composer require magefan/module-google-tag-manager
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.