Skip links

How to add Google Analytics Code to Magento 2? A Step-by-Step Guide

If you are running an e-Commerce store on Magento 2, you need to track your website’s performance to make data-driven decisions. 

Google Analytics is an excellent tool to track your website’s traffic, user behavior, and conversions. 

In this article, we will guide you on how to add Google Analytics code to Magento 2.

Why Use Google Analytics on Magento 2?

Google Analytics provides a wide range of data that helps e-Commerce businesses understand their audience and improve their website’s performance. 

With Google Analytics, you can track the number of visitors, the duration of their stay, the pages they visit, the bounce rate, and more. 

You can also set up goals and track conversions to measure the effectiveness of your marketing campaigns.

Getting Started with Google Analytics

To add Google Analytics to your Magento 2 store, you need to create a Google Analytics account and obtain a tracking ID. 

If you already have a Google Analytics account, you can skip this step.

1. Sign up for Google Analytics

To sign up for Google Analytics, go to and click on “Start for free.” Follow the steps to create an account and set up your property.

2. Create a Tracking ID

Once you have set up your property, you need to create a tracking ID. 

To do this, go to your Google Analytics dashboard and click on the “Admin” tab. Under the “Property” column, click on “Tracking Info” and select “Tracking Code.” 

Your tracking ID will be displayed in the format: “UA-XXXXXXXX-X.”

Adding Google Analytics to Magento 2

Now that you have your Google Analytics tracking ID, you can add it to your Magento 2 store. 

There are two ways to do this: manually or by using a third-party extension.

Method 1: Manual Installation

  1. Log in to your Magento 2 Admin Panel and go to “Stores” > “Configuration.”
  2. Under “Sales,” click on “Google API.”
  3. Expand the “Google Analytics” section and enter your tracking ID in the “Account Number” field.
  4. Click “Save Config” to apply the changes.

Method 2: Using a Third-Party Extension

If you prefer a more convenient way of installing Google Analytics on Magento 2, you can use a third-party extension like AYSA.AI.

AYSA.AI is SEO automation software that helps e-Commerce businesses improve their website’s performance and increase sales. 

AYSA.AI provides a Google Analytics integration feature that allows you to add your tracking code to your Magento 2 store in just a few clicks.

To use AYSA.AI to install Google Analytics on Magento 2, follow these steps:

  1. Sign up for AYSA.AI: Go to and sign up for a free account.
  2. Connect Your Magento 2 Store: After signing up, connect your Magento 2 store to AYSA.AI by installing the AYSA.AI plugin.
  3. Install Google Analytics: Once your store is connected, go to the “SEO Tools” tab and select “Google Analytics.” Follow the instructions to install your tracking code.
  4. Verify Installation: After installing Google Analytics, verify the installation by going to your Google Analytics dashboard and checking the real-time data.


Adding Google Analytics to your Magento 2 store is crucial for tracking your website’s performance and making data-driven decisions. 

You can install Google Analytics manually or use a third-party extension like AYSA.AI for a more convenient and streamlined process. 

By using AYSA.AI, you can save time and focus on other important aspects of your e-Commerce business. 

As an SEO automation software, AYSA.AI also provides other features like keyword research, site audits, and competitor analysis to help you improve your website’s ranking and visibility.