First of all, you will need the Code Snippets WordPress plugin if you don’t already have it installed
Once it’s installed, click ‘Snippets’ in the admin sidebar
Click Add New snippet
Make sure the Function tab is selected, and then paste the following code into the textbox:
Note: Make sure to replace the dummy Event Name in the example with your desired Event Name
Copy
Ask AI
add_action( 'woocommerce_thankyou', 'sales_order_tracking' );function sales_order_tracking( $order_id ) { // Get the order details $order = wc_get_order( $order_id ); // Convert the order total to cents $order_total = $order->get_total() * 100; // Trigger the event on page load and add the order total to the event ?> <script> window.addEventListener('load', (event) => { fathom.trackEvent('YOUR-EVENT-NAME', { _value: '<?php echo $order_total ?>', }); }); </script> <?php}
Click Save changes and activate and your event will now start collecting data on each successful order, including the total order price
To check if your event is working, create a successful order and navigate through to the thank you/success page. Once you have done that, check your Fathom dashboard to see if the event completion and the relevant value was recorded