DocsIntegrationsJoomla / VirtueMart Integration
Integrations

Joomla / VirtueMart Integration

Overview

GDPR compliance and analytics for Joomla websites with VirtueMart e-commerce.

Difficulty: Medium

Works with Joomla 3.x, 4.x, 5.x and VirtueMart 3.x, 4.x

Installation Methods

Method 1: Template Override (Recommended)

  1. Navigate to /templates/YOUR_TEMPLATE/
  2. Edit index.php
  3. Add CONSETO script before </head>
php
<!-- CONSETO GDPR & Analytics -->
<script src="https://www.conseto.io/dist/conseto.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', async function() {
    const conseto = await Conseto.init({
        clientId: '<?php echo $this->params->get('conseto_client_id', 'YOUR_CLIENT_ID'); ?>',
        language: '<?php echo substr(JFactory::getLanguage()->getTag(), 0, 2); ?>',
        theme: 'dark',
        autoTrackEcommerce: true,
        <?php if ($ga4 = $this->params->get('ga4_id')): ?>
        ga4: '<?php echo $ga4; ?>',
        <?php endif; ?>
        brandName: '<?php echo JFactory::getConfig()->get('sitename'); ?>',
        privacyPolicyUrl: '/privacy-policy'
    });

    window.conseto = conseto;
});
</script>

Method 2: Custom HTML Module

  1. Go to Extensions → Modules → New
  2. Select Custom HTML
  3. Set position to head
  4. Add the code below (set "Prepare Content" = No)
html
<script src="https://www.conseto.io/dist/conseto.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', async function() {
    const conseto = await Conseto.init({
        clientId: 'YOUR_CLIENT_ID',
        language: 'sk',
        theme: 'dark',
        autoTrackEcommerce: true
    });
    window.conseto = conseto;
});
</script>

VirtueMart: Product View Tracking

Create template override at templates/YOUR_TEMPLATE/html/com_virtuemart/productdetails/default.php

php
<?php
// Add at the end of default.php
$product = $this->product;
$price = VmConfig::get('show_price') ? $product->prices['salesPrice'] : 0;
$currency = CurrencyDisplay::getInstance()->getCurrencySymbol();
?>

<script>
document.addEventListener('DOMContentLoaded', function() {
    if (window.conseto) {
        window.conseto.track('view_item', {
            item_id: '<?php echo $product->virtuemart_product_id; ?>',
            item_name: '<?php echo addslashes($product->product_name); ?>',
            item_category: '<?php echo addslashes($product->category_name ?? ''); ?>',
            item_brand: '<?php echo addslashes($product->mf_name ?? ''); ?>',
            price: <?php echo (float)$price; ?>,
            currency: '<?php echo $currency; ?>'
        });
    }
});
</script>

VirtueMart: Add to Cart Tracking

php
<script>
// Hook into VirtueMart cart update
if (typeof Virtuemart !== 'undefined') {
    var originalUpdateCart = Virtuemart.updateCart;
    Virtuemart.updateCart = function() {
        var form = document.querySelector('form.addtocart');
        if (form && window.conseto) {
            var productId = form.querySelector('[name="virtuemart_product_id[]"]').value;
            var quantity = form.querySelector('[name="quantity[]"]').value || 1;

            window.conseto.track('add_to_cart', {
                item_id: productId,
                item_name: '<?php echo addslashes($this->product->product_name); ?>',
                price: <?php echo (float)$this->product->prices['salesPrice']; ?>,
                quantity: parseInt(quantity)
            });
        }
        return originalUpdateCart.apply(this, arguments);
    };
}
</script>

VirtueMart: Order Confirmation

Add to templates/YOUR_TEMPLATE/html/com_virtuemart/orders/details.php:

php
<?php
$session = JFactory::getSession();
$orderTracked = $session->get('conseto_order_' . $this->orderDetails['details']['BT']->virtuemart_order_id, false);

if (!$orderTracked):
    $order = $this->orderDetails['details']['BT'];
    $items = $this->orderDetails['items'];
    $session->set('conseto_order_' . $order->virtuemart_order_id, true);
?>
<script>
document.addEventListener('DOMContentLoaded', function() {
    if (window.conseto) {
        window.conseto.trackConversion('purchase', {
            transaction_id: '<?php echo $order->order_number; ?>',
            value: <?php echo (float)$order->order_total; ?>,
            currency: '<?php echo $order->order_currency; ?>',
            tax: <?php echo (float)$order->order_tax; ?>,
            shipping: <?php echo (float)$order->order_shipment; ?>,
            items: [
                <?php foreach ($items as $item): ?>
                {
                    item_id: '<?php echo $item->virtuemart_product_id; ?>',
                    item_name: '<?php echo addslashes($item->order_item_name); ?>',
                    price: <?php echo (float)$item->product_final_price; ?>,
                    quantity: <?php echo (int)$item->product_quantity; ?>
                },
                <?php endforeach; ?>
            ]
        });
    }
});
</script>
<?php endif; ?>

Multilingual Support

CONSETO auto-detects Joomla language:

Joomla LocaleCONSETO
sk-SKsk
cs-CZcz
en-GBen
de-DEde
pl-PLpl
hu-HUhu

Troubleshooting

Consent banner not showing
  • Check browser console for JavaScript errors
  • Verify Client ID is correct
  • Clear Joomla and browser cache
  • Check for conflicting JavaScript
VirtueMart events not tracking
  • Verify template overrides are in correct location
  • Check that window.conseto is available
  • Enable debug mode: debug: true
  • Check Network tab for API calls
Joomla 4/5 compatibility

Update imports for Joomla 4+:

php
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;

$app = Factory::getApplication();
$lang = substr($app->getLanguage()->getTag(), 0, 2);
CONSETO - GDPR Compliance & Web Analytics