How to Add Google Analytics Code to Magento 2?
Google Analytics offers metrics to track incoming traffic and supports offline and mobile app interactions.
You get enhanced commerce to track your website’s activities. It includes purchase activities, successful orders, and wishlist buttons.
Customer metrics let you optimize purchase funnels to increase conversion rates.
We cover the steps to add Google Analytics code to Magento 2.
Steps to Add Google Analytics Code In Magento 2 Stores
1. Create a Google Analytics Account
Go to Google Analytics and create an account.
Click on “Create Account” and fill in your Gmail account address and password. Read and agree to the Privacy and Terms by clicking on “I Agree.”
You will be redirected to Google Analytics after the account is set up.
- Click on Sign Up to start using the tool. Fill in the details about your website, such as:
-Account and website name -Website URL -Industry category -Reporting timezone
- Agree to the Google Analytics Terms of Service Agreement.
2. Get the Tracking Code
You have to add a Google Analytics code to Magento 2 to collect traffic statistics.
Navigate to the left panel of the Analytics dashboard and click on the Admin Tab.
Click on the Tracking Info and open the Tracking Code panel. Copy the Tracking ID and the Tracking Code from the section.
3. Add Google Analytics Code to Magento 2
Log in to the Magento 2 Admin Panel to add the Google Analytics code.
Select Stores from the left-side menu and go to the store Configuration tab.
- In the Sales panel, click on Google API.
- Add your Google Analytics Account Number and Tracking ID.
If you wish to render the anonymous part of your visitors’ IP addresses, set Anonymize IP to “Yes.”
Enable Content Experiments to “Yes.” It is used for A/B testing and other performance tests.
Note: It might take up to 24 hours before Google Analytics can track your website data.
4. Enable Ecommerce Tracking for Google Analytics
Now we can enable ecommerce tracking in Google Analytics. From your Google Analytics Dashboard, go to the Admin panel.
Under all website data, click on eCommerce settings.
You will see an on-off button on the section. Enable the eCommerce button and enhanced eCommerce reporting.
Click on the Save button.
5. Check if the Code is Working Properly
You can check whether the tracking code is working. Navigate to the store’s front on one tab. Open the Google Analytics account in the second open the tab in the.
Choose a Real-Time report, and click on Overview. There should be one active user on site right now.
Reasons why your tracking code won’t be working -
1. Cross-check the analytics code
Copying and pasting the code from a doc file may break the code. Ensure that you copy the code directly from the Google Analytics account.
There should be no extra spaces between the letters.
2. Check for Google Analytics Filters
From the Google Analytics account, go to Admin > Filters.
Review all the filters added to the account. You may have excluded the IP address tracking.
As a result, it won’t display the real-time users from your IP address.
Multiple “Include” filters may also affect your tracking data. Check the filters before adding them to the analytics tool.
3. Google Penalties
Google penalties can affect the website’s ranking.
It may happen if you aren’t using an SSL certificate or have questionable content on your website. Google can penalize your site and result in a traffic drop.
You should not mistake it for Google Analytics not tracking your site. Check if there are other factors affecting the traffic drop.
Google Analytics for Magento 2 Website
Google Analytics gives insights into how many people visit your store. You can track specific website events, demographics, and how much time they spent on each page.
You can check whether the traffic came from social media, ad campaigns, or SERPs.
The universal analytics tool gives clear insights into your store and knows the target customers better. It helps improve the user experience with sales Google API.
Other tools such as Google Tag manager are used to update and manage website tags.
Some of the analytics components for Magento 2 include-
1. Website traffic
Get real-time statistics on the number of visitors accessing your site. You can track every click event on your website.
Trackable events are like Add to Cart, Place Order, and Proceed to Checkout.
2. Visitor segmentation
Segment the visitors for a specific period. Check which pages, links, and sources they access in your store.
In the “Audiences” section of Google Analytics, you can evaluate the users' demographics.
It includes age, gender, customer behavior, and geographic location. You can check the devices used like phones, PCs, tablets, etc.
You can create relevant Google Ad campaigns for your store.
4. Data visualizations
Google Analytics compiles all customer tracking data into one dashboard for analysis.
The dashboards allow you to visualize different data from your website into charts and tables.
5. Goal-related tracking
The Goal is a funnel for when the site achieves your target objectives.
For Magento, a goal can represent a user purchasing on the site. You can configure the goals to get critical information on the number of conversions.
Ecommerce Shopping Behavior Report
Add funnels to your Magento store to get specialized ecommerce data. You have to turn on Enhanced Ecommerce for this funnel -
Navigate to Conversions > Ecommerce > Shopping Behavior
The feature counts the number of user sessions for each step in the funnel. You can also see the percentage of visitors who arrived at the current step from the previous one.
You can see how many sessions turned into transactions -
All sessions > Product Views > Add to cart > Check-Out > Transactions
The Ecommerce Shopping Behavior Report feature analyzes data at a macro level.
It can display how many people view each product and which pages have less engagement. You can use funnels like these to optimize your pages.
Some of the other Google Analytics funnels for Magento 2 include-
- Checkout Behavior - See when the user drops off within a checkout process.
- Custom Reports -Apply advanced segments to compare conversion paths for different visitors.
- Goal Funnels - Add specific ecommerce goals such as product click or checkout completion.
Google Analytics helps understand how visitors interact with your Magento site. Store owners can use the data to create better ad campaigns and optimize the purchase funnels.
You can check out more tutorials on Magento on the MGT-Commerce Tutorials.