Conversion Tracking in WooCommerce
We all know the important of tracking your conversions properly. I have been receiving quite a few questions about how to setup conversion tracking in WooCommerce, especially on my How to Insert the Facebook Conversion Pixel in WordPress post. There is a great new WordPress plugin out that will allow you to easily setup Google AdWords conversion tracking, Bing conversion tracking, and Facebook conversion tracking all at once on your WooCommerce successful checkout page. Follow the instructions below to set it up and start tracking your WooCommerce conversions.
Step 1
First you will need to go download and install the WooCommerce Conversion Tracking plugin. It is completely free thanks to the developer, Tareq Hasan.
[alert-note]This plugin inserts those codes on WooCommerce cart page, checkout success page and after user registration. So you can track who are adding your products to cart, who are buying them and who are registering to your site.[/alert-note]There is no physical thank you page in WooCommerce (otherwise you could simply just put the scripts on that page and be done with it). So if you are wanting to track successful purchases this plugin solves that problem by adding it to the “purchase success page header.” It is triggered after they checkout successfully.
Step 2
Once you have installed the plugin go to WooCommerce “Settings.”
Step 3
You can then find the plugin under the “Integration” tab.
Now we are ready to add the conversion tracking scripts/pixels. Follow my examples below.
How to Generate Your Google AdWords Conversion Script
Step 1
In Google Adwords click into Tools and then “Conversions.”
Step 2
Click on the “+ Conversion” button to add a new conversion.
Step 3
In my example I am going to call my conversion “Successful Checkout” and we will select “Webpage.”
Step 4
I will then fill in the values to match my products (fill in with your appropriate values). So my product is $45.00. I want it to track all conversions (sales). Conversion window is 30. Conversion category is a purchase/sale. I don’t want to add the indicator. Then press “Save and Continue.”
Step 5
I will then choose “I make changes to the code” and then I will copy the script.
How to Generate Your Facebook Conversion Pixel
See my article here on how to generate a Facebook pixel: How to Insert the Facebook Conversion Pixel in WordPress
How to Generate Your Bing Conversion Code
See my article here on how to generate a Bing conversion code: How to Insert the Bing Conversion Code in WordPress
Inserting your Code Into WooCommerce Conversion Tracking
Once you have your tracking code or tracking pixel you can then insert it where you want your conversion to fire. I want to track successful checkouts, so I will put all three of my conversion tracking codes into the “Checkout Scripts” box.
Press “Save Changes” and there you go! You are now tracking conversions in WooCommerce for Google AdWords, Bing, and Facebook. Pretty easy huh? It should be!
Product Specific Conversion Code
A big thank you to Adam Apollo on providing the following code. This applies if you need to load in a product specific conversion code:
get_items() as $item ) { $product = $order->get_product_from_item( $item ); if ( ! $product ) { continue; } $sku = $product->get_sku(); if (preg_match('/-tp$/', $sku) === 1) { return true; } } return false; } function my_custom_tracking( $order_id ) { $order = new WC_Order( $order_id ); if (order_items_include_tracking_pixel($order, $order_id)) { $total = $order->get_order_total(); // INSERT TRACKING CODE or // DO YOUR CUSTOM BEHAVIOR HERE } } add_action( 'woocommerce_thankyou', 'my_custom_tracking' ); ?>
It can be inserted in Functions.php — just add “-tp” to the end of any product slug to load the tracking code or custom behavior on the thank you page. You can also change the specific text to be added to the slug on this line by changing the “-tp” to something else:
if (preg_match('/-tp$/', $sku) === 1) {
You do not need the WooCommerce Conversion Tracking plugin for this code to work.
As always, feel free to leave comments below, I read each and every one of them!
Hi Brian,
Thanks again for an insightful post. How does this work if you have multiple products with different sales prices?
Kind regards,
Marijn
I am still trying to figure out the best way for variable prices. It’s not perfect yet, but in step 4 you can choose “my conversion value” my vary so you can at least see conversions fire. Then you could do the math on the adwords/facebook/bing side to see your cost per conversion.
Hi Brian, Thank you so much for your posts. They really help me implementing the needed pixels into my wpengine wordpress site. I would love to read a post from you about how to implement a Facebook Retargeting campaign with wordpress and woocommerce. I didn’t know where to ask for that post so I just posted it here in the comments. Please keep up the good and helpful posts!
Kind regards,
Jennifer
Hi Jennifer. Thanks for your comment and I’m glad the above post was helpful. For FB retargeting you already have the pixel with the above tutorial installed :) I have made a note to write a post about setting up a FB retargeting campaign. Look for it within the next couple weeks.
thanks a lot a full tutorial would be really helpful :-) I don’t know how to use the Pixel from my normal facebook campaign for retargeting too…
Does this plugin work with WPML (wordpress multilangual ) ?
Hi Kristjan! Thanks for your comment. I asked the developer of this plugin. He said he didn’t test it but it should work fine in WPML. https://twitter.com/tareq_cse/status/524035058378616832
Love, the article, and have applied the plug-in. I also use the software to track conversions by product for an affiliate marketing program. For this purpose i want to include the order ID from woocommerce in the tracking code. Do you know how to reference the order id variable in the tracking code i.e. what to put in stead of %order_id% in the below?
Thanks!
Jesper
Thanks for this article. I have been testing Tareq’s plugin but I thought that Google Conversion code should be in the body tag and Facebook Conversion Pixel should be in the header tag. When using the plugin suggested i get the option of either “inside head tag” or “in footer” Which seems to be body. So i have to pick one or the other for all tracking code. Do you have any suggestions? Thanks
Thanks David for your comment. Google recommends the body for their tag, however it works fine in the header. I have tested this with WooCommerce. You can have both scripts in the header. Hopefully that helps.
In the WooCommerce Conversion Tracking plugin, the product specific code loads on the product page, not on the checkout or thank you page. This defeats the purpose of the entire plugin, and causes huge errors in the numbers of conversions, which cost my client several thousand dollars in the first week until we determined the problem. Do not use this plugin if you are trying to track specific products.
If you need to load in a product specific conversion code, try this:
get_items() as $item ) {
$product = $order->get_product_from_item( $item );
if ( ! $product ) { continue; }
$sku = $product->get_sku();
if (preg_match(‘/-tp$/’, $sku) === 1) {
return true;
}
}
return false;
}
function my_custom_tracking( $order_id ) {
$order = new WC_Order( $order_id );
if (order_items_include_tracking_pixel($order, $order_id)) {
$total = $order->get_order_total();
// INSERT TRACKING CODE or
// DO YOUR CUSTOM BEHAVIOR HERE
}
}
add_action( ‘woocommerce_thankyou’, ‘my_custom_tracking’ );
?>
It can be inserted in Functions.php — just add “-tp” to the end of any product slug to load the tracking code or custom behavior on the thank you page. You can also change the specific text to be added to the slug on this line by changing the “-tp” to something else:
if (preg_match(‘/-tp$/’, $sku) === 1) {
You do not need the WooCommerce Conversion Tracking plugin for this code to work.
Awesome Adam thanks for adding that information. I will update the post later tonight with your info and give you credit. Ya unfortunately my WooCommerce client charges the exact same for all 4 of their products so I have never taken the time to figure out variable conversion sale prices.
Glad you got it figured out!
Two questions:
1. Where it shows //INSERT TRACKING CODE do I just paste the FB conversion pixel they provide in full?
2. Am I adding -tp on my actual product slug? Or am I typing my product slug inside this code that goes in functions.php? IN other words will I have to put: site.com/product/example-tp or am I putting that in this code above? Also, do I include the entire product url or just the ending slug part?
Thanks
Hey Mike. I haven’t tested Adam’s code above but I can explain it for you.
1. Yes, you paste the entire FB conversion pixel code.
2. You are actually adding -tp into your slug’s URL. so domain.com/my-product-tp
The code is searching for a match for -tp on the end of any slug. You can change the code above and use something else other than -tp… Hopefully that makes sense.
Cool. I’ll give it a shot tonight and do some testing. I’ll report back if it looks to work.
Why adding the -tp? I fail to see the reason to do this. IS that for testing only or are we supposed to add -tp to the slugs of all products?
How do you install the code provided by Adam? And what if I have different conversion pixel codes from facebook for each product, where do I put each code? This is very confusing. Please help
Hi Brandie, did you solve this? I also need to have a different pixel code per product…
Greetings, Martijn
Does this plugin works in the latest version of WooCommerce, Version 2.3.5? Or it is just in my website that this plugin doesn’t work? When i go to Integration, I see no input box and only the “Save Changes” button. Pls help..
Hei Lei-chan. I am not sure yet… I am still running on 2.2.11 as 2.3.0 was a major update that requires a lot of testing of my customizations. I hope to upgrade to 2.3.5 next week. I will make sure to test the FB conversion pixel plugin.
Hello Brian,
With this plugin i can put conversion tracking of Adwords and Facebook at the same time? If i select the option in Checkout Scripts, the plugin put the pixel on the thank you page?
Wait your reply. Thank you.
Sorry for the late reply Edi. Yes you can actually put as many tracking codes as you want into this plugin. I currently have AdWords and FB on mine. There is no physical thank you page actually with WooCommerce (otherwise you could simply just put the scripts on that page and be done with it). So this plugin solves that problem by adding it to the “purchase success page header.” It is triggered after they check out successfully. Hopefully that answers your question.
Awesome… I already have this plugin in place… so quick question. I have one pixel that should be in the footer and on that needs to be in the header… Will this work for that? It seems as tho it will not… Your thoughts?
Most of the time either the footer or the header will work, even though they might give you a recommendation. I have both the FB pixel and Google conversion code in my header they are working correctly.
Hi Brian,
I have this plugin and I want to add fb code+google code to the checkout page (woocommerce) but the problem is that the google code has to be in the body (the Tag Assistant by google shows an error for the conversion code) and not in the head. what is the solution for this?
thanks!
Hi Adi,
Hopefully I can explain this so it makes sense. Most WooCommerce installations don’t actually have a physical checkout page, and the conversion pixels have to be fired when the functions run. This is why the tag assistant won’t show it working because there is no physical page to check it on.
If you do have a physicial checkout page, I would recommend using this plugin method here for both FB + Google: https://brianjackson.io/insert-facebook-conversion-pixel-wordpress/
mmm…my thank you page is this: https://www.chuchick.com/checkout/order-received/
is it a physical page or not? i can’t access it from “pages” in the wp panel
That is not a physical page… as I have the same setup on mine. That is a page built dynamically by WooCommerce. My setup also fails to confirm the google tag but that is because they are warning you about putting the code in the header. The way the checkout page works the conversion code is only firing on the header on checkout, not on the rest of the site. So it won’t mess up your stats like Google is saying. Google recommends putting it into the body because most people don’t realize it would then fire on every single page. But this scenario is not one of those. Hopefully that makes sense.
ok – I will try it out and see in case of conversion what happens
thanks!
Hi Brian, could I use Adam Apollos code in the Fb plugins?
This may be of use to some people here. it is how to add the Facebook conversion pixel to your WooCommerce thank you page and track the order values. Just copy and paste it to your functions.php and change it to your own pixel ID.
https://www.social-response.co.uk/facebook-conversion-pixel-woocommerce-values/
I have tried adding the code that was supplied by Adam Apollo in my functions.php file so that I can track specific conversions, but for some reason the code is showing at the top of all my web pages. Do I need to change the slug first, or is this error being caused by something else? Can anyone help?
Thanks
Nice tutorial, very useful. Thanks
Hi Brian!
Awesome post man, I really enjoyed it.
Quick Q for you… I’ve added hitslink.com scripts to my site, “https://www.buylaserpegs.com”… Using Tareq’s awesome plugin.
Now, I need to pass Woo values in 2 places, order ID and order total…
Here’s what I’m using to get the values and it is not working: “$woocommerce->order->id” and “$woocommerce->cart->total”
//order->id’;
// Enter the Orders unique ID This is the code Woocommerce told me to use
ec_Orders_orderAmt=’$woocommerce->cart->total’;
// Enter the amount of the Orders This is the code Woocommerce told me to use var
wa_c=new RegExp(‘__wa_v=([^;]+)’).exec(document.cookie),wa_tz=new Date(),
wa_rf=document.referrer,wa_sr=location.search,wa_hp=’http’+(location.protocol==’https:’?’s’:”);
if(top!==self){wa_rf=top.document.referrer;wa_sr=top.location.search}
if(wa_c!=null){wa_c=wa_c[1]}else{wa_c=wa_tz.getTime();
document.cookie=’__wa_v=’+wa_c+’;path=/;expires=1/1/’+(wa_tz.getUTCFullYear()+2);}wa_img=new
Image();
wa_img.src=wa_hp+’://counter.hitslink.com/statistics.asp?v=1&s=27&eacct=’+wa_account+’&an=’+
escape(navigator.appName)+’&sr=’+escape(wa_sr)+’&rf=’+escape(wa_rf)+’&mvk=’+escape(wa_MultivariateKey)+
‘&sl=’+escape(navigator.systemLanguage)+’&l=’+escape(navigator.language)+
‘&pf=’+escape(navigator.platform)+’&pg=’+escape(wa_pageName)+’&cd=’+screen.colorDepth+’&rs=’+escape(screen.width+
‘ x
‘+screen.height)+’&je=’+navigator.javaEnabled()+’&c=’+wa_c+’&tks=’+wa_tz.getTime()
+’&ec_type=39063&ec_uniqueId=’+ec_Orders_orderID’&ec_orderAmount=’+ec_Orders_orderAmt
;document.getElementById(‘wa_u’).src=wa_hp+’://counter.hitslink.com/track.js’;//]]>
Can you offer any insight into what is wrong or why it won’t work? It will not call either Woo number…. I’ll happily paypal you a few bucks if you can help me get it figured out.
Thank you,
Tim@laserpegs.com
¿How can you add to multiple products? I have 4 products I would like to add a conversion code…
does this plugin add the “view content” pixel from facebook dynamic product ads?
Hi, I need completing the pixel code in my WooCommerce but I haven’t the work incomplete (I use plugin: Woocommerce Conversion Tracking). SALE_VALUE? SALE_NUMBER? …. What I have to put?
The pixel incomplet is:
Hi, very nice guide.
Unfortunately FB is planning on provinding just one pixel code that has to be customized for different uses in differente pages. So there will be no more “Conversion Tracking Pixel” vs “Facebook Pixel”.
(https://www.facebook.com/business/help/1563508590530683)
Do you have any suggestion on how to make it work with WooCommerce?
Can I track product search or just any search?. You know there is no physical search page.
Anybody knows how to change the code to track the value/price of the whole cart ? and not just a fixed value ?
Hiu everybody, has anybody tried the woothemes enhanced ecommerce plugin ?
https://wordpress.org/plugins/woocommerce-google-analytics-integration/
or this one
https://wordpress.org/plugins/enhanced-e-commerce-for-woocommerce-store/
The plugin author here. The product specific code issue was fixed in v0.3. You don’t need any hacks for that. Just put the code in the product edit area metabox. If any order contains that product, the code will be printed on order received page as well.
Hi Tareq, what do you mean by that “Just put the code in the product edit area metabox”? which code? pls explain more. Thanks
I meant the conversion tracking pixel code.
Hi, I’m new in woocommerce tracking conversions.
Can you please tell more about this
// INSERT TRACKING CODE or
// DO YOUR CUSTOM BEHAVIOR HERE
Do you mean insert the whole scripts that you got from google adwords or just the conversion ID?
Thanks
Because I added your code to my function.php the same whole thing and my website doesn’t work and when I delete your code on my function.php it’s working again.
Here is the best way:
// CONVERSION TRACKING FOR ORDERS!
add_action( ‘woocommerce_thankyou’, ‘my_custom_tracking’ );
function my_custom_tracking( $order_id ) {
// Lets grab the order
$order = new WC_Order( $order_id );
/**
* Put your tracking code here
* You can get the order total etc e.g. $order->get_order_total();
**/
$total = $order->get_total();
$conversioncode = ”;
$conversioncode.=’‘;
$conversioncode.=”;
$conversioncode.=’/* */’;
$conversioncode.=”;
$conversioncode.=”;
$conversioncode.=”;
$conversioncode.=”;
$conversioncode.=”;
$conversioncode.=”;
$conversioncode.=”;
$conversioncode.=”;
echo $conversioncode;
}
Thank you !!
Hi, many thanks for well done post. I have just a short question: should I add facebook pixel code with
a standard code fbq(‘track’, “PageView”);
OR
I need to replace it by fbq(‘track’, ‘AddToCart’);
Many thanks for advice.
Is this correct code if I would track all my products ? +20
Do I need change all slugs to ‘-tp’ ?
Nice guide Brian! Hope all is well!
Thanks Anthony! Ya, definitely keeping busy.
Hi, will this track conversions that do not come through adwords or facebook ? Like for example traffic coming to my site through links or social media or blog posts ?
Great article Brian! Can this plugin also be used to add tags for automations (Active Campaign for example) to recover abandoned carts?
Hi Brian – is this still the best plugin around for tracking conversions in WooCommerce? Thanks!
Glad you asked… I need to update the post. I recommend reading this instead: https://kinsta.com/blog/conversion-tracking/ I also wrote this and the plugins I mention in it are awesome!
Is anyone still active on this? Anyways I installed the plugin… but there is no option for a “single” product tracking conversion. Unless this post is old and I can’t find it.
From my understanding there should be a conversion tracking box under the Advanced tab for a Product…
I cannot find it…