GDPR compliance and analytics for Joomla websites with VirtueMart e-commerce.
Works with Joomla 3.x, 4.x, 5.x and VirtueMart 3.x, 4.x
/templates/YOUR_TEMPLATE/index.php</head><!-- 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><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>Create template override at templates/YOUR_TEMPLATE/html/com_virtuemart/productdetails/default.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><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>Add to templates/YOUR_TEMPLATE/html/com_virtuemart/orders/details.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; ?>CONSETO auto-detects Joomla language:
| Joomla Locale | CONSETO |
|---|---|
sk-SK | sk |
cs-CZ | cz |
en-GB | en |
de-DE | de |
pl-PL | pl |
hu-HU | hu |
window.conseto is availabledebug: trueUpdate imports for Joomla 4+:
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
$app = Factory::getApplication();
$lang = substr($app->getLanguage()->getTag(), 0, 2);