Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

How To Add Onclick Gtag On The Place Order Button Rate Topic   - - - - -

 
  • mancup
  • Member
  • Members
  • Join Date: 27-Dec 12
  • 33 posts

Posted 31 January 2018 - 06:11 PM #1

Hello,

I must launch a google script upon PLACE ORDER button via onclick.
The Google exapmle is here :
<button onclick="return gtag_report_conversion()">Submit</button>

Problem is that in the place_order.tpl I cannot see how to code it, it is only smarty and I'm not used to it.
(design/themes/responsive/templates/buttons/place_order.tpl)
How can I trigger this script (gtag_report_conversion()) only on the place order button.
Please help me

Best regards

A JALABERT


 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 11248 posts

Posted 31 January 2018 - 08:40 PM #2

The normal place to do this is the hook for checkout:order_confirmation which will be used when the order is placed.

Note that if you attach it to the Place Order button, you will get erroneous data if the order is Declined or Fails.


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • mancup
  • Member
  • Members
  • Join Date: 27-Dec 12
  • 33 posts

Posted 01 February 2018 - 09:12 AM #3

Hello,

 

Ok can you help me to integrate the script into this hook ?
I'm a newbie on hook and I must launch that script on button or maybe on page loading order_complete :

<!-- Event snippet for CONVERSION_2018 conversion page
In your html page, add the snippet and call gtag_report_conversion when someone
clicks on the chosen link or button. -->
<script>
function gtag_report_conversion(url) {
  var callback = function () {
    if (typeof(url) != 'undefined') {
      window.location = url;
    }
  };
  gtag('event', 'conversion', {
      'send_to': 'AW-821528757/sXsxCKjx_HoQtZHehwM',
      'value': 1.0,
      'currency': 'EUR',
      'transaction_id': '',
      'event_callback': callback
  });
  return false;
}
</script>


 
  • galtinbaeva
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 06-Dec 13
  • 3302 posts

Posted 01 February 2018 - 09:31 AM #4

 

Hello,

 

Ok can you help me to integrate the script into this hook ?
I'm a newbie on hook and I must launch that script on button or maybe on page loading order_complete :

<!-- Event snippet for CONVERSION_2018 conversion page
In your html page, add the snippet and call gtag_report_conversion when someone
clicks on the chosen link or button. -->
<script>
function gtag_report_conversion(url) {
  var callback = function () {
    if (typeof(url) != 'undefined') {
      window.location = url;
    }
  };
  gtag('event', 'conversion', {
      'send_to': 'AW-821528757/sXsxCKjx_HoQtZHehwM',
      'value': 1.0,
      'currency': 'EUR',
      'transaction_id': '',
      'event_callback': callback
  });
  return false;
}
</script>

 

Hello!

 

You need to create the design/themes/YOUR_THEME/templates/addons/my_changes/hooks/checkout/order_confirmation.post.tpl file with the code you sent above. Do not forget to enable My changes add-on and clear cache.

 

All the order data is stored in the $order_info array, for example, order ID = {$order_info.order_id}, order total = {$order_info.total}


Simtech Development | sales@simtechdev.com | www.simtechdev.com
CERTIFIED CS-CART PARTNER | LICENSES | DEVELOPMENT | ADD-ONS | DESIGN | UPGRADE

Google Analytics Enhanced Ecommerce - get advanced ecommerce analytics


 
  • mancup
  • Member
  • Members
  • Join Date: 27-Dec 12
  • 33 posts

Posted 01 February 2018 - 09:40 AM #5

Ok Thanks but will this script launch itself alone or will I have to do a special thing to launch it.
As it is a normally launched upon OnClick on a button.

 

I mean is my_chnages will EXECUTE the script alone ?

 

Best regards

 

A JALABERT



 
  • mancup
  • Member
  • Members
  • Join Date: 27-Dec 12
  • 33 posts

Posted 01 February 2018 - 11:44 AM #6

Hello,

And if I want to execute this script on step 4 just when customer choose the payment methode ?

Thanks



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 19041 posts

Posted 01 February 2018 - 01:59 PM #7

You can use the checkout:final_section_customer_notes hook to execute script on the final step. The file with hook is located here

 

design/themes/responsive/templates/views/checkout/components/final_section.tpl

 

Since steps are loaded by ajax, do not forget to add the cm-ajax-force class to your script

 

http://docs.cs-cart....croformats.html

 

PS Possibly data-no-defer attribute will be also required

 

http://docs.cs-cart....pt_display.html


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 11248 posts

Posted 01 February 2018 - 07:48 PM #8

You can use the checkout:final_section_customer_notes hook to execute script on the final step. The file with hook is located here

 

design/themes/responsive/templates/views/checkout/components/final_section.tpl

 

Since steps are loaded by ajax, do not forget to add the cm-ajax-force class to your script

 

http://docs.cs-cart....croformats.html

 

PS Possibly data-no-defer attribute will be also required

 

http://docs.cs-cart....pt_display.html

 

And if the customer bails out of checkout before hitting submit then he will have sent an order confirmation with no order_id (assuming transaction_id in his example) and no order.  Strongly suggest he use the order_confirmation hook rather than trying to interpret the user's actions in the checkout process.


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 19041 posts

Posted 02 February 2018 - 11:07 AM #9

And if the customer bails out of checkout before hitting submit then he will have sent an order confirmation with no order_id (assuming transaction_id in his example) and no order.  Strongly suggest he use the order_confirmation hook rather than trying to interpret the user's actions in the checkout process.

 

I just answered on the question about payment methods step.


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.