Track WooCommerce Revenue with Optimizely A/B Testing [Code Snippet]

by on March 20, 2016

Track Woo Commerce with Optimizely A/B Testing - PHP functions.php code snippet

Track WooCommerce Revenue with Optimizely A/B Testing [Code Snippet]

  •  
  •  
  •  
  •  

Track Woo Commerce with Optimizely A/B Testing - PHP functions.php code snippet

 

A/B Testing is a wonderfully brilliant way to test new designs and see if they are more or less effective without doing a total redesign. If you have a woocommerce store you can make changes in the design and see the amount of money that the change makes you with the A/B Testing service Optimizely and this code snippet in your WordPress themes’ function.php file.


<?php
// Loads Optimizely and sends revenue information on conversion page.
// Replace Optimizely script with your own ID.
function optimizely_revenue_tracking( $order_id ) {
// Get the order
$order = new WC_Order( $order_id );
$price = $order->get_total();
?>
<script src="//cdn.optimizely.com/js/0101010101.js"></script>
<script>
window.optimizely = window.optimizely || [];
window.optimizely.push(['trackEvent', 'eventName', {'revenue': <?php echo ( $price * 100 ); ?>}]);
</script>
<?php
}
add_action( 'woocommerce_thankyou', 'optimizely_revenue_tracking', 100 );

The implications are endless

Tracking revenue while A/B Testing could potentially change the entire process of updating your website.. that is if making money is something that you enjoy. Instead of blindly implementing your best hunch you can take a solid hypothesis, implement it in Optimizely and see scientifically whether it’s a good change or not.

Found on GitHub here

Some of my articles about A/B Testing

1. 3 Tools to really step up your digital strategy – Where I extol the virtues of Optimizely

2. When to implement changes based on A/B Testing – Where I give solid parameters by which to judge the results of your A/B Tests.

3. 5 A/B Tests that changed the way I design Websites  – May help you think of some hypotheses to test

4. 5 A/B Tests to Affect Revenue on your E-Commerce Site – More ideas about how to move the needle with A/B Tests

 


  •  
  •  
  •  
  •  

Ready to get started?

Get a free consultation now