Google Analytics 4 Setup on PrestaShop
This guide covers all methods to implement Google Analytics 4 (GA4) on your PrestaShop store, from the easiest module-based installations to advanced manual implementations.
Before You Begin
Prerequisites:
- PrestaShop 1.7.x or 8.x (recommended)
- Active Google Analytics 4 property
- GA4 Measurement ID (format:
G-XXXXXXXXXX) - Back Office access with module installation permissions
- Basic understanding of PrestaShop's module system
Multi-Store Considerations:
- Decide if you need separate GA4 properties per store or shared tracking
- Configure each store context independently if using different properties
- Test cross-store navigation if sharing a property
Method 1: Official Google Analytics Module (Recommended for Most)
Installation via PrestaShop Addons
Step 1: Download and Install
- Navigate to Modules > Module Manager in your PrestaShop Back Office
- Search for "Google Analytics" or "Official Google Analytics"
- Click Install on the official module (usually free from PrestaShop Addons)
- Alternatively, download from PrestaShop Addons Marketplace
Step 2: Basic Configuration
Back Office > Modules > Module Manager > Google Analytics > Configure
Required Settings:
- Google Analytics Tracking ID: Enter your
G-XXXXXXXXXXmeasurement ID - Enable Tracking: Toggle ON
- Anonymize IP: Enable for GDPR compliance (recommended)
- Enable eCommerce Tracking: Toggle ON for transaction tracking
Step 3: Advanced Options
// Common module settings
{
"enhanced_ecommerce": true, // Enable Enhanced Ecommerce
"track_internal_traffic": false, // Exclude admin IP addresses
"cross_domain_tracking": false, // Enable only if needed
"userid_tracking": false, // Track logged-in customer IDs
"debug_mode": false // Enable only during testing
}
Configuration Tips:
- User ID Tracking: Enable if you want to track customer behavior across devices
- Internal Traffic: Add your office/admin IP addresses to exclusion list
- Cross-Domain: Only enable if you have multiple domains sharing analytics
- Debug Mode: Use temporarily to verify data collection
Multi-Store Configuration
For Separate Properties Per Store:
- Navigate to Shop Parameters > General > Multi-store
- Select specific store context from top-left dropdown
- Configure Google Analytics module with store-specific Measurement ID
- Repeat for each store in your multi-store setup
- Verify each store sends to correct GA4 property
For Shared Property:
- Use "All Shops" context in multi-store dropdown
- Configure once with single Measurement ID
- Enable content grouping to differentiate stores in reports
- Add custom dimension for
shop_idto segment data
Verifying Installation
Test Tracking:
- Open your store in incognito/private browsing mode
- Open browser developer tools (F12)
- Go to Network tab and filter for "collect" or "gtag"
- Navigate through your store (homepage, product, cart)
- Verify GA4 requests are firing with correct Measurement ID
Check Real-Time Reports:
- Go to Google Analytics > Reports > Realtime
- Browse your store in another tab
- Confirm activity appears within 30 seconds
- Verify page views and events are recording
Hook Registration
The official module typically registers these hooks:
// Front Office hooks
public function install()
{
return parent::install()
&& $this->registerHook('displayHeader')
&& $this->registerHook('displayFooter')
&& $this->registerHook('displayOrderConfirmation')
&& $this->registerHook('actionFrontControllerSetMedia')
&& $this->registerHook('displayProductAdditionalInfo')
&& $this->registerHook('displayShoppingCart');
}
Method 2: Third-Party GA4 Modules
Several developers offer enhanced GA4 modules with additional features:
Popular Third-Party Options
1. Presta Module's GA4 Enhanced
- Features: Server-side tracking, enhanced ecommerce, custom events
- Price: Typically $39-99 (one-time or subscription)
- Best For: Advanced tracking needs, custom event requirements
- Support: Usually includes premium support and updates
2. eBusiness Guru GA4 Pro
- Features: Data layer integration, GTM compatibility, advanced attribution
- Price: $49-129
- Best For: Stores using GTM or complex multi-channel attribution
- Support: Documentation and ticket support
3. Community Modules (Free/Open Source)
- Source: GitHub, PrestaShop forums
- Features: Vary by developer
- Best For: Developers comfortable customizing code
- Support: Community forums, limited official support
Evaluating Third-Party Modules
Before Purchase/Installation:
Check Compatibility:
- Verify PrestaShop version support (1.6.x, 1.7.x, 8.x)
- Check PHP version requirements
- Review theme compatibility notes
- Test in staging environment first
Review Features:
- Does it support all GA4 ecommerce events?
- Can it handle multi-store configurations?
- Does it offer server-side tracking?
- Is there custom event support?
Assess Quality:
- Read user reviews and ratings
- Check update frequency (updated within last 6 months?)
- Review developer's support responsiveness
- Look for documentation quality
Consider Performance:
Installation Process
Standard Third-Party Module Installation:
- Download: Purchase and download module ZIP file
- Upload:
Back Office > Modules > Module Manager > Upload a Module - Install: Click install button after upload completes
- Configure: Navigate to module configuration page
- Test: Verify tracking in GA4 DebugView
Manual Installation (Advanced):
# Via FTP/SSH
cd /path/to/prestashop/modules/
unzip ga4_module.zip
chown -R www-data:www-data ga4_module/
chmod -R 755 ga4_module/
# Set proper permissions
find ga4_module/ -type f -exec chmod 644 {} \;
find ga4_module/ -type d -exec chmod 755 {} \;
Then activate via Back Office Module Manager.
Method 3: Manual Template Integration
For developers who want complete control over GA4 implementation.
Adding GA4 Tracking Code to Theme
Step 1: Locate Your Theme's Header Template
# Classic theme (default)
themes/classic/templates/_partials/head.tpl
# Custom theme
themes/your-theme-name/templates/_partials/head.tpl
Step 2: Add GA4 Global Site Tag
Edit head.tpl and add before </head>:
{* Google Analytics 4 *}
{if !isset($smarty.cookies.cookie_consent) || $smarty.cookies.cookie_consent == 'accepted'}
<!-- 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', {
'send_page_view': true,
'anonymize_ip': true,
{if $customer.is_logged}
'user_id': '{$customer.id|escape:'javascript':'UTF-8'}'
{/if}
});
</script>
{/if}
Step 3: Handle Cookie Consent
PrestaShop requires GDPR compliance. Adjust GA4 loading based on consent:
{* Only load GA4 if consent given *}
<script>
document.addEventListener('DOMContentLoaded', function() {
// Check for cookie consent
if (typeof prestashop !== 'undefined' && prestashop.gdprConsent) {
if (prestashop.gdprConsent.analytics) {
loadGA4();
}
}
});
function loadGA4() {
var script = document.createElement('script');
script.async = true;
script.src = 'https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX';
document.head.appendChild(script);
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX', {
'anonymize_ip': true
});
}
</script>
Using PrestaShop Override System
Create Custom Module for GA4:
// modules/customga4/customga4.php
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
class CustomGA4 extends Module
{
public function __construct()
{
$this->name = 'customga4';
$this->tab = 'analytics_stats';
$this->version = '1.0.0';
$this->author = 'Your Name';
$this->need_instance = 0;
parent::__construct();
$this->displayName = $this->l('Custom GA4 Integration');
$this->description = $this->l('Custom Google Analytics 4 tracking implementation');
$this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_);
}
public function install()
{
Configuration::updateValue('CUSTOMGA4_MEASUREMENT_ID', '');
Configuration::updateValue('CUSTOMGA4_ANONYMIZE_IP', 1);
return parent::install()
&& $this->registerHook('displayHeader')
&& $this->registerHook('displayOrderConfirmation');
}
public function uninstall()
{
Configuration::deleteByName('CUSTOMGA4_MEASUREMENT_ID');
Configuration::deleteByName('CUSTOMGA4_ANONYMIZE_IP');
return parent::uninstall();
}
public function getContent()
{
$output = '';
if (Tools::isSubmit('submitCustomGA4')) {
Configuration::updateValue('CUSTOMGA4_MEASUREMENT_ID', Tools::getValue('CUSTOMGA4_MEASUREMENT_ID'));
Configuration::updateValue('CUSTOMGA4_ANONYMIZE_IP', Tools::getValue('CUSTOMGA4_ANONYMIZE_IP'));
$output .= $this->displayConfirmation($this->l('Settings updated'));
}
return $output . $this->displayForm();
}
public function displayForm()
{
$fields_form = array(
'form' => array(
'legend' => array(
'title' => $this->l('GA4 Settings'),
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Measurement ID'),
'name' => 'CUSTOMGA4_MEASUREMENT_ID',
'required' => true,
'desc' => $this->l('Your GA4 Measurement ID (G-XXXXXXXXXX)')
),
array(
'type' => 'switch',
'label' => $this->l('Anonymize IP'),
'name' => 'CUSTOMGA4_ANONYMIZE_IP',
'values' => array(
array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Yes')),
array('id' => 'active_off', 'value' => 0, 'label' => $this->l('No'))
)
)
),
'submit' => array(
'title' => $this->l('Save'),
)
)
);
$helper = new HelperForm();
$helper->module = $this;
$helper->name_controller = $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex . '&configure=' . $this->name;
$helper->submit_action = 'submitCustomGA4';
$helper->fields_value['CUSTOMGA4_MEASUREMENT_ID'] = Configuration::get('CUSTOMGA4_MEASUREMENT_ID');
$helper->fields_value['CUSTOMGA4_ANONYMIZE_IP'] = Configuration::get('CUSTOMGA4_ANONYMIZE_IP');
return $helper->generateForm(array($fields_form));
}
public function hookDisplayHeader()
{
$measurement_id = Configuration::get('CUSTOMGA4_MEASUREMENT_ID');
if (empty($measurement_id)) {
return '';
}
$anonymize = Configuration::get('CUSTOMGA4_ANONYMIZE_IP');
$this->context->smarty->assign(array(
'ga4_measurement_id' => $measurement_id,
'ga4_anonymize_ip' => $anonymize,
'customer_id' => $this->context->customer->isLogged() ? $this->context->customer->id : null
));
return $this->display(__FILE__, 'views/templates/hook/header.tpl');
}
}
Create Template File:
{* modules/customga4/views/templates/hook/header.tpl *}
<!-- Google Analytics 4 -->
<script async src="https://www.googletagmanager.com/gtag/js?id={$ga4_measurement_id|escape:'html':'UTF-8'}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{$ga4_measurement_id|escape:'javascript':'UTF-8'}', {
'send_page_view': true
{if $ga4_anonymize_ip}, 'anonymize_ip': true{/if}
{if $customer_id}, 'user_id': '{$customer_id|escape:'javascript':'UTF-8'}'{/if}
});
</script>
Multi-Store Implementation
Scenario 1: Different GA4 Properties Per Store
Configuration Approach:
// In your module or template
$shop_id = (int)Context::getContext()->shop->id;
// Map shop IDs to measurement IDs
$measurement_ids = array(
1 => 'G-XXXXXXXXX1', // Main store
2 => 'G-XXXXXXXXX2', // Second brand
3 => 'G-XXXXXXXXX3' // Regional store
);
$measurement_id = isset($measurement_ids[$shop_id]) ? $measurement_ids[$shop_id] : '';
Scenario 2: Single GA4 Property with Store Segmentation
Add Store Context to Tracking:
gtag('config', 'G-XXXXXXXXXX', {
'content_group': '{$shop.name|escape:'javascript':'UTF-8'}',
'custom_map': {
'dimension1': 'shop_id',
'dimension2': 'shop_group'
},
'shop_id': '{$shop.id|escape:'javascript':'UTF-8'}',
'shop_group': '{$shop.id_shop_group|escape:'javascript':'UTF-8'}'
});
Troubleshooting
Common Issues
1. Tracking Not Working After Installation
Check:
- Clear PrestaShop cache:
rm -rf var/cache/* - Regenerate templates: Back Office > Advanced Parameters > Performance > Clear cache
- Verify module is enabled in Module Manager
- Check browser console for JavaScript errors
- Confirm Measurement ID is correct format (G-XXXXXXXXXX)
2. Duplicate Tracking / Double Counting
Cause: Multiple GA4 implementations active simultaneously
Fix:
- Check if both module and manual code are present
- Verify only one module is active
- Search theme templates for multiple gtag.js instances
- Use GA4 DebugView to identify duplicate hits
3. Module Conflicts
Common Conflicts:
- Multiple analytics modules active
- Page builder modules modifying header
- Cache modules blocking script injection
- Cookie consent modules preventing tracking
Resolution:
- Disable conflicting modules one by one
- Check module hook priority/execution order
- Review module compatibility matrix
- Contact module developer for compatibility patches
Performance Optimization
Async Loading Best Practices
{* Load GA4 asynchronously to avoid blocking render *}
<script>
(function() {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = 'https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX');
</script>
Caching Compatibility
PrestaShop Smarty Cache:
- GA4 code should not be cached with dynamic data
- Use
{nocache}tags for customer-specific variables - Regenerate cache after configuration changes
Full Page Cache (Varnish, Redis):
- Ensure tracking codes load client-side
- Don't cache pages with conversion tracking
- Use ESI (Edge Side Includes) for personalized content
Next Steps
Now that GA4 is installed, configure event tracking and ecommerce:
- GA4 Event Tracking - Track user interactions
- GA4 Ecommerce Tracking - Track sales and revenue
- GTM Setup - Advanced tag management alternative
For troubleshooting, see:
- Events Not Firing - Debug tracking issues