How to Add Conversion Tracking Code to Easy Digital Downloads

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' ) ) {
		return;
	}
	if( function_exists( 'edd_is_success_page' ) && ! edd_is_success_page() ) {
		return;
	}
	$session = edd_get_purchase_session();
	if( ! $session ) {
		return;
	}
	$payment_id = edd_get_purchase_id_by_key( $session['purchase_key'] );
?>
<script>
	var price = <?php echo edd_get_payment_amount( $payment_id ); ?>;
	fbq('track', 'Purchase', {
		value: price,
	});
</script>
<?php
}

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!

Ready to get more leads and sales?

Use Hollerbox to design and deploy popups faster.

1 thought on “How to Add Conversion Tracking Code to Easy Digital Downloads”

Leave a Comment

Scroll to Top