Post by heane33 » Wed Sep 19, 2018 3:22 am

Hi, I'm trying to add the google ad conversion tracking code to track conversions on the website.

I see the below code suggested but this was from 2012. I'm using opencart 3.0.2.0. Does anyone know if below code is still good or work with my version?

-------------------
In the file catalog/view/theme/*/template/common/success.tpl
-------------------

Code: Select all

<?php if (isset($this->request->get['route']) && $this->request->get['route'] == 'checkout/success') { ?>

<!-- tracking code goes here -->

<?php } ?>
-------------------
Does there need to be any kind of update or change since this was suggested code for an older version of OC?

Thanks.
Last edited by straightlight on Wed Mar 04, 2020 6:53 am, edited 1 time in total.

New member

Posts

Joined
Thu Aug 11, 2016 6:24 am

Post by heane33 » Wed Sep 19, 2018 3:36 am

From what I understand, the PHP part of the code is there to prevent it from counting a conversion for some action other than an actual website sale (such as account creation, visitor using contact form, etc) since that file is called upon in those instances too.

Appreciate if anyone has any insight if the code is still good as-is or if it needs a tweak.

Thanks.

New member

Posts

Joined
Thu Aug 11, 2016 6:24 am

Post by paulfeakins » Wed Sep 19, 2018 5:46 pm

heane33 wrote:
Wed Sep 19, 2018 3:36 am
Appreciate if anyone has any insight if the code is still good as-is or if it needs a tweak.
Well no it definitely won't work because success.tpl is now success.twig and that won't accept PHP.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Guru Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by heane33 » Thu Sep 20, 2018 9:03 am

I do see I have a file named 'success.tpl' though? I do also see a 'success.twig' file as well but assume they have different purposes since they are both there?

Either way, the code doesn't seem to work. Any idea for any change that's needed to make it work?

New member

Posts

Joined
Thu Aug 11, 2016 6:24 am

Post by heane33 » Thu Sep 20, 2018 9:05 am

And is that to say that I need to add the google tracking and conversion code to the success.twig file? And not the success.php file?

New member

Posts

Joined
Thu Aug 11, 2016 6:24 am

Post by khnaz35 » Thu Sep 20, 2018 11:59 am

heane33 wrote:
Thu Sep 20, 2018 9:05 am
And is that to say that I need to add the google tracking and conversion code to the success.twig file? And not the success.php file?
I guess the easiest way will be edit from Default Extension which should be there have a look here it looks like this http://prntscr.com/kwh31j

Urgent Questions shoot here: khnaz35@gmail.com
Enjoy nature ;) :) :-*


User avatar
Active Member

Posts

Joined
Mon Aug 27, 2018 11:30 pm
Location - Malaysia

Post by heane33 » Thu Sep 20, 2018 12:36 pm

Thanks but I already saw that and from what I can tell, that only puts the google global tracking code on all pages. I know the google conversion code should only be placed on the page you want to count as a conversion, which for most people should be the page a customer goes to after a sale, which should be the success.tpl page from what I saw. Does anyone know differently? Or can anyone confirm?

Thanks.

New member

Posts

Joined
Thu Aug 11, 2016 6:24 am

Post by khnaz35 » Thu Sep 20, 2018 6:46 pm

heane33 wrote:
Thu Sep 20, 2018 12:36 pm
Thanks but I already saw that and from what I can tell, that only puts the google global tracking code on all pages. I know the google conversion code should only be placed on the page you want to count as a conversion, which for most people should be the page a customer goes to after a sale, which should be the success.tpl page from what I saw. Does anyone know differently? Or can anyone confirm?

Thanks.
Try to fire the trigger via google tag manager if it could help

Urgent Questions shoot here: khnaz35@gmail.com
Enjoy nature ;) :) :-*


User avatar
Active Member

Posts

Joined
Mon Aug 27, 2018 11:30 pm
Location - Malaysia

Post by heane33 » Fri Sep 21, 2018 12:51 pm

Currently not using Tag Manager. Prefer not to just to keep things simple where I only use things I currently need. And I don't believe it's necessary since instructions mention a way to do this without it.

I believe it's possible to manually put the conversion code on the 'thank you' success page to count the conversion which I believe should be success.tpl? Can anyone please confirm if that is the correct file to modify, to insert the conversion tracking code so it tracks a conversion after each sale is made?

Thanks all!

New member

Posts

Joined
Thu Aug 11, 2016 6:24 am

Post by khnaz35 » Fri Sep 21, 2018 7:38 pm

heane33 wrote:
Wed Sep 19, 2018 3:22 am
Hi, I'm trying to add the google ad conversion tracking code to track conversions on the website.

I see the below code suggested but this was from 2012. I'm using opencart 3.0.2.0. Does anyone know if below code is still good or work with my version?

-------------------
In the file catalog/view/theme/*/template/common/success.tpl
-------------------

Code: Select all

<?php if (isset($this->request->get['route']) && $this->request->get['route'] == 'checkout/success') { ?>

<!-- tracking code goes here -->

<?php } ?>
-------------------
Does there need to be any kind of update or change since this was suggested code for an older version of OC?

Thanks.
Are you referring to Enhanced E commerce code ?

Urgent Questions shoot here: khnaz35@gmail.com
Enjoy nature ;) :) :-*


User avatar
Active Member

Posts

Joined
Mon Aug 27, 2018 11:30 pm
Location - Malaysia

Post by heane33 » Sat Sep 22, 2018 12:18 am

I'm talking about this. Screenshot from google ads below.

Attachments

g1.jpg

g1.jpg (140.25 KiB) Viewed 7941 times


New member

Posts

Joined
Thu Aug 11, 2016 6:24 am

Post by khnaz35 » Sat Sep 22, 2018 3:16 pm

heane33 wrote:
Sat Sep 22, 2018 12:18 am
I'm talking about this. Screenshot from google ads below.
I believe this code should go to your header.tpl file not in the Success.tpl

Urgent Questions shoot here: khnaz35@gmail.com
Enjoy nature ;) :) :-*


User avatar
Active Member

Posts

Joined
Mon Aug 27, 2018 11:30 pm
Location - Malaysia

Post by heane33 » Sun Sep 23, 2018 1:31 pm

Thanks, I'll take a look at that file there too. Thank you!

New member

Posts

Joined
Thu Aug 11, 2016 6:24 am

Post by pprmkr » Sun Sep 23, 2018 2:52 pm

heane33 wrote:
Sat Sep 22, 2018 12:18 am
I'm talking about this. Screenshot from google ads below.
Do you load global tag.js file elsewhere ?

First edit catalog/controller/checkout/success.php:
After:

Code: Select all

if (isset($this->session->data['order_id'])) {
Paste:

Code: Select all

			$data['transaction_id'] = $this->session->data['order_id'];
			$data['cart_total'] = $this->cart->getTotal();
Then edit catalog/view/theme/default/template/common/success.twig:
Before:

Code: Select all

{{ footer }}
Paste:

Code: Select all

{% if transaction_id is defined %}
	transaction ID = {{ transaction_id }}
	cart Total = {{ cart_total }}
	Use these values if needed as parameter in tag.js
	for example:
	<!-- Event snippet for Example conversion page -->
    <script>
      gtag('event', 'conversion', {'send_to': 'AW-123456789/AbC-D_efG-h12_34-567',
        'value': {{ cart_total }},
        'currency': 'USD',
        'transaction_id': '{{ transaction_id }}'
      });
    </script>

{% endif %}
Edit code to fit your needs.

User avatar
Active Member
Online

Posts

Joined
Sat Jan 08, 2011 11:05 pm
Location - Netherlands

Post by heane33 » Tue Sep 25, 2018 12:43 am

Thank you! :)

New member

Posts

Joined
Thu Aug 11, 2016 6:24 am

Post by yysds » Thu Nov 01, 2018 10:37 pm

Hello pprmkr,

Thank you for instruction. I modified the code to fit my needs as below. But It doesn't work. Can you help me to fix my mistake if you see?

Code: Select all

{% if transaction_id is defined %}
	transaction ID = {{ transaction_id }}
	cart Total = {{ cart_total }}
		
	<script async src="https://www.googletagmanager.com/gtag/js?id=AW-127432541"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'AW-127432541');
</script>
	
	<!-- Event snippet for Example conversion page -->
    <script>
      gtag('event', 'conversion', {'send_to': 'AW-127432541/nOT_KLWhjjsjsJWAeh0IeH',
        'value': {{ cart_total }},
        'currency': 'TRY',
        'transaction_id': '{{ transaction_id }}'
      });
    </script>

{% endif %}

Newbie

Posts

Joined
Thu Nov 01, 2018 10:19 pm

Post by pprmkr » Fri Nov 02, 2018 6:07 pm

Remove:

Code: Select all

	transaction ID = {{ transaction_id }}
	cart Total = {{ cart_total }}
Strange syntax with spaces ?

User avatar
Active Member
Online

Posts

Joined
Sat Jan 08, 2011 11:05 pm
Location - Netherlands

Post by khnaz35 » Fri Nov 02, 2018 9:12 pm

:( :( ???
where to put enhance eCommerce tracking code
https://developers.google.com/tag-manag ... -ecommerce

Urgent Questions shoot here: khnaz35@gmail.com
Enjoy nature ;) :) :-*


User avatar
Active Member

Posts

Joined
Mon Aug 27, 2018 11:30 pm
Location - Malaysia

Post by MarcelO » Tue Mar 26, 2019 4:32 pm

Hi, i followed your instructions. But there goes something wrong in the last part. If i try to edit with the webeditor from opencart the success.twig i get an error as soon as I insert the <script> part. I can save and edit the .twig files. Only if I try to ad a script i got an error like this:

Code: Select all

Forbidden
Forbidden
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /admin/index.php
on this server.<br />
</p>
<hr>
<address>Apache Server at www.elektroscout.ch Port 443</address>
</body></html>
Any Ideas why this is?

I can edit the file manually via ftp, but i think the file is also not accepted and the changes ar ignored. Any help would be highly appreciated. thanks a lot.

Newbie

Posts

Joined
Tue Mar 26, 2019 4:23 pm

Post by screwtape_mk » Fri May 29, 2020 6:50 am

did you end up winning here. i need to accomplish the same thing

New member

Posts

Joined
Sun May 14, 2017 2:39 am
Who is online

Users browsing this forum: nonnedelectari and 390 guests