Setting Up Google Analytics 4 & Tag Manager in Hyvä for Magento 2

Setting Up Google Analytics 4 & Tag Manager in Hyvä for Magento 2

If you're running an online store on Magento 2 and using the Hyvä theme, you're already ahead of the curve when it comes to performance and user experience. But high speed and clean UI are just the beginning — to really scale, you need data. That’s where Google Analytics 4 (GA4) and Google Tag Manager (GTM) come in. In this guide, we’ll walk you through setting up GA4 and GTM in Hyvä for Magento 2 — so you can start collecting actionable insights, tracking user behavior, and boosting conversions. Whether you're a developer or a merchant working with a trusted Magento agency in Berlin, this setup will form the backbone of your analytics strategy.

Why Hyvä + GA4 + GTM Is a Game-Changer for E-commerce 

Hyvä has revolutionized Magento frontend development by replacing bloated Luma themes with lightning-fast, clean, and modular code. But its streamlined approach also means it doesn’t include many of the traditional built-in integrations — like Google Tag Manager or GA4 scripts.  That’s not a bad thing. In fact, it’s a huge opportunity: you get more control, better performance, and no extra JavaScript bloat. By integrating Google Analytics 4 via GTM, you’ll be able to: 
  • Track enhanced eCommerce events (like add to cart, purchases, etc.) 
  • Run marketing campaigns with better attribution 
  • Set up custom conversions and funnels 
  • Reduce reliance on third-party tracking extensions 

What You Need Before You Start 

Make sure you have the following: 
  • A Magento 2 store running with the Hyvä theme
  • Access to your store’s codebase
  • A Google Analytics 4 property set up
  • A Google Tag Manager container created
  • Admin access to Magento 2 backend
Pro Tip: If you're working with a professional Magento 2 service provider, ask them to give you access to preview environments where you can test GTM tags safely.  Step-by-Step: Setting Up GTM in Hyvä  Step 1: Add GTM Code Snippets to Your Theme  Unlike Luma-based Magento 2 stores, Hyvä doesn’t have a GTM module out of the box. So you’ll need to add the GTM container manually in your custom layout.  GTM Head snippet: Insert this in the <head> section of your default_head_blocks.xml or custom layout file:  xml  Copy  <referenceContainer name="head.additional">      <block class="Magento\Framework\View\Element\Template" name="gtm_head" template="Magento_Theme::html/gtm-head.phtml"/>  </referenceContainer>  Then create a file gtm-head.phtml with the GTM head code from your container.  GTM Body snippet: Insert in default.xml or the layout where your <body> tag is rendered:  xml  Copy  <referenceContainer name="after.body.start">      <block class="Magento\Framework\View\Element\Template" name="gtm_body" template="Magento_Theme::html/gtm-body.phtml"/>  </referenceContainer>  And create the corresponding gtm-body.phtml. 

Step 2: Configure Your GTM Container 

Log into Google Tag Manager and add a GA4 Configuration tag using your GA4 measurement ID.
  1. Click "Add a new tag" 
  1. Choose GA4 Configuration 
  1. Enter your Measurement ID 
  1. Set the trigger to All Pages 
  1. Save and publish the container 
This sends page view data to GA4 across your Magento store. 

Adding eCommerce Tracking for Magento 2 

GA4 is event-based, so to go beyond page views, you’ll want to configure: 
  • View Item 
  • Add to Cart 
  • Begin Checkout 
  • Purchase 
You can either write custom dataLayer pushes in Magento templates or use third-party modules that support Hyvä (like Anowave, Scommerce, or custom-developed modules). Here’s an example of pushing product view data:  html  Copy  <script>  window.dataLayer = window.dataLayer || [];  window.dataLayer.push({    event: 'view_item',    ecommerce: {      items: [{        item_name: 'Bluebell Wedding Dress',        item_id: 'SKU12345',        price: 999.99,        item_category: 'Wedding Dresses'      }]    }  });  </script>  Place this script inside your product template, e.g., Magento_Catalog/templates/product/view.phtml. 

Testing Your GA4 & GTM Setup 

Don’t skip this step. Use the GTM Preview mode and the GA4 DebugView to ensure data is flowing correctly. Tools to verify: 
  • Google Tag Assistant
  • GA4 Realtime Dashboard
  • Chrome DevTools > Network > collect

How a Magento Agency in Berlin Can Help 

Working with a local Magento agency in Berlin ensures your store is built, customized, and tracked with precision. Whether it’s deploying Hyvä, optimizing for Core Web Vitals, or integrating GA4 with GTM, an experienced Magento 2 service team can make sure you’re getting clean data and scalable infrastructure. Benefits of working with a professional partner: 
  • Custom tag development 
  • Debugging and QA environments 
  • Ongoing analytics consulting 
  • Integration with marketing tools like Facebook Pixel, TikTok, LinkedIn Ads, and more 
Common Pitfalls to Avoid 
  • Not configuring Consent Mode for GDPR compliance 
  • Forgetting to load dataLayer before GTM triggers 
  • Using deprecated Universal Analytics tags 
  • Not enabling enhanced measurement in GA4 
Final Thoughts  Setting up Google Analytics 4 and Tag Manager in Hyvä for Magento 2 gives you full visibility into your customer journey while keeping your site lightweight and blazing fast. It’s a must-have for eCommerce businesses serious about growth. If you need expert help, look no further than a certified Magento agency in Berlin with a deep understanding of Hyvä development and Magento 2 services. When done right, analytics isn’t just a tool — it’s your growth engine.

Frequently Asked Questions (FAQs) 

What’s the difference between GA4 and Universal Analytics for Magento?  GA4 is event-driven, more flexible, and future-proof. Universal Analytics was session-based and is now sunset by Google.  Do I need a developer to set up GTM and GA4 in Hyvä?  If you’re comfortable editing layout files and HTML, you can do it yourself. But for advanced tracking, working with a Magento 2 service provider is recommended.  Is Hyvä compatible with all Magento extensions?  Not always. You’ll need to check if the extension supports Hyvä or has a fallback integration. Analytics and GTM usually require manual setup or module support. 

Latest Post

This site is registered on wpml.org as a development site. Switch to a production site key to remove this banner.