How to Add Google Analytics 4 to Duda | OpsBlu Docs

How to Add Google Analytics 4 to Duda

Install GA4 on your Duda website using the built-in analytics widget or head code injection. Covers Measurement ID and multi-site tracking.

For general GA4 concepts and features, see the Google Analytics 4 overview.

Prerequisites

  • Google Analytics 4 property created
  • GA4 Measurement ID (G-XXXXXXXXXX)
  • Duda site editing access

Installation Methods

Duda has built-in Google Analytics support:

  1. Open your site in Duda editor
  2. Go to Site Settings (gear icon)
  3. Navigate to Site Settings > Google Analytics
  4. Enter your GA4 Measurement ID (G-XXXXXXXXXX)
  5. Click Save
  6. Publish your site

Benefits of native integration:

  • Automatic setup
  • Duda-optimized loading
  • No code to maintain
  • Works with ecommerce

Method 2: Head HTML Injection

For more control or custom configurations:

  1. Go to Site Settings > Head HTML
  2. Paste the GA4 code:
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'G-XXXXXXXXXX');
</script>
  1. Replace G-XXXXXXXXXX with your Measurement ID
  2. Click Save
  3. Publish your site

Method 3: Via Google Tag Manager

If using GTM for tag management:

  1. Install GTM first: GTM Setup for Duda
  2. Add GA4 Configuration tag in GTM
  3. No additional Duda configuration needed

Configuration

Enhanced Measurement

GA4's Enhanced Measurement automatically tracks:

  • Page views
  • Scrolls (90% depth)
  • Outbound link clicks
  • Site search
  • Video engagement
  • File downloads

Enable/disable in GA4 Admin > Data Streams > Enhanced Measurement.

Ecommerce Tracking

Duda's ecommerce provides automatic data layer events:

// Duda's dmAPI provides product data
window.dmAPI.getProductInfo();  // Current product
window.dmAPI.getCartInfo();     // Cart contents

For GA4 ecommerce, use GTM with triggers based on Duda's data layer.

Custom Dimensions

Track Duda-specific data:

// Example: Track page template type
gtag('config', 'G-XXXXXXXXXX', {
  'custom_map': {
    'dimension1': 'page_template'
  },
  'page_template': 'product_page'
});

Verification

Check Installation

  1. View Page Source: Search for "gtag.js" or your Measurement ID
  2. GA4 Realtime: Check Admin > Reports > Realtime
  3. Google Tag Assistant: Use browser extension

Common Issues

No data in GA4:

  • Verify Measurement ID is correct
  • Check site is published (not just saved)
  • Clear Duda's CDN cache
  • Test in incognito mode

Duplicate pageviews:

  • Check for multiple GA4 implementations
  • Remove manual code if using native integration
  • Verify GTM isn't firing duplicate tags

Multi-Language Sites

For Duda sites with multiple languages:

// Track language as custom parameter
gtag('config', 'G-XXXXXXXXXX', {
  'custom_map': {
    'dimension2': 'content_language'
  },
  'content_language': document.documentElement.lang
});

Cross-Domain Tracking

If using multiple domains:

gtag('config', 'G-XXXXXXXXXX', {
  'linker': {
    'domains': ['site1.com', 'site2.com']
  }
});

Next Steps