-
klintensiv2021
Hello,
how can I add a google purchease script to thank you page with elements?
Page: https://klintensiv.ro/checkout/order-received/
Script:
<!– Event snippet for Achizitii Site conversion page –>
<script>
gtag(‘event’, ‘conversion’, {
‘send_to’: ‘AW-798760367/PbC3CM644ckCEK-78PwC’,
‘value’: 1.0,
‘currency’: ‘RON’,
‘transaction_id’: ”
});
</script>Thank you!
Costin -
David
Hi there,
in Appearance > Elements -> Add New –> HOOK, see here:
https://docs.generatepress.com/article/hooks-element-overview/
Add your script to the text area.
Set the Display Rules to the site locations where you require ie eg.Entire Site
Then set the Hook to either:
a.
wp_head
for adding the code to the site<head>
b.wp_footer
for adding the code to the site<footer>
-
klintensiv2021
Hello,
Thx. I need the hook, only on a specific page.
This page: https://klintensiv.ro/checkout/order-received/How can I do dhis?
Thank you! -
Alvind
Hi there,
You can set that in the Element’s Location settings. Instead of Entire Site, choose Page and select the order received page.
-
klintensiv2021
hi, I did not have an order recieve page in the element list.
This page (https://klintensiv.ro/checkout/order-received/) is automatet created by woocomerce.Also, I need to insert value of order in this page.
<!-- Event snippet for Achizitii Site conversion page --> <script> gtag('event', 'conversion', { 'send_to': '', 'value': 1.0, 'currency': 'RON', 'transaction_id': '' }); </script>
-
David
You would need to use a PHP snippet to do that:
// Add the script to the head section of the order-received page function add_conversion_tracking_script() { // Check if it's the order-received page if (is_wc_endpoint_url('order-received')) { // Get the current order ID $order_id = absint( get_query_var('order-received') ); // Check if order ID is valid if ($order_id > 0) { // Get the order object $order = wc_get_order($order_id); // Get the transaction ID $transaction_id = $order->get_order_number(); // Output the script with transaction ID ?> <!-- Event snippet for Achizitii Site conversion page --> <script> gtag('event', 'conversion', { 'send_to': '', 'value': 1.0, 'currency': 'RON', 'transaction_id': '<?php echo esc_js($transaction_id); ?>' }); </script> <?php } } } add_action('wp_head', 'add_conversion_tracking_script');
- You must be logged in to reply to this topic.