Browse help articles
Support home / Integrations

WooCommerce

Before you begin: Create your Fathom account and add your website to get its site ID. Already have one? You’re ready to follow the steps below.

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

  1. First of all, you will need the Code Snippets WordPress plugin if you don’t already have it installed
  2. Once it’s installed, click ‘Snippets’ in the admin sidebar
  3. Click Add New snippet
  4. 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

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
}
  1. Click Save changes and activate and your event will now start collecting data on each successful order, including the total order price
  2. 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

Ready to check your setup? Visit your published website, then open its Fathom dashboard to check for your first pageview. If it doesn’t appear, our installation troubleshooting guide will help.

Find help with setup, your analytics, or your account.