News:

Looking for documentation? Take a look on our wiki

Main Menu

Problem with analytics code at orderdone.php page

Started by depika, December 19, 2018, 11:27:31 AM

Previous topic - Next topic

depika

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

GJC Web Design

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
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation