This module seamlessly integrates Google Tag Manager (GTM) with automatic Google Analytics 4 (GA4) configuration into your PrestaShop store. When both GTM Container ID and GA4 Measurement ID are provided, the module creates a powerful dual-tracking setup that combines GTM's tag management capabilities with GA4's advanced analytics features.
- ✅ Dual Integration: GTM + GA4 working together seamlessly
- ✅ Smart Auto-Configuration: GA4 automatically configured within GTM dataLayer
- ✅ Zero Code Required: Complete setup through admin panel
- ✅ Enhanced Analytics: Advanced GA4 tracking with GTM flexibility
- ✅ Enterprise-Ready: Secure, validated, and performance-optimized
- ✅ PrestaShop 8.x Compatible with backward compatibility to 7.1+
- ✅ Professional Implementation following Google's best practices
Traditional Setup Problems:
- Multiple tracking codes slow down pages
- Conflicting analytics implementations
- Complex manual configuration required
Our Solution:
- Single GTM container loads everything
- GA4 configured automatically inside GTM
- Perfect harmony between GTM and GA4
- Optimal performance with maximum features
- PrestaShop 1.7.1.0 or higher (recommended: 8.0+)
- PHP 7.4 or higher
- Valid Google Tag Manager container
- Valid Google Analytics 4 property
- Basic understanding of GTM/GA4 (helpful but not required)
- Download the latest release
- Upload to
/modules/gtmmodule/in your PrestaShop installation - Navigate to Modules & Services → Module Manager
- Search for "Google Tag Manager with GA4"
- Click Install
cd /path/to/your/prestashop/modules/
git clone https://github.com/your-username/prestashop-gtm-ga4-module.git gtmmoduleThen install through PrestaShop admin panel.
GTM Container ID:
- Log into Google Tag Manager
- Select your container
- Copy the Container ID (format:
GTM-XXXXXXX)
GA4 Measurement ID:
- Log into Google Analytics 4
- Go to Admin → Data Streams → Web
- Copy the Measurement ID (format:
G-XXXXXXXXXX)
- Go to Modules & Services → Module Manager
- Find "Google Tag Manager with GA4" and click Configure
- Enter your GTM Container ID (required)
- Enter your GA4 Measurement ID (optional but recommended)
- Click Save
With GTM ID only:
- GTM container loads normally
- Ready for manual tag configuration in GTM
With GTM + GA4 IDs:
- GTM container loads with GA4 pre-configured
- Automatic page tracking enabled
- Enhanced measurement activated
- GA4 events available in GTM dataLayer
- Perfect integration achieved ✨
The module uses PrestaShop's hook system for optimal placement:
Header Hook (displayHeader):
<script>
// Initialize dataLayer
window.dataLayer = window.dataLayer || [];
// GTM initialization with GA4 auto-config
window.dataLayer.push({
'gtm.start': new Date().getTime(),
'event': 'gtm.js'
});
// GA4 auto-configuration (when ID provided)
window.dataLayer.push({
'event': 'ga4_init',
'ga4_measurement_id': 'G-XXXXXXXXXX',
'page_title': document.title,
'page_location': window.location.href
});
// Load GTM container
(function(w,d,s,l,i){...})(window,document,'script','dataLayer','GTM-XXXXXXX');
</script>Body Hook (displayAfterBodyOpeningTag):
<noscript>
<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXXX"
height="0" width="0" style="display:none;visibility:hidden">
</iframe>
</noscript>gtmmodule/
├── gtmmodule.php # Main module class
├── README.md # Documentation
├── views/
│ └── templates/
│ ├── admin/
│ │ └── config_info.tpl # Admin panel info
│ └── hook/
│ ├── gtm_header.tpl # Header implementation
│ └── gtm_body.tpl # Noscript fallback
└── index.php # Security protection
When GA4 Measurement ID is provided, the module automatically enables:
- Page Views: Automatic tracking of all page visits
- User Sessions: Complete user journey tracking
- Enhanced Measurement: Advanced user interactions
- Scroll Tracking: 90% scroll depth events
- Outbound Clicks: External link tracking
- File Downloads: PDF, DOC, ZIP download tracking
- Site Search: Internal search query tracking
- Video Engagement: YouTube/Vimeo interaction tracking
- Purchase Events: Ready for transaction tracking
- Add to Cart: Shopping behavior tracking
- Product Views: Catalog interaction tracking
- Custom Events: Fully customizable through GTM
- Input Validation: Strict format validation for all IDs
- XSS Protection: All output properly escaped
- SQL Injection Prevention: Safe database operations
- Access Control: Admin-only configuration
- Asynchronous Loading: No blocking of page rendering
- Minimal Overhead: Lightweight implementation
- Core Web Vitals: Optimized for Google's performance metrics
- Caching Friendly: Works with all PrestaShop cache systems
GTM Container ID:
- Pattern:
GTM-[A-Z0-9]+ - Example:
GTM-ABC123 - Required: Yes
GA4 Measurement ID:
- Pattern:
G-[A-Z0-9]+ - Example:
G-ABC123DEFG - Required: No (but recommended)
- Clear, actionable error messages
- Format examples provided
- Multilingual support through PrestaShop translation system
❌ GTM not loading
✅ Check Container ID format (GTM-XXXXXXX)
✅ Verify GTM container is published
✅ Clear PrestaShop cache
✅ Check browser console for errors
❌ GA4 not tracking
✅ Verify GA4 Measurement ID format (G-XXXXXXXXXX)
✅ Check Google Analytics Real-time reports
✅ Ensure GA4 property is active
✅ Test with Google Analytics Debugger extension
❌ Configuration not saving
✅ Check admin permissions
✅ Verify database connectivity
✅ Clear PrestaShop cache
✅ Check server error logs
Add temporary debugging to gtmmodule.php:
// Add after line 142 for debugging
error_log('GTM ID: ' . Configuration::get('GTM_CONTAINER_ID'));
error_log('GA4 ID: ' . Configuration::get('GA4_MEASUREMENT_ID'));| Version | Compatibility | Status |
|---|---|---|
| 8.1.x | ✅ Fully Tested | Recommended |
| 8.0.x | ✅ Fully Tested | Recommended |
| 7.8.x | ✅ Compatible | Supported |
| 7.4+ | ✅ Compatible | Supported |
| 7.1-7.3 | Limited |
- Default Themes: 100% compatible
- Custom Themes: Compatible if hooks are properly implemented
- Third-party Themes: Generally compatible
- Chrome, Firefox, Safari, Edge (latest versions)
- Internet Explorer 11+ (limited)
- Mobile browsers (iOS Safari, Chrome Mobile)
Recommended GTM Setup:
- Create GA4 Configuration tag using the dataLayer variables
- Set up Enhanced E-commerce tracking
- Configure custom events based on your needs
- Use GTM Preview mode to test everything
DataLayer Variables Available:
ga4_measurement_id- Your GA4 IDpage_title- Current page titlepage_location- Current page URLgtm.start- GTM initialization timestamp
For advanced users, you can extend the module:
// Hook into the module's output
public function hookActionModuleGtmBeforeOutput($params)
{
// Add custom dataLayer variables
$params['custom_data'] = [
'user_type' => 'premium',
'page_category' => 'product'
];
}- 🆓 Completely Free: No limitations, no premium versions
- 🔓 Open Source: MIT License, modify as needed
- 🤝 Community Driven: Contributions welcome
- 📈 Commercial Use: Fully permitted
- Fork the repository
- Create a feature branch
- Follow PSR-2 coding standards
- Test thoroughly
- Submit pull request
- Documentation: Check this README first
- GitHub Issues: Report bugs and feature requests
- Community: PrestaShop forums and communities
- Professional Support: Available via email
- ✅ Enhanced GA4 integration with smart dataLayer configuration
- ✅ Improved validation and error handling
- ✅ Better admin interface with clear instructions
- ✅ Performance optimizations
- ✅ Security enhancements
- ✅ Added GA4 auto-configuration
- ✅ Dual GTM+GA4 setup
- ✅ Enhanced measurement support
- ✅ Initial GTM integration
- ✅ Basic admin configuration
- ✅ Hook implementation
- 🛒 Enhanced E-commerce: Automatic purchase tracking
- 📊 Custom Events: GUI for event configuration
- 🔄 Data Import: Import existing GTM configurations
- 📱 Mobile App: Integration with PrestaShop mobile apps
- 🌐 Multi-store: Advanced multi-store support
Need custom implementation or advanced setup?
Contact for Professional Support:
- 📧 Email: dzemal.imamovic@outlook.com
- 🔧 Fiverr: https://www.fiverr.com/s/yvazVAG
- 🔧 Services: Custom GTM/GA4 implementations, advanced tracking setup
- 💼 Enterprise: Large-scale deployments, custom integrations
If this module helps your business, please star it on GitHub! Your support helps us continue developing free tools for the PrestaShop community.
You can support my work by buying me a coffee or donating via PayPal. Every bit helps and is much appreciated!
Made with ❤️ for the PrestaShop community
Free Forever • Open Source • Enterprise Ready
Perfect Analytics Setup: GTM + GA4 working in harmony, configured automatically, no coding required.