Hello, I am trying to use the gtag.js conversion tracking code in opencart 1.5.6 and I have been able to get it to work sending the order value variables from the checkout controller to the success.tpl, but I can not seem to get them in the header.tpl from the header controller.
In the header.tpl i used a php if to show code on the checkout/success page sending the route and variables from the header controller, but it does not seem to be working. Can anyone assist with the code I would need to send the order value & id to the header.tpl along with the php if route statement to only show it on the success page (but in the header) ?
Thank you!
Marketplace request.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
This is the code I am trying to use in header.php:
This is the code from header.tpl:
Can anyone see why this may not be working?
Code: Select all
if (!empty($this->request->get['route'])) {
$data['route'] = $this->request->get['route'];
} else {
$data['route'] = '';
}
Code: Select all
<!-- Global site tag (gtag.js) - Google Ads: 1006202476 -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-36630190-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-36630190-1');
gtag('config', 'AW-1006202476');
</script>
<?php if (isset($route) && $route == 'checkout/success') { ?>
<!-- Event snippet for Purchase conversion page -->
<script>
gtag('event', 'conversion', {
'send_to': 'AW-1006202476/pAthCMzxuQgQ7Nzl3wM',
'value': <?php echo $total; ?>,
'currency': 'USD',
'transaction_id': <?php echo $order_id; ?>
});
</script>
Can anyone see why this may not be working?
Are you having a closing tag for if?
Use <?php echo var_dump($route); ?> to trace var value. Also you can remove isset because $route is set anyway
Use <?php echo var_dump($route); ?> to trace var value. Also you can remove isset because $route is set anyway
My extensions in marketplace. [ security | flexibility | speedup ]
Code: Select all
<?php if (isset($route) && $route == 'checkout/success') { ?>
Code: Select all
if (isset($this->request->get['route'])) && $this->request->get['route']) == 'checkout/success') {
if (isset($this->session->data['order_id'])) {
$this->load->model('checkout/order');
$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
if ($order_info) {
$this->data['ecommerce_analytics'] =
Then in the template.
Code: Select all
<?php if (!empty($ecommerce_analytics)) {
// Your analytics script
} ?>
Who is online
Users browsing this forum: No registered users and 123 guests