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.
  1. connect to your hosting via FTP
  2. insert the click tracking code in the file catalog/view/theme/YOUR_THEME/template/common/footer.tpl
  3. 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’];
  4. 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’];
  5. in the file catalog/view/theme/default/template/common/success.tpl add the sale tracking code IN FRONT OF the line containing: “echo $footer;”:
  6. 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.
Katka Novotná

Viac ako dva roky som pracovala na pozícií e-commerce marketér a zvyšovala som obraty rôznym eshopom. Niektoré z nich sa vyšplhali až na Shop Roku (ocenenie od Heureka.sk). Mám skúsenosti s PPC Adwords aj Facebook. Analytics mi je veľmi blízky. Pre reklamnú agentúru Wiktor Leo Burnett som pomáhala s UX/UI webových projektov a aplikácií pre veľkých klientov. Vo voľnom čase tvorím webové stránky založené prevažne na WordPresse.

More articles that might interest you

Which campaigns are available in our network?