# Magento 2 Google Global Site Tag (gtag.js) with GA4(Google Analytics 4) Enabled

### <span style="color: rgb(59, 130, 246);">Installation and User Guide for Magento 2 Global Site Tag (gtag.js) Extension</span>

****Table of Contents****

1. [**Installation**](#bkmrk-installation "Installation")
    - **Installation via app/code**
    - **Installation via Composer**
    - **Installation via Composer( (Hyvä Theme):**
2. [**Configuration Settings for Tracking Base**](#bkmrk-configuration-settin "Configuration Settings for Tracking Base")
    - **General Settings**
    - **Checkout Behaviour**
3. [Configuration Settings for Global Site Tag (gtag.js)](#bkmrk-configuration-settin-1 "Configuration Settings for Global Site Tag (gtag.js)")
    - **General Settings**
4. [Set up Google Analytics 4](#bkmrk-set-up-google-analyt "Set up Google Analytics 4")
5. [Set Up Cross Domain Measurement](#bkmrk-set-up-cross-domain- "Set Up Cross Domain Measurement")
6. [Front-end Site view](#bkmrk-front-end-site-view "Front-end Site view")
    - **Home Page with Tags**
    - **Gtag.js Code**
    - **Gtag.js Brand Name**

### <span style="color: rgb(59, 130, 246);">Installation</span>

- ****Installation via app/code:****<span style="white-space: pre-wrap;"> 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.</span>

```
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy
```

- ****Installation via Composer:****<span style="white-space: pre-wrap;"> Please follow the guide provided in the below link to complete the installation via composer.</span>

<p class="callout success">[https://docs.scommerce-mage.com/magento-2-extensions/installation-via-composer/installation-via-composer](https://docs.scommerce-mage.com/magento-2-extensions/installation-via-composer/installation-via-composer)</p>

- ****Installation via Composer(Hyvä Theme):****<span style="white-space: pre-wrap;"> 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.</span>

```php
composer require hyva-themes/magento2-scommerce-gtag
```

### <span style="color: rgb(59, 130, 246);">Configuration Settings for Tracking Base</span>

<span style="white-space: pre-wrap;">Go to </span>****Admin &gt; Stores &gt; Configuration &gt; Scommerce Configuration &gt; Tracking Base****

#### <span style="color: rgb(249, 115, 22);">General Settings</span>

- ****Enabled –****<span style="white-space: pre-wrap;"> Select "Yes" or "No" to enable or disable the module.</span>
- ****Enable Enhanced Ecommerce –****<span style="white-space: pre-wrap;"> Select 'Yes' to enable this module. Please make sure this feature is enabled in Google Analytics first before enabling in Magento2.</span>
- ****Product ID Attribute –****<span style="white-space: pre-wrap;"> Select the attribute which you have submitted in your Google base feed. For e.g. SKU</span>
- ****Brand Attribute –****<span style="white-space: pre-wrap;"> Please select brand attribute, if you have one otherwise put your brand name in the below input box.</span>
- ****Use Base Currency -****<span style="white-space: pre-wrap;"> 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.</span>

[![gtag_config_1.png](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/gtag-config-1.png)](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/gtag-config-1.png)

- ****Product Price Include Tax-****<span style="white-space: pre-wrap;"> Set "Yes" then VAT will be included in the price.</span>
- ****Order Total Include VAT –****<span style="white-space: pre-wrap;"> Set "Yes" then VAT will be included in order total.</span>
- ****Always Send Parent SKU –****<span style="white-space: pre-wrap;"> Set "Yes" then it always send parent sku instead of child sku to GA during checkout.</span>
- ****Category Attribute-****<span style="white-space: pre-wrap;"> Please select category attribute if you have one otherwise put your brand name in the below input box. </span>****Attribute should be available for product listing 'Storefront Properties -&gt; Used in Product Listing = Yes'****
- ****Is Category ID-****<span style="white-space: pre-wrap;"> Set "Yes" if "Category Attribute" is ID of the category, "No" if it is plain value</span>

[![image.png](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/image.png)](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/image.png)

- ****Send Parent Category –****<span style="white-space: pre-wrap;"> Set "Yes" to send the category path and Set "No" to send the category name only.</span>
- ****Default List-****<span style="white-space: pre-wrap;"> Enter the default list name if the product impression is not found</span>
- ****Send Admin Orders to Google–****<span style="white-space: pre-wrap;"> Select "Yes" to track orders created in admin</span>
- ****Source-****<span style="white-space: pre-wrap;"> Please add the Campaign Source for backend orders.</span>
- ****Medium-****<span style="white-space: pre-wrap;"> Please define the Campaign Medium for Backend Orders.</span>
- ****Send Product Impression on Scroll -****<span style="white-space: pre-wrap;"> Enable this feature when you have loads of products on product listing / category pages.</span>
- ****Category Ajax Enabled –****<span style="white-space: pre-wrap;"> Enable this feature if you have third party ajax enabled extension on your category page.</span>

[![image (1).png](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/image-1.png)](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/image-1.png)

#### <span style="color: rgb(249, 115, 22);">Checkout Behaviour</span>

- ****Add Carrier Title:-****<span style="white-space: pre-wrap;"> Use this to add carrier title to the shipping step. Set "Yes" to send </span>**carrier\_code::carrier\_title**. Ex. flatrate::Flat Rate
- ****Add Payment Title :-****<span style="white-space: pre-wrap;"> Use this to add payment method title to payment step. Set "Yes" to send </span>**method::title**. Ex. checkmo::Check / Money Order
- ****Steps Configuration:-****<span style="white-space: pre-wrap;"> define checkout steps</span>
    - ****Step:-****<span style="white-space: pre-wrap;"> number of step</span>
    - ****Selector:-****<span style="white-space: pre-wrap;"> add the selector for the step. Basic selector could be '#customer-email' this is equals to '#customer-email/change' and will send customer email itself</span>
    - ****Type:-****<span style="white-space: pre-wrap;"> choose the step type from the dropdown</span>

[![image (2).png](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/image-2.png)](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/image-2.png)

### <span style="color: rgb(59, 130, 246);">Configuration Settings for Global Site Tag (gtag.js)</span>

<span style="white-space: pre-wrap;">Go to </span>****Admin &gt; Stores &gt; Configuration &gt; Scommerce Configuration &gt; Global Site Tag (gtag.js)****

#### <span style="color: rgb(249, 115, 22);">General Settings</span>

- ****Enabled –****<span style="white-space: pre-wrap;"> Select "Yes" or "No" to enable or disable the module.</span>
- ****License Key –****<span style="white-space: pre-wrap;"> 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 </span><support@scommerce-mage.com>.
- ****Accounts ID –****<span style="white-space: pre-wrap;"> You can add multiple account id, it can be Analytics, Adwords.</span>
    - ****Main Account –****<span style="white-space: pre-wrap;"> Select 'Yes' to set your main analytics id as an account id. This account will be used to connect gtag.js.</span>
    - ****Use Linker –****<span style="white-space: pre-wrap;"> If this is enabled (set to 'Yes') then this account will be linked to domains from "Domains to link" field, which is specified below</span>
    - ****Action –****<span style="white-space: pre-wrap;"> You can delete your account\\, if required.</span>

[![image (3).png](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/image-3.png)](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/image-3.png)

- ****Enable Linker -****<span style="white-space: pre-wrap;"> If this is enabled then you can set linker properties, in domain configurations which is specified below e.g. Domain to link, Decorate Forms. This setting is mainly for Cross domain mesurement, so to use this you must first enable it in Google Analytics 4 Admin.</span>
- ****Domains to Link -****<span style="white-space: pre-wrap;"> Enter the domains that you want to link. Example destination.com, dest3.com or /^example.(com|de|nl)$/.</span>
- ****Decorate Forms -****<span style="white-space: pre-wrap;"> If you have forms on site pointing to the destination domain, set this property of the linker parameter to Yes</span>
- ****Promotion Tracking –****<span style="white-space: pre-wrap;"> Here is the format to set up the promotion tracking: &lt;a href="#" data-promotion="CREATIVENAME" data-id="PROMOID" data-name="PROMONAME" data-creative="PROMOCREATIVE" data-position="PROMOPOSITION"&gt; Content &lt;/a&gt;</span>
- ****Enable Dynamic Remarketing Tag –****<span style="white-space: pre-wrap;"> If set to 'Yes', then this will enable and install remarketing tag to different pages.</span>
- ****Enable Tracking for Other Sites –****<span style="white-space: pre-wrap;"> This will enable other sites variables (</span>[https://support.google.com/tagmanager/answer/6106009?hl=en-GB#zippy=%2Ccustom](https://support.google.com/tagmanager/answer/6106009?hl=en-GB#zippy=%2Ccustom)[)](https://developers.google.com/adwords-remarekting-tag/parameters#other)<span style="white-space: pre-wrap;"> instead of retail site variables.</span>

[![image (4).png](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/image-4.png)](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/image-4.png)

### <span style="color: rgb(59, 130, 246);">Set up Google Analytics 4</span>

- Go to Analytics and select the website on which you want to implement GA4.
- Once you are in universal analytics panel go into admin settings. Here you will notice an UPGRADE TO GA4 button, click on it. You will be walked with creating a new property. Follow along, once you are finished you will see the new GA4 view on your screen

[![image.jpg](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/image.jpg)](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/image.jpg)

### <span style="color: rgb(59, 130, 246);">Set Up Cross Domain Measurement</span>

****Step 1:-****<span style="white-space: pre-wrap;"> Go to Google Analytics 4 Admin&gt;Data Streams&gt;Select your stream&gt;Configure Tag Settings &gt;Configure Your Domains, here add your domains or subdomains that you want to track.</span>

[![image (5).png](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/image-5.png)](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/image-5.png)

****Step 2:-****<span style="white-space: pre-wrap;"> Add the all domains added above in the configuration "Domains to link" comma separated. Now if you have any links taking you from your main site to the linked site, </span>****\_gl cookie****<span style="white-space: pre-wrap;"> is automatically apended to the URL that contains several information such as source website, source campaign etc hereby accomplishing the cross domain measurement. an example of such URL is as follows: </span>

```php
https://magento2demo.scommerce-mage.co.uk/?_gl=1fzl3bd_gaMTk3ODY0NTU1Mi4xNzIyODQzNDc3_ga_FWXJFY956H*MTcyMjg1OTYxOC40LjEuMTcyMjg1OTYzNS4wLjAuMA..
```

### <span style="color: rgb(59, 130, 246);">Front-end Site view</span>

- ****Home Page with Tags -****<span style="white-space: pre-wrap;"> In Tag Assistant tool you can see all the fired tags.</span>

[![image (1) (1).png](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/image-1-1.png)](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/image-1-1.png)

- ****Gtag.js Code -****<span style="white-space: pre-wrap;"> In the below image you can see the UA and AW tracking id's from </span>****Admin &gt; Stores &gt; Configuration &gt; Scommerce Configuration &gt; Global Site Tag (gtag.js) &gt; Account Id****<span style="white-space: pre-wrap;"> &gt; Click on </span>****"Add Account"****<span style="white-space: pre-wrap;"> – G-R6FSTDG16K, AW-123234123.</span>

[![image (2) (1).png](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/image-2-1.png)](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/image-2-1.png)

- ****Gtag.js Brand Name –****<span style="white-space: pre-wrap;"> You can add brand name from </span>****Admin &gt; Stores &gt; Configuration &gt; Scommerce Configuration &gt; Global Site Tag (gtag.js) &gt; Brand Name – "TestScommerce".****

[![image (1).jpg](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/image-1.jpg)](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/image-1.jpg)

<span style="white-space: pre-wrap;">If you have a question related to this extension please check out our </span>[****FAQ Section****](https://www.scommerce-mage.com/magento2-google-analytics-missing-transactions.html#customfaq)<span style="white-space: pre-wrap;"> first. If you can't find the answer you are looking for then please contact </span>[****support@scommerce-mage.com****](mailto:core@scommerce-mage.com)****.****