Magento 2 Google Analytics 4

Table of Content

  1. Extension Installation Guide
  2. Integrating Google Tag Manager with Website
  3. Configuration
  4. GTM API Configuration
  5. Exporting Json File
  6. Uploading Json File in Google Tag Manager
  7. Data Tracking in Google Analytics

 

  1. Extension Installation
  • For Magento Marketplace Customers
    • Find the Composer name and version of the extension in the extension’s composer.json file.
    • Login to your SSH and run:
      • composer require meetanshi/magento-2-google-analytics-4 --ignore-platform-reqs
    • Enter your authentication keys. Your public key is your username; your private key is your password.
    • Wait for Composer to finish updating your project dependencies and make sure there aren’t any errors.
    • To verify that the extension installed properly, run the command:
      • php bin/magento module:status Meetanshi_GA4 --ignore-platform-reqs
          • By default, the extension is probably disabled.
          • Enable the extension and clear static view files:
      • php bin/magento module:enable Meetanshi_GA4 --clear-static-content
      • php bin/magento setup:upgrade
      • For Magento version 2.0.x to 2.1.x - php bin/magento setup:static-content:deploy
      • For Magento version 2.2.x & above - php bin/magento setup:static-content:deploy –f
      • php bin/magento cache:flush
         
  • For Meetanshi Customers
  • Extract the zip folder and upload our extension to the root of your Magento 2 directory via FTP.
  • Login to your SSH and run below commands step by step:
  • php bin/magento setup:upgrade
  • For Magento version 2.0.x to 2.1.x - php bin/magento setup:static-content:deploy
  • For Magento version 2.2.x & above - php bin/magento setup:static-content:deploy –f
  • php bin/magento cache:flush
  1. Integrating Google Tag Manager with Website

To connect Google Tag Manager with the website, login to your “Google Tag Manager Account”. Move to Account à Container (Make sure to select respective container). Now, move to Admin à Install Google Tag Manager where you can find the Js and non-Js codes respectively. Paste them in the respective fields in Google Analytics 4 extension configuration.

  1. Configuration
    Login to Magento 2, move to Stores à Configuration à Meetanshi à GA4 where you can find various settings to configure the extension.
  • GA4: Enable GA4 extension from here.
  • Google Tag Manager JS Code: Enter the JS code you have copied from Google Tag Manager.
  • Google Tag Manager Non-JS Code: Enter the Non-JS code you have copied from Google Tag Manager.
  • Product Identifier: Select product identifier for tracking.
  • Enable Product Brand: Select “YES” to enable product brand in tracking.
  • Enable Variant: Select “YES” to enable product variants in tracking.
  • Order Success Page Total Calculation: Select how you want to track the order total calculation for transactions.
  • Exclude Tax From Transaction: Select “YES” to exclude tax from transactions tracking.
  • Exclude Shipping From Transaction: Select “YES” to exclude shipping from transactions.
  • Exclude Shipping Including Tax: Select “YES” to exclude shipping including tax from transactions.
  • Success Page Paths: In case of custom checkout pages, i.e., if you are not using default Magento 2 success path, add custom URL here.
  • Exclude Orders with 0 value: Select “YES” to exclude tracking of orders with 0 value. i.e., Free products.
  • Measure Product Clicks: Select “YES” to track product clicks from category, search result page and other related cross sell and upsell grids.
  • Child vs Parent: Select how to track transaction, i.e., child product or parent product.

  1.  GTM API Configuration
    For Google Tag Manager API configuration, you will need account ID and container ID from your Google Tag Manager account. To get the same, login to your Google Tag Manager Account and move to Account à Container à Workspace. Now, check the URL and copy both the account ID and container ID.

     

  • You will also need measurement ID from Google Analytics 4. To get the same, login to your Google Analytics 4 account and select the respective Property à View. Now, click Admin, and under the column of your property, select the Data Streams. Then select your data stream and copy the measurement ID.

  • Once you have your account ID, container ID and measurement ID, configure your GTM API under the Magento 2 extension configuration.
    • Account ID: Paste account ID that you copied from your Google Tag Manager.
    • Container ID: Paste container ID that you copied from your Google Tag Manager.
    • Measurement ID: Paste measurement ID that you copied from your Google Analytics 4.
  1. Exporting Json File

You will need your Google Tag Manager (GTM) ID as your public ID which you can get from your Google Tag Manger Account. To get the same, login to your Google Tag Manager account and select the respective Account à Container. Copy your GTM public ID as shown in the below image.
 

Now from the extension configuration, under the Json Export Options section, paste the public ID copied from Google Tag Manager. After that Click on “Save Config”, to save all the settings. Now, click on “Generate Json for GTM – Tags, Triggers and Variables” and then click “Download Json”.

  1. Uploading Json File in Google Tag Manager

Once the extension is configured successfully, you require to import all the tags, triggers and variables for the extension to work. Move to Account à Container. Click on the Admin à Import Container, browse the downloaded Json file, select the workspace, choose one of the import options, click “Confirm”.

  • You can preview your tags from Workspace à Tags. Click “Preview and perform all the actions on the website to verify the tags.

  • On performing various activities on the website, you can see the respective tags fired.

 

  1. Data Tracking in Google Analytics
    To check whether your data has been tracked from your website, login to your respective Google Analytics 4 account, move to Account à Property. From the left sidebar, move to Reports à Engagement à Events. You can view all your events tracked.

Note: Google Analytics 4 starts collecting data after the setup is complete, and the data will not be updated immediately. It is conservatively estimated that it takes approximately 24-48 hours for the data to be fully displayed in Google Analytics.