Skip to content

Install Statsdot on WooCommerce

Updated October 16, 2026

WooCommerce runs on WordPress, so the snippet goes in exactly as in the WordPress guide: a header plugin or your child theme. Read its part on caching plugins too, since shops often use them.

Count purchases

The order received page has the order number in its address (/checkout/order-received/123/), and Statsdot matches page goals by their exact path. So instead of a page goal, send an event when that page loads. Add this to your child theme's functions.php or as a PHP snippet in a plugin such as WPCode:

add_action('woocommerce_thankyou', function ($order_id) {
    if (! $order_id) {
        return;
    }

    echo "<script>document.addEventListener('DOMContentLoaded', function () { window.statsdot && window.statsdot.track('Purchase'); });</script>";
});

The snippet in the head loads with defer, so the event waits for DOMContentLoaded, when the script is ready. Do not add the order number or the customer's name as a label: Statsdot works without personal data, and your events should too.

If an optimisation plugin delays JavaScript, exclude this inline script as well as statsdot.com/js/script.js.

Turn it into a goal

In the site's Settings (the cog next to the dates), add a goal of type Event with the name Purchase. The dashboard then shows how many visitors bought and the conversion rate over all visitors. If a customer reloads the thank-you page, the event is sent again, but the goal still counts that visitor once.

The steps before

The cart and checkout pages have fixed paths, so they work as page goals. WordPress paths end with a slash: /cart/ and /checkout/. With the three goals you can see how many visitors open the cart, start the checkout and complete the order.

More in Events and goals.