How To Add Onclick Gtag On The Place Order Button

Hello,

I must launch a google script upon PLACE ORDER button via onclick.
The Google exapmle is here :
Submit

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

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.

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 :


            

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 :


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}

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

Hello,

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

Thanks

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.com/4.1.x/core/front-end/microformats.html

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

http://docs.cs-cart.com/4.7.x/user_guide/look_and_feel/changing_attributes/script_display.html

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.com/4.1.x/core/front-end/microformats.html

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

http://docs.cs-cart.com/4.7.x/user_guide/look_and_feel/changing_attributes/script_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.

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.