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:

Leave a Reply

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