WooCommerce analytics
Before you can start collecting WooCommerce sales data, you will need to add the Fathom script to your site. To do that, follow our WordPress guide
Collecting data for purchases
- 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 ID in the example with your Event ID
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.trackGoal('YOUR-EVENT-ID', '<?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
If you still have questions or require help with anything, please reach out to us and we'll happily get things sorted out for you.