Post by ashon » Mon May 04, 2020 9:54 pm

OC 3.0.3.2

i have been trying to find a where to add the google ads Purchase tracking event i have done some google search and i found one that said to do this but its for a older version of OC so wanted to know if someone could help or guide me in the correct direction
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 this still work for success.twig ? if not is there a new way to do so


or can i just put the event code in the success.twig like so

Code: Select all

{{ header }}
<!-- Event snippet for Purchase conversion page -->
<script>
  gtag('event', 'conversion', {
      'send_to': 'AW-*********/************',
      'value': '{total}',
      'transaction_id': '{order_id}'
  });
</script>
above:

Code: Select all

<ul class="breadcrumb">
  {% for breadcrumb in breadcrumbs %}
  <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
  {% endfor %}
</ul>
{% if j3.settings.get('pageTitlePosition') == 'top' %}
  <h1 class="title page-title"><span>{{ heading_title }}</span></h1>
{% endif %}
{{ j3.loadController('journal3/layout', 'top') }}
<div id="common-success" class="container">
  <div class="row">{{ column_left }}
    {% if column_left and column_right %}
    {% set class = 'col-sm-6' %}
    {% elseif column_left or column_right %}
    {% set class = 'col-sm-9' %}
    {% else %}
    {% set class = 'col-sm-12' %}
    {% endif %}
    <div id="content" class="{{ class }}">
      {% if j3.settings.get('pageTitlePosition') == 'default' %}
        <h1 class="title page-title">{{ heading_title }}</h1>
      {% endif %}
      {{ content_top }}
      {{ text_message }}
      <div class="buttons">
        <div class="pull-right"><a href="{{ continue }}" class="btn btn-primary">{{ button_continue }}</a></div>
      </div>
      {{ content_bottom }}</div>
    {{ column_right }}</div>
</div>
{{ footer }}

Active Member

Posts

Joined
Sat Apr 18, 2015 2:18 am

Post by opencartmart » Mon May 04, 2020 10:02 pm

ashon wrote:
Mon May 04, 2020 9:54 pm

Code: Select all

<?php if (isset($this->request->get['route']) && $this->request->get['route'] == 'checkout/success') { ?>
<!-- tracking code goes here -->
<?php } ?>
You don't need to check whether it is the success page or not as you are on the success page already. For OC 3.x, just add your tracking code before the {{ footer }} tag in the success twig file e.g. catalog/view/THEME/template/common/success.twig . It will be something like:

Code: Select all

YOUR TRACKING CODE HERE
{{ footer }}
Update: Please check the updated answer below.
Last edited by opencartmart on Mon May 04, 2020 10:30 pm, edited 1 time in total.

XForm - Opencart Form Builder
Xshippingpro - An advanced Shipping Module
Need Professional support? Skype: opencartmart


Active Member

Posts

Joined
Wed Oct 02, 2013 3:59 am

Post by ashon » Mon May 04, 2020 10:05 pm

opencartmart wrote:
Mon May 04, 2020 10:02 pm
ashon wrote:
Mon May 04, 2020 9:54 pm

Code: Select all

<?php if (isset($this->request->get['route']) && $this->request->get['route'] == 'checkout/success') { ?>
<!-- tracking code goes here -->
<?php } ?>
This code is meaningless. You don't need to check whether it is the success page or not as you are on the success page already. For OC 3.x, just add your tracking code before the {{ footer }} tag in the success twig file e.g. catalog/view/THEME/template/common/success.twig . It will be something like:

Code: Select all

YOUR TRACKING CODE HERE
{{ footer }}
ok thank you will test that to see if it works and the reason people said for that code is because the contact us uses the same success.twig something like that

Active Member

Posts

Joined
Sat Apr 18, 2015 2:18 am

Post by opencartmart » Mon May 04, 2020 10:25 pm

ashon wrote:
Mon May 04, 2020 10:05 pm
ok thank you will test that to see if it works and the reason people said for that code is because the contact us uses the same success.twig something like that
Ooop!, you are right. I forgot the contact page. So you have to add one flag on the order success page. You can do as follows:

1. In the file, catalog/controller/checkout/success.php, Just after the following line:

Code: Select all

$data['continue'] = $this->url->link('common/home');
Add the following:

Code: Select all

$data['is_order'] = true;
Now you can use this `is_order variable`, in success. twig file. Example:

Code: Select all

  {% if is_order %}
      add your tracking code 
  {% endif %}

XForm - Opencart Form Builder
Xshippingpro - An advanced Shipping Module
Need Professional support? Skype: opencartmart


Active Member

Posts

Joined
Wed Oct 02, 2013 3:59 am

Post by straightlight » Mon May 04, 2020 10:33 pm

Or, use a /before event to paste the tracking code into a separate TWIG file while the order ID can be tracked in the success page. See this documentation on how to proceed: https://github.com/opencart/opencart/wiki/Events-System .

Never modify the controller files directly while an order ID can be tracked in from the Event Engine.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON


Posts

Joined
Sun Oct 15, 2023 6:37 pm
Who is online

Users browsing this forum: No registered users and 13 guests