How To Set Up Magento 2 GA4 Using GTM – Complete Method
Enjoy a Seamless GA4 Integration
Install Meetanshi’s Magento 2 Google Analytics 4 extension for a hassle-free setup.
Thinking to upgrade your Magento 2 ecommerce analytics to GA4? Here’s the complete stepwise method to set up Google Analytics 4 on Magento 2.
Google Analytics is one of the most popular website analytics platforms. The totally free-to-use platform offers deep insights into the website traffic and user behavior. The latest version, Google Analytics 4, has taken analytics to the next level, especially for the e-commerce sites. If you’re a Magento 2 store owner lost solving the GA4 maze, then this post is for you!
In this post, find a step-wise tutorial to set up the new Google Analytics 4 in Magento 2 using Meetanshi’s extension.
What’s Covered?
Why Set Up Google Analytics 4 on Magento 2?
For online store owners, data means everything!
Google Analytics 4 has totally replaced the Universal Analytics from July 1, 2023 onwards.
Magento 2 store owners must make an immediate switch to the latest platform to continue collecting data.
Furthermore, the advanced version takes the e-commerce tracking beyond the basic metrics, which can help you drill down into customer’s journey. Here are some solid reasons to set up GA4 on your site:
- In-built e-commerce tracking
- Sales forecasting through ML
- New data tracking model
- Support for custom-events
- Unified Web + App analytics
- Custom report generation
Learn more about the rich features of Google Analytics 4 version.
Now, let’s go through the step-wise tutorial to set up Google Analytics 4 on a Magento 2 store.
5 Steps to Set Up Google Analytics 4 on Magento 2?
In order to set up Google Analytics 4 in your store, we will use Magento 2 Google Analytics 4 extension. It is the easiest method to set up GA4 e-commerce tracking via GTM for Magento users. It’s essential to set up a staging environment. This allows for testing and development in a controlled and isolated environment, separate from the live production environment.
Prerequisites:
- Magento 2 Google Analytics 4 extension
- Google Tag Manager account
Here are the steps to set up Google Analytics 4 on Magento 2 using the extension:
- Install & Enable the Extension
- Add GTM Code to Magento 2
- Configure the Extension
- Magento 2 GTM API Configuration
- Generate & Import JSON into GTM
1. Install & Enable the Extension
Download and install Meetanshi’s Magento 2 Google Analytics 4 extension. Once installed, go to Stores → Configuration → Meetanshi → GA4 to enable it.
2. Add GTM Code to Magento 2
Open a new tab, log into your Google Tag Manager Account, and go to Account → Container.
Select the respective container and move to Admin → Install Google Tag Manager, where you can find the Js and non-Js codes.
Copy the codes from the Google Tag Manager, and paste them into respective fields in the Stores → Configuration → Meetanshi → GA4 configuration.
- Paste <head> code into Google Tag Manager JS Code field
- Paste <body> code into Google Tag Manager Non-JS Code field
Click on the Save Configuration button at the top-right corner.
3. Configure the Extension
Now, its time to configure the Magento 2 extension to set up GA4.
- Product Identifier: Select the product identifier variable in your store.
- Enable Product Brand: Select ‘Yes’ to track the product brand in GA4.
- Enable Variant: Select ‘Yes’ to track product variants in GA4.
- Order Success Page Total Calculation: Choose the method to calculate order success page total. You can choose from:
- Grand Total: Amount with discounts
- Sub-Total: Whole amount without discounts
- Exclude Tax From Transaction: Select ‘Yes’ to exclude the tax from the transaction amount.
- Exclude Shipping From Transaction: Select ‘Yes’ to exclude the shipping from the transaction amount.
- Exclude Shipping Including Tax: Select ‘Yes’ to exclude the shipping including tax.
- Success Page Paths: Enter the success page path, in case of custom checkout pages. You can enter multiple success page paths separated by commas.
- Exclude Orders with 0 Value: Select ‘Yes’ to avoid tracking orders with zero value.
- Measure Product Clicks: Select ‘Yes’ to measure product clicks from various pages.
- Child Vs Parent: Select whether you want to track the parent product or each of the child products separately.
Finally, click Save to proceed and proceed with the next step.
4. Magento 2 GTM API Configuration
Now, it’s time to configure the GTM API with the Magento 2 extension.
For this you’ll need to get the account ID & container ID from your GTM account. To get them, log into Google Tag Manager Account, and go to Account → Container → Workspace. The URL of the Workspace will contain the account ID after the accounts/ and container ID after the containers/ part. For example:
Move to the Magento admin, and go to Stores → Configuration → Meetanshi → GA4, expand the GTM API Configuration section, and paste the Account ID and Container ID in the respective fields.
You also need to enter the measurement ID into the extension.
To get it, log into your GA 4 account, and navigate to Property → View → Admin → Data Streams. Select the data stream of your Magento 2 store and copy its measurement ID.
Now, paste the copied measurement ID in the respective field in the extension.
Click Save Config at the top-right corner to save the progress.
5. Generate & Import JSON into GTM
Once everything is configured properly, it’s time to generate the JSON file for the container.
In your GTM account, copy the GTM public ID as shown in the screenshot:
Paste the GTM Public ID into the respective field in the extension, and click Generate JSON for GTM – Tags, Triggers and Variables button.
Now, click Download JSON to download the container file.
The final step is to import the Magento 2 container into GTM.
In your GTM account, navigate to Account → Container, select Admin tab, and click Import Container.
Choose the JSON file generated by the extension, and import it.
Now, you can take a look at the imported tags in the Workspace → Tags section, and Submit them.
If everything looks good to go, click Submit to completed the Magento 2 Google Analytics 4 setup.
Voila!! 🎉 You’ve successfully setup Google Analytics 4 on Magento 2. The GA4 dashboard will start populating data soon!
That’s how easy it is to setup Google Analytics 4 in Magento 2 using Meetanshi’s extension!
In this article, we discussed the easiest method to set up Google Analytics 4 in Magento 2. I hope this tutorial has been useful to you. In case you still have any doubts or face any issue during the setup, feel free to comment, I would be happy to help you. 🙂
Want to integrate GA4 to your Magento 2 Store? Magento 2 Google Analytics 4 by Meetanshi is all you need.
Shivbhadrasinh Gohil
Shivbhadrasinh is the Co-founder & Chief Marketing Officer at Meetanshi. He leads the marketing team and is the person behind the marketing & branding success of the company. Being a seasoned digital marketer, he has been consulting online businesses for growth since 2010 and has helped 100+ clients with digital marketing success.
He loves sharing tips and insights about the latest digital marketing trends aimed at helping online business owners.
Prev
Best Resources to Learn Magento 2 From Scratch
Magento 2.3 End of Life [Everything You Need to Know]
Next