WooCommerce Manual Integration
David Rolenc avatar
Written by David Rolenc
Updated over a week ago

In order to successfully manually integrate tracking of your WooCommerce website, you will need to set up your system by the instructions in the Quick setup section and then tracking by following the guide below.

  1. In your WooCommerce admin environment, find file functions.php in the active theme and place the below code there (or to your custom PHP file)

    <?php
    /**
    * This is a PHP code, so should be wrapped inside PHP
    * Like we added here.
    * If PHP is already open then don't include above <?php open tag
    */
    /**
    * Adding custom javascripts or php action on WooCommerce Thank you page
    * Works with WooCommerce 3.0 or above
    */
    add_action( "wp_head", "trackdesk_header_script", 20 );

    if ( ! function_exists( 'trackdesk_header_script' ) ) {
    function trackdesk_header_script() {
    ?>
    <script async src="//cdn.trackdesk.com/tracking.js"></script>
    <script type="text/javascript">
    (function(t,d,k){(t[k]=t[k]||[]).push(d);t[d]=t[d]||t[k].f||function(){(t[d].q=t[d].q||[]).push(arguments)}})(window,"trackdesk","TrackdeskObject");

    trackdesk('YOUR TENANT ID', 'click');
    </script>
    <?php
    // Send conversion only on thank you page
    if ( function_exists( 'is_order_received_page' ) && is_order_received_page() && isset( $_GET['order-received'] ) ) {
    $order = wc_get_order( $_GET['order-received'] );

    if ( $order instanceof WC_Order ) {
    ?>
    <script type="text/javascript">
    trackdesk('YOUR TENANT ID', 'conversion', {
    conversionType: 'YOUR SELECTED CONVERSION TYPE',
    amount: {
    value: '<?php echo ($order->order_total - $order->order_shipping); ?>'
    },
    customParams: {
    advS1: '<?php echo $order->id; ?>',
    }
    });
    </script>
    <?php
    }
    }
    }
    }
    ?>

    Make sure to replace YOUR TENANT ID with your actual tenant id on both places.

    Make sure to replace YOUR SELECTED CONVERSION TYPE with the conversion type you want to use for tracking.
    Make sure you correctly enter the opening and closing PHP tags, for more see the comment in the code snippet above.
    โ€‹

    Save the file, and you are done!

Testing Your Integration

Please remember to test the creation of a click and a conversion before starting your program. This way you can verify that tracking has been set up correctly. You can create a test click and conversion by following the steps described here.

Did this answer your question?