Advertisement
borlabs

WooCommerce Tracking Code

Nov 13th, 2022 (edited)
1,074
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.63 KB | None | 0 0
  1. add_action('woocommerce_thankyou', 'my_custom_tracking');
  2.  
  3. function my_custom_tracking($order_id) {
  4.     $order = wc_get_order( $order_id );
  5.    
  6.     $fbqCode = "<script>fbq('track', 'Purchase');</script>";
  7.     $googleAnalyticsCode = "<script>gtag('event', 'conversion', {
  8.            'send_to': 'AW-608570056/jkryCPDw7_ACEMiVmKIC',
  9.            'value': ".$order->get_total().",
  10.            'currency': 'USD',
  11.            'transaction_id': ''
  12.        });</script>";
  13.  
  14.     echo BorlabsCookieHelper()->blockCookie($fbqCode, 'facebook-pixel');
  15.     echo BorlabsCookieHelper()->blockCookie($googleAnalyticsCode, 'google-analytics');
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement