To add a conversion tracking code on the WooCommerce Thank You page without editing the child theme’s functions.php
file, you can follow these steps using a plugin like Code Snippets or directly through WooCommerce settings (depending on the tracking service). Here’s a guide to both methods.
Table of Contents
Method 1: Using the Code Snippets Plugin
- Install the Code Snippets Plugin:
- Go to your WordPress dashboard.
- Navigate to Plugins > Add New.
- Search for Code Snippets and install it.
- Activate the plugin once it’s installed.
- Create a New Snippet:
- Go to Snippets > Add New.
- Give the snippet a title like WooCommerce Thank You Page Tracking.
- Add Conversion Tracking Code:
- Paste the following code snippet in the code area. This example assumes you have a JavaScript tracking code to add:
add_action('woocommerce_thankyou', 'custom_thankyou_page_tracking', 10, 1);
function custom_thankyou_page_tracking($order_id) {
if (!$order_id) return;
// Add your tracking script here
?>
<script>
// Example of a conversion tracking code
console.log("Order ID:", <?php echo $order_id; ?>);
// Add your actual tracking code here
</script>
<?php
}
- Replace the
console.log
line with your actual tracking code. For example, if you’re using Google Analytics, Facebook Pixel, or any custom tracking code, place it within the<script>
tags.
Save and Activate the Snippet:
- Click Save Changes and Activate.
- The code will now run on the Thank You page of WooCommerce whenever an order is completed.
Also Read
WA Notifier – How to send bulk messages using WhatsApp API? Step By Step Guide
Kling AI – How to Access Kling AI in India
Method 2: Directly Add Conversion Tracking Code Using WooCommerce Settings (for Specific Platforms)
Some platforms, like Google Analytics and Facebook Pixel, offer integration through WooCommerce settings or official plugins. This method may vary slightly by platform but typically follows these steps:
- Install a Tracking Plugin (e.g., WooCommerce Google Analytics or Facebook for WooCommerce):
- Go to Plugins > Add New and search for the platform’s plugin.
- Install and activate the plugin.
- Set Up Conversion Tracking:
- Go to WooCommerce > Settings and find the tab for your plugin (e.g., Integration > Google Analytics).
- Enter your tracking information and configure the settings to track purchases on the Thank You page.
- Test the Conversion Tracking:
- Place a test order to verify that the tracking code fires correctly on the Thank You page.
Both methods are easy to use and do not require editing any theme files directly. The Code Snippets method is more flexible for custom codes, while the WooCommerce settings method simplifies integration with popular analytics services.
Method 3: Add Conversion Code Using function.php
To add conversion tracking code on the “Thank You” page in WooCommerce, you can follow these steps to ensure it only fires when a purchase is completed. This approach uses your child theme’s functions.php
file.
Step 1: Access Child Theme’s functions.php
File
- Log in to your WordPress dashboard.
- Go to Appearance > Theme File Editor.
- Select your child theme, and then open the
functions.php
file.
Step 2: Add Code for Conversion Tracking
Add the following code to your functions.php
file. This code checks if the user is on the WooCommerce “Thank You” page and injects your tracking script only on that page.
/**
* @snippet Conversion tracking code in thank you head Woocommerce
* @author Rahul Baghel
* @website https://wpexpertrahul.good4uh.com/
*/
add_action( 'wp_head', 'wpexpertrahul_google_conversion_thankyou' );
function wpexpertrahul_google_conversion_thankyou(){
// On Order received endpoint only
if( is_wc_endpoint_url( 'order-received' ) ) :
$order_id = absint( get_query_var('order-received') ); // Get order ID
if( get_post_type( $order_id ) !== 'shop_order' ) return; // Exit
$order = wc_get_order( $order_id ); // Get the WC_Order Object instance
?>
<!-- Event snippet for Purchase conversion page -->
<script>
gtag('event', 'conversion', {
'send_to': 'AW-XXXXXXXXXXXXXXXXXX', // Enter your tracking code here
'value': <?php echo $order->get_total(); ?>,
'currency': '<?php echo $order->get_currency(); ?>',
'transaction_id': '<?php echo $order_id; ?>'
});
</script>
<?php
endif;
}
Step 3: Customize the Tracking Code
- Replace the placeholder tracking code with your actual tracking script, such as Google Ads, Facebook Pixel, or any other tracking platform.
- For Google Ads, replace
'AW-XXXXXX/XXXXXXXXXX'
with your Conversion ID and Conversion Label. - The
transaction_id
is dynamically pulled from the WooCommerce order, so each purchase is uniquely tracked.
Step 4: Save and Test
- After pasting the code, click Update File to save the changes.
- Test the tracking code by completing a test order on your WooCommerce store.
- Verify that the tracking event is firing correctly by checking the tracking platform (e.g., Google Ads or Facebook Ads) or using a browser extension like Tag Assistant for Google or Pixel Helper for Facebook.
This setup will now trigger your tracking script only on the WooCommerce “Thank You” page, capturing each conversion after a successful order.
Conclusion
Adding conversion tracking to your WooCommerce Thank You page can significantly enhance your insights into customer behavior and the effectiveness of your marketing efforts. By using a plugin like Code Snippets or a dedicated WooCommerce tracking plugin, you can seamlessly integrate tracking codes without modifying theme files, keeping your setup flexible and secure. This approach not only simplifies the process but also ensures that your tracking remains consistent across updates. Implementing this tracking can provide valuable data for optimizing your sales funnel, allowing you to make informed decisions to improve customer engagement and conversion rates.
If you found this post helpful, please like, comment, and share it with others. And if you’re new to the blog don’t forget to subscribe our Newsletter for more AI tool insights. Thank you for reading!
If you liked the information in this blog post, then subscribe to our blog below
Frequently Asked Questions
What is conversion tracking, and why is it important for WooCommerce?
Conversion tracking allows you to monitor when customers complete specific actions, like purchases, on your WooCommerce store. By implementing conversion tracking on the Thank You page, you gain insights into customer behavior, measure the success of your marketing efforts, and identify areas for improvement in your sales funnel. This data helps you optimize your campaigns and increase sales effectively.
How do I add a conversion tracking code to the WooCommerce Thank You page without editing theme files?
You can add conversion tracking to the Thank You page without editing theme files by using a plugin like Code Snippets. This plugin lets you add custom code snippets that are executed site-wide or on specific pages. Alternatively, if your tracking platform has an official WooCommerce plugin (like Google Analytics or Facebook Pixel), you can install and configure it directly in WooCommerce settings for easy tracking.
What types of conversion tracking codes can I add to the WooCommerce Thank You page?
Common types of conversion tracking codes include Google Analytics, Facebook Pixel, and other third-party marketing platforms. You can also add custom JavaScript codes provided by your ad network, CRM, or other marketing tools that track conversions based on customer actions on the Thank You page. Each code typically captures the order ID, order value, or other customer information.