Hello
I am trying to add google analytics code at the orderdone.php thank you page so that google can track the orders.
Here is the code I have added so far
// GET ORDER DETAILS
defined('DS') or define('DS', DIRECTORY_SEPARATOR);
if (!class_exists( 'VmConfig' )) require(JPATH_ROOT .'/administrator/components/com_virtuemart/helpers/config.php');
if(!class_exists('VmModel'))require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'vmmodel.php');
$order_model = VmModel::getModel('orders');
$myorder = $order_model->getOrder($virtuemart_order_id);
$orderTotal = $myorder['details']['BT']->order_total;
$myTagString = "gtag('event', 'purchase', {
\"transaction_id\": \"$virtuemart_order_id \", // order ID - required
\"affiliation\": \"Sfragidadiko.gr\", // affiliation or store name
\"order_total\": $orderTotal , // total - required
\"order_tax\":, // tax
\"order_shipping\": // shipping
});
";
$doc = JFactory::getDocument();
$doc->addScriptDeclaration( $myTagString );
However when I submit the order all the values are blank. Here is what I get as a return
<script type="text/javascript">
gtag('event', 'purchase', {
"transaction_id": " ", // order ID - required
"affiliation": "Sfragidadiko.gr", // affiliation or store name
"order_total": " ", // total - required
"order_tax":, // tax
"order_shipping": // shipping
});
</script>
I have also tried $this->cart>virtuemart_order_id and $order_id
What am I doing wrong? I would appreciate your help
echo out $myorder to see whats in it
the object returned to orderdone.php is $html and also check $this etc to see what is available