Yireo - Developer training

Open main menu
GoogleTagManager 2

Magento 2 Extension

GoogleTagManager 2

Add GTM to Magento including e-commerce dataLayer and FPC

  • 100% open source and well-written
  • compliant with modern Magento standards
  • Free with no strings attached
  • Community collaboration via GitHub

Latest release: 3.1.0

Jisse Reitsma

This extension has been created by Jisse Reitsma

This extension has been written - with love - by Jisse Reitsma, founder of Yireo, three times Magento Master, partner of ExtDN, trainer and author. Jisse has been in the Magento ecosystem for many years and has created numerous Magento extensions. He also has been pushing better coding practices, like CI/CD, clean coding, coding standards and testing.

Packages & pricing

This extension is hosted on GitHub:

Usage after installation


Login to your Google Tag Manager account. Follow the Google instructions to create a new Google Tag Manager container. Extract the Container Public ID from your new container. Configure your new ID in Magento through Admin Panel> Stores> Configuration> Yireo> Yireo GoogleTagManager.


The extension has the following configuration options:

  • Enabled: When this is set to No, the extension does not work.
  • Container Public ID: The ID of your Google Tags container (starting with GTM-).
  • Debug: Enable this for additional debugging in a logfile and the browser console.
  • Debug Clicks: Enable this for additional debugging when clicking on specific links.
  • Maximum Products in Category: Instead of listing all products on a specific category page, only list the first products.
  • Product EAV Attributes: Product attributes to include when listing products in a specific event.
  • Category EAV Attributes: Category attributes to include when listing categories in a specific event.
  • Customer EAV Attributes: Customer attributes to include when listing customers in a specific event. Currently this is not implemented fully because of privacy regulations.

Tip: Browser extension

Use the DataLayer Checker for Chrome to easily see what kind of data is sent from Magento to Google Tag Manager.

Tip: CheckoutTester2

When you want to track conversions in your Magento checkout, our extension helps out as well: It adds the relevant information to all your checkout and cart pages. Do you want to know which variables are on the success page? Use the Yireo CheckoutTester extension to preview that page and view its HTML source.

Bring your towel.

Quick Start

Get up and running with your Yireo extension

Installation via composer URL

We recommend to install Magento 2 extensions via composer. See the Composer project for instructions on how to get composer up and running. Once composer is installed, use the following command to install our extension.

composer require yireo/magento2-googletagmanager2

This will make composer download the package from Packagist. After the composer installation has finished, use the following commands to enable the module within Magento:

bin/magento module:enable Yireo_GoogleTagManager2
bin/magento cache:clean
bin/magento setup:upgrade

After these commands, the extension is ready for use in Magento. If you were already logged into the Magento Admin Panel, make sure to logout and log back in again, before proceeding. Do not forget to grab yourself a manual copy of our extension as a backup.

Manual installation

Please note that we strongly recommend using composer instead. If you bump into issues with this manual procedure, the first thing we need to ask is whether you have installed all dependencies, as mentioned in the composer.json file of this extension. If the composer.json file of this extension mentions requirements, you need to fulfill these requirements. This could involve checking for PHP requirements but also installing third party add-ons. Sounds difficult? Yes! That's why we can only recommend you to use composer. The manual installation does NOT make your life easier, even if you think it does.

Do use composer: It allows for dependency tracking and in the end, prevents breaking your site. However, in some cases, it might be required to do a non-composer installation. For these exceptional situations, download the module ZIP from our site (under the tab File Downloads). Next, create a folder with the following name and copy to the ZIP contents to it:


After the files have been uploaded, confirm that all files are in place. For instance, you should have a file like app/code/Yireo/GoogleTagManager2/etc/module.xml. Next, use the following commands to enable the module within Magento:

bin/magento module:enable Yireo_GoogleTagManager2
bin/magento cache:clean
bin/magento setup:upgrade

After these commands, the extension is ready for use in Magento. If you were already logged into the Magento Admin Panel, make sure to logout and log back in again, before proceeding. Do not forget to grab yourself a manual copy of our extension as a backup.


Head over to the GitHub repository for downloads: https://github.com/yireo/Yireo_GoogleTagManager2

Frequently Asked Questions

Yes. The community of Hyvä has created a Hyvä compatibility module for our Yireo GoogleTagManager2 module. See the compatibity project for details on the module.

No, it is not. As a policy, all our Yireo software is unencrypted - we do not make use of technologies like ionCube or ZendOptimizer. All PHP-code is open source, but for commercial extensions the code is only given to paying customers.

You probably would like to know if this extension is working under a specific Magento version 2.X.Y. However, from a technical point of view, the question is wrong: The major Magento version 2.X.Y is not semantical but instead used for marketing purposes. It doesn't give any guarantees.

Instead, we maintain compatibility with the actual modules that lie underneath (like Magento_Catalog or the Magento Framework). And version management for these dependencies is handled via composer. We strongly advice you to rely on composer to answer the question whether our extension works under a specific Magento version. This is the only way to guarantee compatibility in a professional way.

Alternatively, study our CHANGELOG for details on the progress we made.

This extension is offered for free. Feel free to go the GitHub repository (see the link under Quick Start> Downloads) and open an Issue there. Please note that this is a voluntary open source project. The more helpful you are in describing the issue at hand, the more likely volunteers can come in to help you with the issue.

Yes, this extension ships with native JavaScript code that works with Hyvä. Additionally, the module ships with Hyvä-specific XML layout handles. Note that this applies to the Yireo GoogleTagManager2 version 3. With version 2, you will still need the compatibility module.

Currently, Luma-based checkouts work without an issue, but for using the React-based checkout or the MageWire-based checkout, more work is needed.

Yes, version 3 does. Version 2 is no longer maintained, but you could use the following composer patch with vaimo/composer-patches: bash { "patches": { "yireo/magento2-googletagmanager2": { "Fix PHP 8.2 error": { "source": "https://patch-diff.githubusercontent.com/raw/yireo/Yireo_GoogleTagManager2/pull/136.diff", "link": "https://github.com/yireo/Yireo_GoogleTagManager2/pull/136", "level": 1 } } } }

Make sure that both Google Analytics and Google Tag Manager are properly configured. See our tutorial for additional guidance. Make sure the module settings in Magento are properly configured: The flag Enabled sets to be set to Yes. The Container Public ID needs to start with GTM- (unless you are testing in the Developer Mode). Optionally debugging can be enabled, which should print various messages in the Console of your browser. Refresh all Magento caches. Within the Network tab of your browsers Developer Tools, you should be able to see an outgoing request to https://www.googletagmanager.com/.

Sometimes it is reported to us that with our module, revenue does not show up properly in the GA panel. With all reports so far, this turned out to be an incorrect revenue setting in GA panel, instead of something related to this Magento module. Note that the responsibility of this module is to deliver a purchase event. If that purchase event is showing in GA properly, then the job of this module is done. However, it is the responsibility of GA to calculate the right revenue from all purchases.

The main methodology for this module to generate its Data Layer by using the XML layout. The block with name yireo_googletagmanager2.data-layer contains a data-layer argument that could be modified and extended with other XML layout files.

A separate class \Yireo\GoogleTagManager2\DataLayer\Mapper\ProductDataMapper is used to supply the fields per product impression dynamically. You can create a DI plugin to intercept the return value of the method mapByProduct() (by creating a DI plugin method afterMapByProduct()): Each entry in the returned array has a key that refers to the data property of the product (EAV attribute) and a value that refers to the Data Layer field (or impressionField).

For example, you could declare a DI plugin within your own di.xml, create a DI plugin class and use a method like the following: php public function afterMapByProduct(ProductDataMapper $productDataMapper, array $productData, ProductInterface $product): array { $productData['foo'] = 'bar'; return $productData; }


Getting support

If you run into problems, we are happy to help you out with the following resources:

  • Check FAQ on this page
  • See our Quick Start on this page
  • Open an Issue in the GitHub repository
    • Be as descriptive in your issue as possible
    • Do everything you can to troubleshoot the issue yourself
    • Understand that you are asking others to give up their free time

We usually respond in 24 hours but understand this is all done on a voluntary basis. Also note that we require you to collaborate together with us. Interpret errors as best as you can, before claiming our time. Free software does not automatically lead into free support as well.


Unit testing

This extension ships with PHPUnit tests. The generic PHPUnit configuration in Magento 2 will pick up on these tests. To only test Yireo extensions, simply run PHPUnit from within this folder. Note that this assumes that the extension is installed via composer. For instance:


Also note that Mockery (mockery/mockery) is used for the integration tests. If you want to test this module, you need to install its dev-dependencies:

composer require yireo/magento2-googletagmanager2 --dev

The JavaScript code ships with MochaJS unit tests. To install the stuff, simply run (within this extension directory) the following:

npm install
npm run mocha

Or just use yarn:

npm run mocha

Supported Magento versions

  • 2.2 (2.2.5, 2.2.6, 2.2.7, 2.2.8, 2.2.9, 2.2.10)
  • 2.3 (2.3.2, 2.3.3, 2.3.4, 2.3.5, 2.3.5-p1, 2.3.5-p2, 2.3.6, 2.3.7, 2.3.7-p1, 2.3.7-p2)
  • 2.4 (2.4.0, 2.4.1, 2.4.2, 2.4.2-p1, 2.4.2-p2, 2.4.3, 2.4.4, 2.4.5)
The supported PHP versions equal the versions supported by Magento itself

Requirement details

  • magento/framework: ^102.0 || ^103.0
  • magento/module-backend: ^100.0 || ^101.0 || ^102.0
  • magento/module-catalog: ^100.0 || ^101.0 || ^102.0 || ^103.0 || ^104.0
  • magento/module-checkout: ^100.1
  • magento/module-config: ^100.0 || ^101.0
  • magento/module-cookie: ^100.0
  • magento/module-customer: ^100.0 || ^101.0 || ^102.0 || ^103.0
  • magento/module-eav: ^100.0 || ^101.0 || ^102.0
  • magento/module-quote: ^101.0
  • magento/module-sales: ^100.0 || ^101.0 || ^102.0 || ^103.0
  • magento/module-store: ^100.0 || ^101.0
  • psr/log: ^1.0
  • php: ^7.4|^8.1
  • ext-json: *
  • ext-pcre: *


All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.


[3.1.0] - 19 March 2023

  • Fix undeclared $scopeConfig in PHP 8.2
  • Add additional magento_sku and magento_id to products

[3.0.18] - 17 March 2023

  • Fix Invisible Cart Items #131 (@stijntrinos)

[3.0.17] - 14 March 2023

  • Better fix for product edit pages

[3.0.16] - 13 March 2023

  • Cast prices to float in orders and order items #133 (@lfolco)
  • Also support product edit pages
  • Optimise GetProductsFromCategoryBlockPlugin #135

[3.0.15] - 7 March 2023

  • Prevent unknown $html argument in plugin to cause Fatal Error, not reported here, not duplicated

[3.0.14] - 28 February 2023

  • Use tax config for prices in cart/order events #129 (@samicoman)
  • Return prices as numbers instead of strings #128 (@samicoman)

[3.0.13] - 21 February 2023

  • Make sure array does not get converted to string #125
  • Removed duplicate IFRAME #126 (@elioermini)

[3.0.12] - 14 February 2023

  • Use Magento\Checkout\Model\Cart instead of CartInterface #122

[3.0.11] - 14 February 2023

  • Use core method instead of custom filter #123 (@sprankhub)
  • Prevent duplication of items in the view_item_list event #119 (@samicoman)

[3.0.10] - 31 January 2023

  • Prevent TypeError with final price #120

[3.0.9] - 20 January 2023

  • Fix purchase event
  • Prevent duplication of items in the purchase event when configurable product were ordered (@samicoman)

[3.0.8] - 16 January 2023

  • Prevent failure when no eav attribute set in the config #117 (@samicoman)

[3.0.7] - 13 January 2023

  • Use sku instead of id as item_id #114 (@samicoman)
  • Properly format product price #114 (@samicoman)
  • Add categories per product #114 (@samicoman)
  • Make sure to calculate value with right price in cart events #115 (@samicoman)
  • Handle configurable products in purchase event #116 (@samicoman)

[3.0.6] - 31 December 2022

  • Prevent reloading order per order-item

[3.0.5] - 21 December 2022

  • Render debugging block only if available

[3.0.4] - 17 December 2022

  • Finalize product clicks for Hyva
  • Fix typo in payment validator

[3.0.3] - 13 December 2022

  • Hyva event handling

[3.0.2] - 13 December 2022

  • Basic compatibility with Hyva

[3.0.1] - 13 December 2022

  • Backend model prevents saving container ID

[3.0.0] - 12 December 2022

  • GA4 support
  • Removed GA4/UA/EE support
  • Extensibility via XML layout
  • Support for EAV attributes of products and categories
  • Click events
  • Cart & checkout events
  • Integration Tests

[2.1.8] - 1 July 2022

  • Update ecommerce attributes #95 (@BorisovskiP)

[2.1.7] - 31 March 2022

  • Prevent adding quote data to success page #91
  • Add additional field for ecommerce push #93 (@sprankhub)
  • Prevent adding quote data to success page #91
  • Add additional field for ecommerce push #93 (@sprankhub)

[2.1.7] - 31 March 2022

  • Prevent adding quote data to success page #91
  • Add additional field for ecommerce push #93 (@sprankhub)

[2.1.6] - 23 March 2022

  • Add ecommerce push on checkout success #90 (@sprankhub)

[2.1.5] - 21 March 2022

  • Fix Duplicate Product Tracking #88 (@sprankhub)
  • Add parent SKU #89 (@sprankhub)

[2.1.4] - 17 February 2022


Fix duplicate product loading #85 (@sprankhub)

[2.1.3] - 23 September 2021

  • Prevent Fatal Error with Amasty_Xlanding

[2.1.2] - 29 July 2021

  • Fix error on cart configure page (@Irinina)

[2.1.1] - 10 July 2021

  • Make sure \Yireo\GoogleTagManager2\ViewModel\Product::getProductPrice() always returns float

[2.1.0] - 10 July 2021

  • Various styling issues (PHPCS, PHPStan)
  • Increase framework requirement to 101.2 because of ViewModel bug
  • Enabled debugging in JS (dumping attributes and config)
  • New Attributes ViewModel to collect data after initialize output
  • Add API interfaces to guarantee backwards compatibility in future
  • Added XML layout container gooogletagmanager_container for most datalayer blocks
  • Added debug utility class
  • Renamed existing plugin interceptors
  • Rewrite x-magento-init into simple require() for performance
  • Refactored Category block to no longer depend on onLoadedProductCollection
  • Removed all block classes (Script, Category, Product, Generic, Custom)
  • Remove \Yireo\GoogleTagManager2\Util\GetCurrentProduct
  • Remove \Yireo\GoogleTagManager2\Util\GetCurrentCategory
  • Remove helper
  • Remove container model
  • Remove entire observer-based input method
  • Remove ViewModelFactory

[2.0.5] - 5 May 2021


Re-add CSP whitelisting

[2.0.4] - 30 April 2021

  • Fix block retrieval with Layout instead LayoutFactory (@sprankhub)
  • Make sure view model is set correctly (@sprankhub)

[2.0.3] - 29 October 2020

  • Fix error when block is not present

[2.0.2] - 28 October 2020

  • Category Sort By not working properly with 2.4.X because of weird product loading (70)
  • Refactored legacy Registry into request
  • Move Config class to new namespace
  • PHPCS fixes for Magento Marketplace compliance

[2.0.1] - 29 July 2020

  • Magento 2.4 support

[2.0.0] - 2020-07-21

  • Legacy CustomerData class
  • Dev dependency with Mockery
  • Upgrade PHPUnit to be 2.4 compatible
  • Bumped minimum PHP to 7.2

[1.1.3] - 2020-05-30

  • Add a new CSP whitelist for M2.3.5+

[1.1.2] - 2020-03-31

  • Some small code quality things

[1.1.1] - 2020-02-10

  • Add ACL file for configuring access to config

[1.1.0] - 2019-11-23

  • Major rewrite to remove custom sections in favor of DI plugin
  • No more reloading of sections

[1.0.3] - 2019-08-07

  • Use currency code instead of currency symbol (@nicolas-medina)

[1.0.2] - 2019-06-15

  • Move cookie-restriction-mode to JS to work with FPC

[1.0.1] - 2019-03-13

  • Fix duplicate code
  • Add compatibility with Magento 2.2 again (2.1 is dropped permanently)
  • Fix invalid template path
  • Fix reloading issues with quote

[1.0.0] - 2019-02-26

  • First release with Changelog
  • See GitHub commits for earlier messages

We are a proud member of ExtDN

ExtDN forms a network of Magento extension developers, that strive for a better extension quality - both on a technical level and from an end-users point of view. With industry leaders like Fooman and aHeadworks, ExtDN lifts up the Magento extension space to a new level. And Yireo is proud to be part of this.

Do not miss out on what we say

This will be the most interesting spam you've ever read

We don't write too commercial stuff, we focus on the technology (which we love) and we regularly come up with innovative solutions. Via our newsletter, you can keep yourself up to date on all of this coolness. Subscribing only takes seconds.

Sign up for the Yireo newsletter



GitHub organizations

Legal information

Other Yireo sites

Get Social

About Yireo