For general GTM concepts, see the Google Tag Manager overview.
Prerequisites
- Google Tag Manager container created
- GTM Container ID (GTM-XXXXXXX)
- Duda site editing access
Installation
Method 1: Native GTM Integration (Recommended)
Duda has built-in GTM support:
- Open your site in Duda editor
- Go to Site Settings (gear icon)
- Navigate to Site Settings > Google Tag Manager
- Enter your Container ID (GTM-XXXXXXX)
- Click Save
- Publish your site
Benefits:
Method 2: Manual Code Injection
For custom configurations:
Head HTML:
- Go to Site Settings > Head HTML
- Paste the GTM head code:
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXXX');</script>
<!-- End Google Tag Manager -->
Body HTML: 3. Go to Site Settings > Body HTML 4. Paste the noscript fallback:
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
- Replace
GTM-XXXXXXXwith your container ID - Publish your site
Verification
Check Installation
- GTM Preview Mode: Click Preview in GTM, enter your Duda site URL
- Tag Assistant: Use browser extension
- View Page Source: Confirm GTM code in head and body
Preview Mode Steps
- In GTM, click Preview
- Enter your live Duda site URL
- Site opens with GTM debugger
- Verify "Container Found" message
- Check which tags are firing
Data Layer Configuration
Duda's Built-in Data Layer
Duda ecommerce sites have a built-in data layer via dmAPI:
// Available on ecommerce pages
window.dmAPI.getProductInfo() // Returns current product data
window.dmAPI.getCartInfo() // Returns cart data
// Example product data structure
{
"id": "product-123",
"name": "Product Name",
"price": 29.99,
"currency": "USD"
}
Custom Data Layer Events
Add custom data layer pushes in Head HTML:
<script>
window.dataLayer = window.dataLayer || [];
// Push page data
dataLayer.push({
'pageType': 'product',
'pageCategory': 'electronics'
});
</script>
Ecommerce Data Layer
For GA4 ecommerce via GTM:
<script>
document.addEventListener('DOMContentLoaded', function() {
// Check if on product page
if (window.dmAPI && window.dmAPI.getProductInfo) {
var product = window.dmAPI.getProductInfo();
if (product) {
dataLayer.push({
'event': 'view_item',
'ecommerce': {
'items': [{
'item_id': product.id,
'item_name': product.name,
'price': product.price,
'currency': product.currency || 'USD'
}]
}
});
}
}
});
</script>
Common Tags to Configure
Google Analytics 4
- Tags > New > GA4 Configuration
- Enter Measurement ID
- Trigger: All Pages
- Save and publish
Meta Pixel
- Tags > New > Custom HTML
- Paste Meta Pixel base code
- Trigger: All Pages
- Save and publish
Conversion Tracking
- Create conversion tags (Google Ads, Meta, etc.)
- Set triggers based on Duda events
- Use data layer variables for dynamic values
Trigger Examples
Add to Cart
Create a Custom Event trigger:
- Trigger Type: Custom Event
- Event Name:
add_to_cart
Then add this to Head HTML to fire the event:
<script>
document.addEventListener('DOMContentLoaded', function() {
// Listen for add to cart buttons (adjust selector as needed)
document.querySelectorAll('.add-to-cart-button').forEach(function(btn) {
btn.addEventListener('click', function() {
var product = window.dmAPI.getProductInfo();
dataLayer.push({
'event': 'add_to_cart',
'ecommerce': {
'items': [{
'item_id': product.id,
'item_name': product.name,
'price': product.price
}]
}
});
});
});
});
</script>
Form Submissions
- Create a Form Submission trigger in GTM
- Or use Custom Event with Duda form listener:
<script>
document.addEventListener('DOMContentLoaded', function() {
document.querySelectorAll('form').forEach(function(form) {
form.addEventListener('submit', function() {
dataLayer.push({
'event': 'form_submit',
'form_id': form.id || 'unknown'
});
});
});
});
</script>
Consent Mode
For GDPR compliance:
<!-- Add BEFORE GTM code in Head HTML -->
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('consent', 'default', {
'analytics_storage': 'denied',
'ad_storage': 'denied'
});
</script>
Update consent when user accepts:
gtag('consent', 'update', {
'analytics_storage': 'granted',
'ad_storage': 'granted'
});
Troubleshooting
GTM Not Loading
- Check container ID is correct
- Verify site is published
- Clear Duda's CDN cache
- Check for JavaScript errors
Tags Not Firing
- Use GTM Preview Mode
- Check trigger conditions
- Verify data layer values
- Confirm no consent blocking
Ecommerce Events Missing
- Verify on correct page type
- Check dmAPI availability
- Confirm data layer pushes working
- Test in browser console