OpenCart 3 Google Analytics Setup Guide | OpsBlu Docs

OpenCart 3 Google Analytics Setup Guide

Complete guide to setting up Google Analytics on OpenCart 3. Install GA4 using the built-in module, marketplace extensions, or manual template.

Overview

OpenCart provides multiple ways to integrate Google Analytics 4 (GA4):

  • Built-in Google Analytics module (OpenCart 3.x+)
  • Third-party marketplace extensions with enhanced features
  • Manual template modification for custom implementations

Method 1: Built-in Google Analytics Module

Prerequisites

  • OpenCart 3.0 or higher
  • Admin access to OpenCart
  • GA4 Measurement ID (format: G-XXXXXXXXXX)

Installation Steps

  1. Access the Extensions Manager

    Admin Panel > Extensions > Extensions
    
  2. Filter by Analytics

    • In the "Choose the extension type" dropdown, select Analytics
    • Locate "Google Analytics" in the list
  3. Install the Extension

    • Click the green Install button (+ icon)
    • The button will change to an Edit button (pencil icon)
  4. Configure Google Analytics

    • Click the Edit button
    • Enter your Google Analytics Code (Measurement ID: G-XXXXXXXXXX)
    • Set Status to Enabled
    • Click Save

Built-in Module Limitations

The default OpenCart Google Analytics module has several limitations:

Method 2: Marketplace Extensions

1. Enhanced Google Analytics 4 by iSenseLabs

  • Full GA4 ecommerce tracking
  • Automatic event configuration
  • User properties and custom dimensions
  • Server-side tracking option

2. Google Analytics 4 Pro by Opencart.Expert

Installing Marketplace Extensions

  1. Access OpenCart Marketplace

    https://www.opencart.com/index.php?route=marketplace/extension
    
  2. Purchase and Download

    • Search for "Google Analytics 4"
    • Purchase the extension
    • Download the extension file (usually .ocmod.zip or .zip)
  3. Upload Extension

    Admin Panel > Extensions > Installer
    
    • Click Upload button
    • Select your downloaded extension file
    • Wait for successful upload confirmation
  4. Install via Extension Installer

    Admin Panel > Extensions > Extensions > Analytics
    
    • Find your newly uploaded extension
    • Click Install (+ icon)
    • Click Edit (pencil icon) to configure
  5. Configure Extension Settings

    • Enter GA4 Measurement ID
    • Enable ecommerce tracking
    • Configure event parameters
    • Set user consent options (GDPR)
    • Save configuration

Method 3: Manual Template Modification

For custom implementations or when extensions don't meet requirements:

1. Locate Header Template

OpenCart uses an MVC architecture. The header template is located at:

catalog/view/theme/[your-theme]/template/common/header.twig

For default theme:

catalog/view/theme/default/template/common/header.twig

2. Add GA4 Tracking Code

Edit the header.twig file and add before the closing </head> tag:

{# Google Analytics 4 #}
<!-- 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,
    'cookie_domain': 'auto',
    'cookie_flags': 'SameSite=None;Secure'
  });
</script>

3. Create OCMOD for Future-Proof Installation

To preserve modifications across updates, use OpenCart's OCMOD system:

Create file: ga4-tracking.ocmod.xml

<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>Google Analytics 4 Tracking</name>
    <code>ga4_tracking</code>
    <version>1.0</version>
    <author>Your Name</author>
    <link>https://yourwebsite.com</link>

    <file path="catalog/view/theme/*/template/common/header.twig">
        <operation>
            <search><![CDATA[</head>]]></search>
            <add position="before"><![CDATA[
<!-- 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>
            ]]></add>
        </operation>
    </file>
</modification>

Install OCMOD:

  1. Upload ga4-tracking.ocmod.xml via:

    Admin Panel > Extensions > Installer
    
  2. Refresh modifications:

    Admin Panel > Extensions > Modifications
    

    Click the Refresh button (circular arrow icon)

  3. Clear cache:

    Admin Panel > Dashboard > click the blue gear icon (top-right)
    Select both cache options and click Clear
    

Verification

Check Installation

  1. Visit your storefront in a browser
  2. Open Developer Tools (F12)
  3. Go to Network tab
  4. Filter by "analytics" or "gtag"
  5. Refresh the page
  6. Verify you see requests to:
    • www.googletagmanager.com/gtag/js
    • www.google-analytics.com/g/collect

Real-Time Testing

  1. Go to Google Analytics > Reports > Realtime
  2. Visit your storefront in another tab
  3. Verify you appear in real-time users
  4. Check that page views are recorded

Common Issues

Extension Not Appearing

Problem: Installed extension doesn't show in Analytics list

Solution:

  1. Check PHP version compatibility (OpenCart 3.x requires PHP 7.0+)
  2. Verify file permissions:
    chmod 644 system/library/
    chmod 644 catalog/controller/extension/analytics/
    
  3. Check error logs:
    Admin Panel > System > Maintenance > Error Logs
    

Tracking Code Not Loading

Problem: GA4 code doesn't appear in page source

Solution:

  1. Clear OpenCart cache
  2. Refresh modifications
  3. Check theme compatibility
  4. Verify extension status is "Enabled"

Multiple Tracking Codes

Problem: GA4 tracking code appears multiple times

Solution:

  1. Disable all GA extensions except one
  2. Check for manual code in theme files
  3. Review active OCMODs:
    Admin Panel > Extensions > Modifications
    

Multi-Store Setup

For OpenCart multi-store configurations:

  1. Access Store Settings

    Admin Panel > System > Settings
    
  2. Select Store to Configure

    • Click Edit for each store
  3. Configure GA4 Per Store

    • Each store can have a different Measurement ID
    • Or use the same ID with custom dimensions to separate data
  4. Extension Configuration

    • Most extensions support multi-store
    • Configure tracking per store in extension settings

Next Steps

Additional Resources