0

I have a google ads tag that is tracking my purchase for a woocommerce website. But inside the dataLayer I don't get the value or ordernumber back. I put this code inside my function.php:

function thankyou_page_tracking_code() { if ( ! is_wc_endpoint_url( 'order-received' ) ) { return; } ?> <script> gtag('event', 'conversion', { 'send_to': 'Here i write my number', 'value': 0.0, 'currency': 'EUR', 'transaction_id': '' }); </script> <?php } add_action( 'wp_footer', 'thankyou_page_tracking_code' ); 

But I don't see anything inside my dataLayer.

I do get an error that says (in dutch):
Variabele is als onwaar geretourneerd vanwege een onbekende fout tijdens de uitvoering
Total Ecommerce Items Value (price * quantity)
Which in english is:
Variable returned false due to an unknown error during execution
Total Ecommerce Items Value (price * quantity)

I tried multiple things but something like this:

function thankyou_page_tracking_code() { if ( ! is_wc_endpoint_url( 'order-received' ) ) { return; } // Haal de order ID op uit de URL $order_id = isset( $_GET['order-received'] ) ? $_GET['order-received'] : ''; // Haal de WooCommerce order op $order = wc_get_order( $order_id ); if ( ! $order ) { return; // Als de order niet bestaat, stop dan } // Haal de order totaal en valuta op $order_total = $order->get_total(); $currency = get_woocommerce_currency(); // Voeg de Google Ads tracking code toe met de juiste transaction_id, value en currency ?> <script> gtag('event', 'conversion', { 'send_to': 'here i write my number', 'value': <?php echo $order_total; ?>, 'currency': '<?php echo $currency; ?>', 'transaction_id': '<?php echo $order->get_id(); ?>' }); </script> <?php } add_action( 'wp_footer', 'thankyou_page_tracking_code' );` 

This makes the webshop not even go to purchase page. Anybody an idea?

0

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.