Using the right Magento 2 extension is more essential now than ever. With MagePal, you can rest assured that you are getting the best quality Magento extensions, each line of code are carefully crafted and rigorously tested. Spend less time debugging and more time doing what you do best with MagePal extensions!
DataLayer is a JavaScript API that allows you to quickly and easily integrate any third-party Javascript with your Magento Store using Google Tag Magento. It provides an easy way to access and transform your Google Tag Manager data to match any specification with zero source code edits. Whether you want to integrate Bing, Facebook, SnapChat, Pinterest, or any other services.
Want to learn more about your customers? Gain valuable insight on your customers shopping behavior, sales performance and more. Upgrade to our new Google Analytics 4 (GA4) to take full advantage of Google Analytics most valuable features.
Review license.txt
Install Google Tag Manager (version 3.0.0 or greater for Magento 2.4.0 and above)
composer require magepal/magento2-data-layer
Using Hyvä Magento 2 Theme?
composer require hyva-themes/magento2-magepal-data-layer
Learn more about installing and setting up Google Tag Manager
Install DataLayer for Google Tag Manager (version 2.0.0 or greater for Magento 2.4.0 and above)
Enable Module (from {Magento root} folder)
php -f bin/magento module:enable --clear-static-content MagePal_GoogleTagManager
php -f bin/magento module:enable --clear-static-content MagePal_DataLayer
php -f bin/magento setup:upgrade
Like our extensions? Would you be kind enough to leave us a Google review? It only takes a minute and we’d be eternally grateful! Just click the link to go to our MagePal Google Business page and leave us your feedback.
Log into your Magento 2 Admin
After logging into your Google Tag Manager account, you will need to configure Google Tag Manager to send the information to Google Analytics once the various event happen. To do this you will need to follow the following instruction below.
/**
* @param string domain
* @return this
*/
setUrlDomain(domain)
/**
* @param object params
* params = {key:'pair'}
* @return this
*/
addUrlParams(params)
/**
* Reset url parameters
* @return this
*/
resetParams()
/**
* Build url string
* @return string
*/
buildUrl()
/**
* Create hidden iframe tag and open url
* @return this
*/
addIframe(url)
/**
* Create hidden image tag and open url
* @return this
*/
addImage(url)
require(['DataLayerApi'], function (dataLayerApi) {
var helper = dataLayerApi();
var queryParms1 = {
KEY: 'xyz',
OID: 123,
};
var queryParms2 = {
page_type: 'productDetail',
price: 1,
};
helper.setUrlDomain('//test.magepal/tags/c/');
helper.addUrlParams(queryParms1);
helper.addUrlParams(queryParms2);
//generate url test.magepal/tags/c/?KEY=xyz&OID=123&page_type=productDetail&price=1
var url = helper.buildUrl();
//create an iframe and open url
helper.addIframe(url);
//creat hidden iframe and open url
helper.addImage(url)
});
/**
* Get Url query string parameter by name
*/
getParameterByName(name)
/**
* Set Cookie
*/
setCookie(name, value, lifetime)
/**
* Get cookie by name
*/
getCookie(name, deleteCookie)
/**
* Delete cookie by name
*/
deleteCookie(name)
/**
* Save cookie if url query string exist
* Helper function for getParameterByName() and setCookie()
* @param urlParameter
* @param cookieName
* @param expiration
* @return {boolean}
*/
saveTrackingCodeIfKeyExist(urlParameter, cookieName, expiration)
/**
* Retrieve cookie if exist
* @param cookieName
* @param deleteCookie bool
*/
getTrackingCodeIfKeyExist(cookieName, deleteCookie)
require(['DataLayerApi'], function (dataLayerApi) {
var helper = dataLayerApi();
expiration = 60 * 60 * 24 * 30;
urlParameter = 'referenceId'
//get query string value if exist
var value = helper.getParameterByName(urlParameter);
//save value if exist to a cookie
if (value !== null && value !== '') {
cookieName = 'referenceId';
helper.setCookie(cookieName, value, expiration);
}
});
/**
* Get Currency Code
* @param defaultCode
* @return string
*/
getCurrencyCode(defaultCode)
/**
* To csv
* @param arr
* @return string
*/
toCsv(arr)
/**
* To csv
* @param arr
* @return string
*/
toTsv(arr)
/**
* Get customer data
* @param sKey
* @param defaultValue
* @return object | mix
*/
getCustomer(sKey, defaultValue)
/**
* Get customer id
* @param defaultValue
* @return int
*/
getId(defaultValue)
/**
* Get customer email address
* @param defaultValue
* @return string
*/
getEmail(defaultValue)
/**
* Get get email sha1
* @param defaultValue
* @return string
*/
getEmailSha1(defaultValue)
/**
* Get customer Website Id
* @param defaultValue
* @return int
*/
getWebsiteId(defaultValue)
/**
* Get data element by key
* @param sKey
* @param defaultValue
* @return {*|*|string}
*/
getCategory(sKey, defaultValue)
/**
* Get data element by key
* @param sKey
* @param defaultValue
* @return {*|string|*}
*/
getCategoryItem(sKey, defaultValue)
/**
* Get Production Impression collection
* @return {Array|*}
*/
getProductImpressions()
/**
* Get Product Impression SKUs
* @param fieldName
* @param options
* @return {*|Array|string}
*/
getProductSkus(fieldName, options)
/**
* Return product detail
*/
getCategoryDetail()
/**
* Get data element by key
* @param sKey
* @param defaultValue
* @return {*}
*/
getProduct(sKey, defaultValue)
/**
* Get data element by key
* @param sKey
* @param defaultValue
* @return {*|string|*}
*/
getProductItem(sKey, defaultValue)
/**
* Get Product collection
* @param options
* @return {Array|*}
*/
getProductCollection(options)
/**
* Get Skus
* @param fieldName
* @param options
* @return {*[]|*|Array|string}
*/
getProductSkus(fieldName, options)
/**
* Return product detail
* @return {}
*/
getProductDetail()
/**
* Get Item added to cart
* @param options
* @return {Array|*}
*/
getAddedToCartItems(options)
/**
* Get total for item added to cart
* @return float
*/
getAddedToCartTotal()
/**
* Get skus added to cart
* @param fieldName
* @param options
* @return {*|Array|string}
*/
getAddedToCartItemSkus(fieldName, options)
/**
* Get items removed from cart
* @param options
* @return array
*/
getRemovedFromCartItems(options)
/**
* Get item removed from cart
* @return float
*/
getRemovedFromCartTotal()
/**
* Get item removed from cart qty
* @return int
*/
getRemovedFromCartQty()
/**
* Get skus of item removed from cart
* @return array | string
*/
getRemovedFromCartItemSkus(fieldName, options)
/**
* Get data element by key
* @param sKey
* @param defaultValue
* @return {}
*/
getCart(sKey, defaultValue)
/**
* Get data element by key
* @param sKey
* @param defaultValue
* @return {}
*/
getCartItem(sKey, defaultValue)
/**
* Get Items
* @param options {appendIndex: bool, renameFieldTo: {fromKey:to, ...}}
* @return {*}
*/
getItems(options)
/**
* Get item count
* @return {}
*/
getItemCount()
/**
* Get quote items SKUs
* @param fieldName
* @param options {appendIndex: bool, renameFieldTo: {fromKey:to, ...}}
* @return {Array|string}
*/
getSkus(fieldName, options)
/**
* Get data element
* @param sKey
* @param defaultValue
* @return {*|string|*}
*/
getOrder(sKey, defaultValue)
/**
* Get items orders
* @param format {appendIndex: bool, renameFieldTo: {fromKey:to, ...}}
* @return {}
*/
getItems(options)
/**
* Get purchase items SKUs
* @param fieldName object
* @param options {format: 'csv'|'tsv'}
* @return array
*/
getSkus(fieldName, options)
/**
* Get item count
*/
getItemCount()
/**
* get Payment Method
* @param name
* @param defaultValue
* @return {string}
*/
getPaymetMethod(name, defaultValue)
/**
* get Shipping Method
* @param name
* @param defaultValue
* @return {*|string|*}
*/
getShippingMethod(name, defaultValue)
Add more information to the data layer to meet your client needs is as simple as extending our API.
define([
'jquery',
'underscore',
'DataLayerApi'
], function ($, _, Component) {
'use strict';
return Component.extend({
/**
* Add new method
* Hello World
*/
getHelloWorld() {
return 'hello world';
},
/**
* Extend existing functionality
* Get Currency Code
* @return string
*/
getCurrencyCode: function (defaultCode) {
var code = this._super(defaultCode);
if (code == 'xyz') {
return 'USD';
}
}
});
});
Even the most advanced Google Tag Manager users often run into issues while setting up new tags. Frustrated by the process we often ask ourselves, why doesn’t my tag fire, what data is sending to Google Analytics, and why didn’t this trigger work?
One of the most overlooked, yet important steps while working with GTM is its preview and debugging mode. Google Tag Manager’s preview mode allows you to preview your container code as if the current container draft was deployed so that you can test your configuration before it is published.
To enable preview mode, click Preview. Google Tag manager will display a banner across the top of the workspace overview page to indicate that preview mode is active.
Once preview mode is enabled a debug pane will display at the bottom of your browser content, which display all the fired tags fired, which data is available on the data layer at that moment in time and the order the tags are firing.
=============
=============
=============
=============
=============
=============
=============
=============
If your are using Magento + Google Analytics, then you need Enhanced E-commerce for Google Tag Manager.
Quickly previewing alternative product images on your category list page.
Providing your customer with a beautiful and functional order package tracking without leaving your site.
Total Downloads
years experience with Magento
Magento / Adobe Commerce Extensions
With millions of downloads worldwide, install with confidence knowing that our extensions will just work.
Is your Magento store ready for the future? Say hello to the new Google Analytics 4, which is built from the ground up with all-new features and advanced machine learning technology.