Magento 2 Google Tag Manager (GTM) GA4 Ecommerce Tracking
Installation and User Guide for Magento 2 Google Tag Manager Pro Tracking Extension
Table of Contents
- Installation
- Installation via app/code
- Installation via Composer
- Installation via Composer(Hyvä Theme)
- Installation via Composer(Breeze Theme)
- Configuration Settings for Tracking Base
- General Settings
- Checkout Behaviour
- Configuration Settings for Google Tag Manager Pro
- General Settings
- Cookies From Query Params
- JSONs/Script provided with extension package
- Importing JSONs into GTM
- Setting variable information in GTM
- Publishing Tags in GTM
- Set up Google Analytics 4
- Set up Google Adwords Conversion
- Set up Enhanced Conversion
- Enable Enhanced Conversions in Google Adwords
- Set up Enhanced Conversion with the Module
- Cookies From Query Params
- Upgrading the Module From 3.0.1 and Below
- Front-end Screenshots
- Order Total of Product without VAT
- Order Total of Product with VAT
- Send SKU of Child Product
- Send SKU of Parent Product Only
- Send Parent Category
- Primary Category
- Set up Consent Mode V2 with GTM
Installation
- Installation via app/code: Upload the content of the module to your root folder. This will not overwrite the existing Magento folder or files, only the new contents will be added. After the successful upload of the package, run below commands on Magento 2 root directory.
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy
-
Installation via Composer: Please follow the guide provided in the below link to complete the installation via composer.
-
Installation via Composer(Hyvä Theme): Go to My Account section then go to Composer Instructions. Run the composer config commands mentioned on the page then run the below command to install the module on hyva theme.
composer require hyva-themes/magento2-scommerce-googletagmanagerpro
- Installation via Composer(Breeze Theme): Go to My Account section then go to Composer Instructions. Run the composer config commands mentioned on the page then run the below command to install the module on hyva theme.
composer require scommerce/breeze-googletagmanagerpro
Configuration Settings for Tracking Base
Go to Admin > Stores > Configuration > Scommerce Configuration > Tracking Base
General Settings
-
Enabled – Select “Yes” or “No” to enable or disable the module.
-
Enable Enhanced Ecommerce – Select ‘Yes’ to enable this module. Please make sure this feature is enabled in Google Analytics first before enabling in Magento2.
-
Enable Enhanced Conversion:- Set "Yes" to enable enhanced conversion to send PII data to Google Adwords to target actual customers. You need to turn on enhanced conversions in Google Adwords. Click here for more information
-
Enable Consent mode - This setting activates Google Consent Mode v2. It lets us control how Google tags use user consent and protect user data
-
Cookie mapping - This setting defines the mapping between user preference cookies and the corresponding Google Consent Mode parameters ad_storage, ad_user_data, ad_personalization, analytics_storage
Cookie preference cookie could be set using our GDPR extension or any Consent Management Platform (CMP). -
Product ID Attribute – Select the attribute which you have submitted in your Google base feed. For e.g. SKU
-
Brand Attribute – Please select brand attribute, if you have one otherwise put your brand name in the below input box.
-
Primary Category Attribute – When a product is in more than one category then the primary category attribute will be sent to Google.
-
Brand Attribute – Please
-
Sliders name- Enter the name for custom sliders that will be sent as list name with the data layer.
-
Affiliation- Enter the affiliation name which you want to send with the GA4 data layers.
-
Use Base Currency - Set ‘Yes’ if you want to send base order data and ‘No’ to send store order data to Google. Set this ‘No’ only when you have multicurrency and you want to send different currency data to Google.
-
Product Price Include Tax- Set “Yes” then VAT will be included in the price.
-
Order Total Include VAT – Set “Yes” then VAT will be included in order total.
-
Always Send Parent SKU – Set “Yes” then it always send parent sku instead of child sku to GA during checkout.
-
Category Attribute- Please select category attribute if you have one otherwise put your brand name in the below input box. Attribute should be available for product listing 'Storefront Properties -> Used in Product Listing = Yes'
-
Is Category ID- Set "Yes" if "Category Attribute" is ID of the category, "No" if it is plain value
-
Send Parent Category – Set “Yes” to send the category path and Set “No” to send the category name only.
-
List Name with full path- Choose whether you want to send the full path of the category or not. When 'yes' The breadcrumbs are broken into separate categories and sent as item_category1, item_category2 etc. Set 'No' to send the lowest level category. for ex:- Men>Tops>Jackets, when 'yes' Men, tops, jackets all three categories will be sent. When 'no' only jackets is sent.
-
Send 'Default List'- When customers land on the product page directly then 'default' list' will be sent as list name when set to 'Yes'. When 'No' list name/ list ID will be removed.
-
Default List- Enter the default list name if the product impression is not found
-
Send Admin Orders to Google– Select “Yes” to track orders created in admin
-
Send Refund On Order Cancellation:- Set "yes" to send refund event on order cancellation.
-
Source-Please add the Campaign Source for backend orders.
-
Medium-Please define the Campaign Medium for Backend Orders.
-
Send Product Impression on Scroll - Enable this feature when you have loads of products on product listing / category pages.
-
Product item class on category / product listing page- Enter the product item class. Make sure this product class item hierarchy is as unique as possible for example for luma theme you can use div.products ol.product-items li.product-item
-
Threshold for Scroll:- Enter the number of product impressions to be sent with view_item_list on scroll.
-
Category Ajax Enabled – Enable this feature if you have third party ajax enabled extension on your category page.
Checkout Behaviour
- Add Carrier Title:- Use this to add carrier title to the shipping step. Set "Yes" to send carrier_code::carrier_title. Ex. flatrate::Flat Rate
- Add Payment Title :- Use this to add payment method title to payment step. Set "Yes" to send method::title. Ex. checkmo::Check / Money Order
Configuration Settings for Google Tag Manager Pro
Go to Admin > Stores > Configuration > Scommerce Configuration > Google Tag Manager Pro
General Settings
-
Enabled – Select “Yes” or “No” to enable or disable the module.
-
License Key – Please add the license for the extension which is provided in the order confirmation email. Please note license keys are site URL specific. If you require license keys for dev/staging sites then please email us at support@scommerce-mage.com.
-
Server Side Tagging – Set "Yes" to enable server side tagging and "no" to disable it. Please don’t turn this on unless you understand what this setting does.
-
Account Id – Enter your Google Tag Manager Account Id.
-
Enable dynamic remarketing tags – Set “Yes” if you want to enable google dynamic remarketing tags to used for GTM.
-
Enable tracking for other sites – Set “Yes” to enable tracking for other sites.
-
Send Ecom Category Path – Set "yes" to send the category path with ecomm_category.
-
Enable GDPR Cookie Check – Select "Yes" or "No" to enable/disable GDPR Cookie Check
-
Server Side Tagging – Set "Yes" to enable server side tagging and "no" to disable it. Please don’t turn this on unless you understand what this setting does.
-
Server Side script part - Enter the HTML code of server side GTM container. It will replace the default HTML code on the frontend.
-
Server Side noscript part - Enter the noscript part of server-side GTM code. It will also replace the default HTML code on the frontend.
-
Force decline – If you set this to yes then GTM tracking will be turned off unless customer accepts the cookie policy from the cookie notification message from your website
-
GDPR Cookie Key – You can add name of your GDPR cookie here for our GDPR extension the name of cookie key is cookie_accepted but if you are using other GDPR extension then please check with extension developer
-
Enable GA4 data layer-Select "Yes" to add GA4(Google Analytics 4) events to the data layer.
Cookies From Query Params
- Enabled – Select “Yes” or “No” to enable or disable the module.
- Configuration – Use this setting to create cookies by entering cookie parameter, cookie name, and cookie value.
- Lifetime – Enter the lifetime of the cookie. It will be stored in the users browser as per the time defined in this setting.
JSONs/Script provided with extension package
NOTE:- Please make sure to import the JSON files again after every upgrade of the module as we keep changing these files time to time and keep them updated with our latest data layers.
The extension package contains JSONs which can be imported in GTM to set up required Tags, Triggers and Variables.
Finding JSON files
Please follow the steps below to download the module:-
Step 1:- Login to your account and go to the My Account Section
Step 2:- Click on My Downloadable Products
Step 3:- Click on the extension and from the dropdown menu select download
Go to the extension file m2-google-tag- manager-pro and then to the Data Folder (Path - m2-google-tag-manager-pro/data/) to find these files.
The JSONs can be used to set up
- GTM-GoogleAnalytics4.json:- Google Analytics 4
- GTM-Facebook_Pixel_Tracking.json:- Facebook Pixel tracking
- GTM-Snapchat_Tracking.json:- Snapchat Pixel tracking
- GTM-AdwordsDynamicRemarketing.json:- Google AdWords Dynamic Remarketing
- GTM-google_ads_conversion_tracking.json:- Google Ads Conversion Tracking
- GTM-Pinterest.json:- Pinterest tracking
- GTM-Pinterest-GA4.json:- Use this file if you are using only GA4 and not UA
- GTM-Reddit_Pixel_Tracking.json:- Reddit Pixel Tracking
- GTM-Tiktok_Pixel_Tracking.json:- Tiktok Pixel Tracking
- GTM-Twitter.json:- Twitter Pixel Tracking
- GTM-Partnerize.json:- Partnerize
- GTM-Webgains_tracking.json:- Webgains Affiliate tracking
- GTM-google_ads_enhanced_conversion_tracking.json:- Google Ads Enhanced Conversion Tracking(Make sure its enabled in the extension configuration and also ensure that "send conversion data using data layer is set to "No" in tracking base configuration)
- GTM-google_ads_enhanced_conversion_tracking_using_datalayers.json - If you have set "send conversion data using data layer is set to "Yes" in tracking base configuration then import this JSON file which utilizes data layer push to populate the conversion PII data.
- SetPrimaryCategories.php:- Primary Category Script (SetPrimaryCategories.php) – All of the above JSON files can be imported into GTM but primary category script needs to be added into the root directory of your website. Add the SetPrimaryCategories.php file in your website’s root directory and open the link as follows: - http://Your_website_URL.com/SetPrimaryCategories.php
Note:- Please import only one Pinterest JSON file depending upon the extension configuration you are using. If you are only using GA4 and no UA then you can use the Pinterest GA4 JSON file. Also if you have 'Send Product Impression on Scroll ' enabled in Admin>Stores>Configuration>Scommerce Configuration>Tracking Base then use the Pinterest GA4 JSON file as well otherwise you can use the original Pinterest JSON file.
Importing JSONs into GTM
To import JSONS provided with extension package follow below steps: