Hi Stan,
Is OPC sending Tracking coupon code to Analytics? We are using AwoCoupon and when i go to analytics i don't see my coupon codes?
Thanks
<script>
gtag('event', 'purchase', {
'transaction_id': '<?php echo $this->escapeSingle($idformat); ?>',
'affiliation': '<?php echo $this->escapeSingle($this->vendor['company']); ?>',<?php
$app = JFactory::getApplication();
if ($app->getName() === 'administrator') {
?>
'non_interaction': true, <?php
} ?>
'value': <?php echo number_format($order_total, 2, '.', ''); ?>,
'currency': '<?php echo $this->escapeSingle($this->currency['currency_code_3']); ?>',
'tax': <?php echo number_format($this->order['details']['BT']->order_tax, 2, '.', ''); ?>,
'shipping': <?php echo number_format($this->order['details']['BT']->order_shipment, 2, '.', ''); ?>,
'coupon': '<?php if (!empty($this->order['details']['BT']->coupon_code)) echo $this->escapeSingle($this->order['details']['BT']->coupon_code); ?>',
'items': <?php
$max = count($this->order['items']);
$i = 0;
$items = array();
foreach ($this->order['items'] as $key=>$order_item)
{
$product_id = $order_item->pid;
$i++;
if (empty($order_item->category_name)) $order_item->category_name = '';
if (!empty($order_item->virtuemart_category_name)) $order_item->category_name = $order_item->virtuemart_category_name;
$json = array();
$json['id'] = (string)$product_id;
$json['name'] = $order_item->order_item_name;
$json['list_name'] = 'Purchase';
$json['brand'] = '';
$json['category'] = $order_item->category_name;
$json['variant'] = $order_item->order_item_sku;
$json['list_position'] = $i;
$json['price'] = (float)number_format($order_item->product_final_price, 2, '.', '');
$json['quantity'] = (int)number_format($order_item->product_quantity , 0, '.', '');
if (!empty($this->order['details']['BT']->coupon_code))
$json['coupon'] = $this->order['details']['BT']->coupon_code;
$items[] = $json;
}
echo json_encode($items, JSON_PRETTY_PRINT);
?> });
<?php
$root = Juri::root();
if (substr($root, -1) !== '/') $root .= '/';
if (empty($this->params->page_url)) $this->params->page_url = '/thank-you';
if (substr($this->params->page_url, 0, 1) === '/') $cart_path = substr($this->params->page_url, 1);
else {
$cart_path = $this->params->page_url;
$this->params->page_url = '/'.$this->params->page_url;
}
if (empty($this->params->page_title)) $this->params->page_title = 'OPC Checkout';
if (empty($GLOBALS['_gtag'])) {
$GLOBALS['_gtag'] = new stdClass();
$GLOBALS['_gtag']->page_title = $this->params->page_title;
$GLOBALS['_gtag']->page_location = $root.$cart_path;
$GLOBALS['_gtag']->page_path = $this->params->page_url;
}
if (!empty($this->params->adwrods_conversion_id)) { ?>
gtag('event', 'conversion', {
'send_to': '<?php echo $this->params->google_analytics_id; ?>/<?php echo $this->params->adwrods_conversion_id; ?>',
'value': <?php echo number_format($order_total, 2, '.', ''); ?>,
'currency': '<?php echo $this->escapeSingle($this->currency['currency_code_3']); ?>',
'transaction_id': '<?php echo $this->escapeSingle($idformat); ?>',
<?php
$app = JFactory::getApplication();
if ($app->getName() === 'administrator') {
?> 'non_interaction': true <?php
}
?>
});
<?php } ?>
if ((typeof console != 'undefined') && (typeof console.log != 'undefined') && (console.log != null))
{
console.log('OPC Tracking gtag: Purchase.');
}
</script>
dataLayer.push({
'ecommerce': {
'purchase': {
'actionField': {
'id': '<?php echo $this->escapeSingle($idformat); ?>', // Transaction ID. Required for purchases and refunds.
'affiliation': '<?php echo $this->escapeSingle($this->vendor['company']); ?>',
'revenue': <?php echo number_format($order_total, 2, '.', ''); ?>, // Total transaction value (incl. tax and shipping)
'tax': <?php echo number_format($this->order['details']['BT']->order_tax, 2, '.', ''); ?>,
'shipping': <?php echo number_format($this->order['details']['BT']->order_shipment, 2, '.', ''); ?>,
'coupon': '<?php if (!empty($this->order['details']['BT']->coupon_code)) echo $this->escapeSingle($this->order['details']['BT']->coupon_code); ?>'
},
'products': [<?php
$max = count($this->order['items']);
$i = 0;
foreach ($this->order['items'] as $key=>$order_item)
{
$product_id = $order_item->pid;
$i++;
if (empty($order_item->category_name)) $order_item->category_name = '';
if (!empty($order_item->virtuemart_category_name)) $order_item->category_name = $order_item->virtuemart_category_name;
?>{
'name': '<?php echo $this->escapeSingle($order_item->order_item_name); ?>',
'id': '<?php echo $this->escapeSingle($product_id); ?>',
'price': <?php echo number_format($order_item->product_final_price, 2, '.', ''); ?>,
'brand': '',
'category': '<?php echo $this->escapeSingle($order_item->category_name ); ?>',
'variant': '<?php echo $this->escapeSingle($order_item->order_item_sku); ?>',
'quantity': <?php echo number_format($order_item->product_quantity , 0, '.', ''); ?>,
'coupon': '<?php if (!empty($this->order['details']['BT']->coupon_code)) echo $this->escapeSingle($this->order['details']['BT']->coupon_code); ?>'
}<?php if ($i !== $max) echo ','; ?>
<?php } ?>]
}
}
});