Many services such as Facebook ads, Google Adwords, Optimizely, and Woopra require tracking codes to be installed on your website.

This allows you to get relevant data when people purchase on your Easy Digital Downloads store. You can see if your ads are converting, what a/b testing variation is performing better, or just what path the new customer took before purchase.

This data allows you to see where your conversions are coming from, so that you can push harder on those channels. Without conversion data, you are flying blind.

Tracking Conversions with Easy Digital Downloads

Most services, such as Facebook, give you a Javascript snippet to install on your purchase confirmation page in order to track conversions.

It looks something like this:

fbq('track', 'Purchase', {'value':'9.99','currency':'USD'});

This code sends a tracking event to Facebook that tells it there was a purchase. It works along with the Facebook Pixel code (which you must also have installed), and tracks conversions for Facebook ads.

Usually this is very easy to install, but it’s a bit more complicated with Easy Digital Downloads.

The Problem

The problem is that the purchase confirmation page can be visited multiple times by your customer.

It is used to display download links, and most customers visit the page multiple times to download their products. This causes the conversion code to fire multiple times, which gives you false positives in your conversion data.

The Solution

In order to avoid sending conversion data each time the purchase confirmation page is visited, we must only output the conversion script on the first visit to the page.

To do this, we need to add some special code that checks if this is a conversion. We do that using the edd_get_purchase_session() function.

function my_edd_conversion_tracking() {
	if( ! function_exists( 'edd_get_purchase_session' ) ) {
	if( function_exists( 'edd_is_success_page' ) && ! edd_is_success_page() ) {
	$session = edd_get_purchase_session();
	if( ! $session ) {
	$payment_id = edd_get_purchase_id_by_key( $session['purchase_key'] );
	var price = <?php echo edd_get_payment_amount( $payment_id ); ?>;
	fbq('track', 'Purchase', {
		value: price,

add_action( 'wp_head', 'my_edd_conversion_tracking', 11 );

It can go in a theme functions.php file or a plugin. To change the tracking code to something other than Facebook, such as Google AdWords, just modify the code in the script tag.

This code is straight from the plugin developer, Pippin Williamson. Thanks Pippin!

Published by Scott

1 Comment

  1. Hello

    Good idea thank you. Is this code still working ??

    Best regards


Leave a Reply

Your email address will not be published.

Content Upgrade Bonuses

Get 3 free bonuses to make it easier for you to create better content upgrades:
  • 21 extra content upgrade ideas and examples
  • Free ebook cover design
  • Free 3D ebook cover Photoshop action
Enter your name and email below.
Holler Box

WooCommerce Statistics Infographic

Enter your email below to get our analysis of 2017 WooCommerce statistics in a handy PDF infographic.
Holler Box