php - google enhanced conversionInsert javascript code into the head tags of the woocommerce thank you page
one text
<script>
dataLayer.push({
'enhanced_conversion_data': {
"email": 'customerBillingEmail',
"phone_number": 'customerBillingPhone'
}
});
</script>
How can I add this code to the code below? How can I set up google enhanced conversion.
Thank you in advance for your help.
add_action( 'wp_head', 'my_google_conversion' );
function my_google_conversion(){
// On Order received endpoint only
if( is_wc_endpoint_url( 'order-received' ) ) :
$order_id = absint( get_query_var('order-received') ); // Get order ID
if( get_post_type( $order_id ) !== 'shop_order' ) return; // Exit
$order = wc_get_order( $order_id ); // Get the WC_Order Object instance
?>
<script>
gtag('event', 'conversion', {
'send_to': 'AW-746876528/x5W1CLfA8JoBEPDckeQC',
'value': <?php echo $order->get_total(); ?>,
'currency': '<?php echo $order->get_currency(); ?>',
'transaction_id': '<?php echo $order_id; ?>'
});
</script>
<?php
endif;
}
Source