Yireo - Trainings & extensions

Open main menu

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
FREE

Latest release: 1.0.3

Configuration

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 System> Configuration> [Services] Google Tag Manager.

Features

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
  • Insertion Method: A technical thing which is either set to Observer or to XML Layout. If the one does not work for you, try the other one instead.
  • Debug: For developers.

Data layer attributes

This extension adds the following attributes automatically to the data layer. There is no backend option to tune this, so if you want to make changes, change the PHTML templates in your own theme.

  • customerLoggedIn = Whether the customer has logged in
  • customerId = ID of the customer
  • customerGroupId = Customer group ID
  • customerGroupCode = Customer group code
  • categoryId = Category ID
  • categoryName = Category name
  • categoryProducts = Listing of top 3 products
  • productId = Product ID
  • productName = Product name
  • productSku = Product SKU
  • productPrice = Product price
  • transactionId = Order ID
  • transactionDate = Order date
  • transactionAffiliation = Website name
  • transactionTotal = Order total
  • transactionTax = Order tax
  • transactionShipping = Shipping amount
  • transactionPayment = Payment method
  • transactionCurrency = Currency of website
  • transactionPromoCode = Promotional code used for order
  • transactionProducts = Listing of all items in cart
    • sku = Item SKU
    • name = Item name
    • price = Item price
    • category = Listing of category IDs
    • quantity = Item quantity

Note that on a product page with an URL that also identifies a category, both the product attributes and the category attributes are added.

Technical details

This module does not use XML rewrites to change core classes. It uses two insertion modes - one using the XML layout, one using an observed event core_block_abstract_to_html_after.

Tip

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 to install 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. 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:

app/code/Yireo/GoogleTagManager2

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.

Downloads

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

Frequently Asked Questions

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.

Getting support

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

We usually respond within 24 hours.

Testing

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:

phpunit

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:

yarn
npm run mocha

Supported Magento versions

  • 2.2 (2.2.0, 2.2.1, 2.2.2, 2.2.3, 2.2.4, 2.2.5, 2.2.6, 2.2.7, 2.2.8, 2.2.9, 2.2.10)
  • 2.3 (2.3.0, 2.3.1, 2.3.2, 2.3.3)

Requirement details

  • magento/framework: ^101.0|^102.0
  • magento/module-catalog: ^100.1|^101.0|^102.0|^103.0
  • magento/module-checkout: ^100.1
  • magento/module-cookie: ^100.0
  • magento/module-customer: ^100.1|^101.0|^102.0
  • magento/module-directory: ^100.1
  • magento/module-quote: ^100.1|^101.0
  • magento/module-sales: ^100.1|^101.0|^102.0
  • magento/module-store: ^100.1|^101.0
  • php: >=7.0.0
  • ext-json: *
  • ext-pcre: *

Changelog

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.

[Unreleased]

[1.0.3] - 2019-08-07

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

[1.0.2] - 2019-06-15

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

[1.0.1] - 2019-03-13

Fixed
  • 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

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

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.

Maybe our newsletter is something for you?

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 in a few seconds

Proud member of

  Latest blog

Extensions

Legal information

Other Yireo sites

Get Social

About Yireo