Magento 1 / OpenMage GA4 Google Tag Manager (GTM)

Installation and User Guide for Magento 1 / OpenMage GA4 Google Tag Manager (GTM)

Table of Contents

  1. Installation 
    • Disable Compilation Mode
    • Upload Package
    • Clear Caches
  2. Configuration Settings for Google Tag Manager Pro Tracking
    • General Settings
    • Query String Parameter Cookies
  3. JSONs provided with extension package
    • Google Analytics 4
    • Facebook Pixel Tracking
    • Snapchat Pixel Tracking
    • Adwords Dynamic Remarketing
    • Google Ads Enhanced Conversion Tracking with Javascript variable
    • Google Ads Enhanced Conversion Tracking with Data layer
    • Microsoft UET Tracking (Bing Ads Tracking)
    • Tiktok Pixel Tracking
    • Twitter(X) Pixel Tracking
    • Reddit Pixel Tracking
  4. Importing JSONs into GTM
  5. Setting variable information in GTM
  6. Publishing Tags in GTM
  7. Set up Google Analytics 4
  8. AJAX Add to Basket or Remove from Basket
    • AJAX Add to Basket
    • AJAX Remove from Basket
  9. Set Primary Categories
  10. Upgrading the Module From 0.0.35 and Below
  11. Query String Parameter Cookies

Installation

Configuration Settings for Google Tag Manager Pro Tracking 

Go to Admin > Stores > Configuration > Scommerce Configuration > Google Tag Manager Pro Tracking

General Settings

Please don’t turn this on unless you understand what this setting does.

Default value - denied or granted. Will be set in content initialization

image (1) (2).png

image - 2025-07-02T174123.484.png

image - 2025-07-02T174210.921.png

image - 2025-07-02T174253.830.png

image (2) (2).png

Query String Parameter Cookies

JSONs provided with extension package

The extension package contains JSONs which can be imported in GTM to set up required Tags, Triggers and Variables. The JSONs can be used to set up:

Importing JSONs into GTM

Setting variable information in GTM

Variables Created with JSON's

Publishing Tags in GTM

Once all set up is done and verified, need to Publish the tags to make it live on the website.

Step 1 - Click the SUBMIT button at the top right corner of the screen.image - 2025-07-02T181102.841.jpg

Step 2 - Enter an identifiable Version name.

Step 3 - Scroll down to the Workspace Changes to see all the changes made.

Step 4 - Click PUBLISH and you will be presented with a summary for this version.

Set up Google Analytics 4

image (83) (1).png

image - 2025-07-02T181608.652.jpg

image - 2025-07-02T181646.627.jpg

AJAX Add to Basket or Remove from Basket

Add the following two functions in your ajax add to basket js file and call gaAddToCart on success of Ajax add to basket and gaRemoveFromCart on success of Ajax remove from basket function.

AJAX Add to Basket
function gaAddToCart() {
	jQuery.cookie.json = true;
	var productToBasket = jQuery.cookie("productToBasket");
	var productlist = jQuery.cookie("productlist");
	if (productToBasket != undefined) {
		manipulationOfCart(productToBasket, 'add', productlist);
		jQuery.removeCookie("productToBasket", {
			path: '/',
			domain: '.' + document.domain
		});
	}
}
AJAX Remove from Basket 
function gaRemoveFromCart() {
	jQuery.cookie.json = true;
	var productOutBasket = jQuery.cookie("productOutBasket");
	if (productOutBasket != undefined) {
		manipulationOfCart(productOutBasket, 'remove', '');
		jQuery.removeCookie("productOutBasket", {
			path: '/',
			domain: '.' + document.domain
		});
	}
}
Set Primary Categories

You can use a script provided with the extension to automatically add primary categories for products. Admin can exclude certain categories from primary category and also prioritise one category over the other to be picked as the primary category.

Go to Admin>Catalog>Categories select a category then scroll down to find the option "Primary Category Settings". Here click on "Exclude From Primary Category" to exclude this category from primary category or enter the priority 0 being the highes. The highest priority category will be picked first for the primary category.image - 2025-07-02T182021.040.png

To automatically assign primary category for all products run the command given below by going into the root directory of your store.

scommerce:seo-base:set-primary-category

N.B - If you are using older version then run the script provided in the extension folder at the path Data/SetPrimaryCategoryM2.php from ssh

Upgrading the Module From 0.0.35 and Below

If you are using an older version of the extension(0.0.35 and below) where a common data layer is used to populate data to both UA and GA4 then upon updating to the latest version you need to make the following changes in GTM.

Remove these Tags, Triggers and Variables from GTM container
TAGS
Variables
Triggers

Now follow the steps below to import the latest GA4 settings for GTM

Step 1:- Acquire the latest GA4 JSON file provided with the module.

Step 2:- Go to your GTM container then click on admin>Import Container.

image - 2025-07-02T182649.513.png

Step 3:- Click on Choose container file and choose the JSON file acquired in step 1 then select the workspace new/existing. Also select Merge>Rename conflicting tags, triggers, and variables so that no crucial setting is lost.

image - 2025-07-02T182751.083.png

Step 4:- Lastly, click confirm to finish the import. Once it's done you will have the latest tags, triggers and variables for GA4 in your GTM.

Query String Parameter Cookies

Cookies from query Params configuration can be used to create new cookie parameters which can be stored in the users browser as per the valid time configured. for eg:- We have created a "msclkid"cookie in the configuration. Now if the cookie parameter is passwed with the URL then that cookie will be created in the browser.

image - 2025-07-02T183311.214.png

If you have a question related to this extension please check out our FAQ Section. If you can't find the answer you are looking for then please contact support@scommerce-mage.com.


Revision #10
Created 23 June 2025 13:37:50 by scommerce
Updated 2 July 2025 14:15:13 by scommerce