How to Add Google Analytics to WooCommerce Thank You Page

Woo Commerce is the widely used theme for building eCommerce platform in wordpress. Sometimes it is required to track leads on how many users purchased/checkout the goods using Google AdServices. Here, I will provide a simple script which can be added to functions.php to add the google script to your WooCommerce theme.

/*** Add Google Conversion Code ***/
add_action( 'woocommerce_thankyou', 'google_conversion_tracking' );     

function google_conversion_tracking() {     
<!-- Google Code for Conversion Page --> 
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 'Your Conversion Id Here';
var google_conversion_label = "Your Conversion Label Here";
var google_remarketing_only = false;
/* ]]> */
<script type="text/javascript" src="//">
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" 
	 src="//'Your Conversion Id Here'/?label='Your Conversion Label Here'&guid=ON&script=0"/>
Add to functions.php


Here woocommerce_thankyou is a function for Woo Commerce to add to the thank you page and google_conversion_tracking is the callback function for that. You need to create a google ad account to get the tracking codes like conversion id and label. Once you have that, change the places in the code with your id and conversion label. You are done :).

Check with the tracking dashboard on google apps.

For any new addition or modification, please feel free to knock Devkinz:

2 thoughts on “How to Add Google Analytics to WooCommerce Thank You Page

  1. That’s super nice and helpful but we came across a problem with Paypal tracking.

    Sometimes a purchase is tracked and sometimes it’s not. We assume that after Paypal payment you can go back to the shop but you don’t HAVE to. So some people just leave after payment without even seeing the Thank you-page.

    There is this hook we would like to try out: “woocommerce_payment_complete”. Not sure if it works though

    • Thanks a lot for your response. You are right, you can use the woocommerce_payment_complete hook to add the scripts. Let me know if you faced any difficulties, will be here to help.

      If you need further modification, you can contact with us for development.

Leave a Reply

Your email address will not be published. Required fields are marked *