Employing the tracking code in OpenCart 2
Employing the tracking code in OpenCart 2
A guide for the GTM setup for e-shops in OpenCart 2.
- connect to your hosting via FTP
- insert the click tracking code in the file catalog/view/theme/YOUR_THEME/template/common/footer.tpl
- in the file catalog/controller/checkout/confirm.php find the line containing: $data[‘totals’] = array(); and insert under it: $this->session->data[‘totals’] = $order_data[‘totals’];
- in the file catalog/controller/checkout/success.php find the line containing: if ($this->customer->isLogged()) { and insert above it: $data[‘pap4_orderid’] = $this->session->data[‘order_id’]; $data[‘pap4_totals’] = $this->session->data[‘totals’];
- in the file catalog/view/theme/default/template/common/success.tpl add the sale tracking code IN FRONT OF the line containing: “echo $footer;”:
- save the changes on hosting
Click tracking code
”XXXXXXXXXXX“ needs to be substituted for your account ID<script type="text/javascript" id="pap_x2s6df8d" src="https://login.dognet.sk/scripts/fj27g82d"></script>
<script type="text/javascript">
PostAffTracker.setAccountId('XXXXXXXXXXX');
try {
PostAffTracker.track();
} catch (err) { }
</script>
Sale tracking code
”XXXXXXXXXXX“ needs to be substituted for your account ID<?php
if(isset($pap4_totals) && isset($pap4_orderid)) {
$subtotal = 0;
foreach ($pap4_totals as $item) {
if ($item['code'] == 'sub_total') {$subtotal += $item['value'];}
if ($item['code'] == 'coupon') {$subtotal += $item['value'];}
if ($item['code'] == 'voucher') {$subtotal += $item['value'];}
}
if ($subtotal < 0) {$subtotal = 0;}
$subtotal = $subtotal / 1.27;
?>
<script type="text/javascript" id="pap_x2s6df8d" src="https://login.dognet.sk/scripts/fj27g82d"></script>
<script type="text/javascript">
PostAffTracker.setAccountId('XXXXXXXXXXX');
var sale = PostAffTracker.createSale();
sale.setTotalCost('<?php echo ((float)$subtotal / 1.2); ?>');
sale.setOrderID('<?php echo $pap4_orderid; ?>');
PostAffTracker.register();
</script>
<?php } ?>
In case you have VAT other than 20%, adjust division in the line sale.setTotalCost. 