Track checkout abandonment in Magento with Google Analytics

Lacey Tech Solutions are pleased to have been given the award for Best Website Development & SEO Agency 2019!

If Website analytics is setup correctly, they can give businesses all the information they need to make important website improvements to increase their e-commerce sales. In this article I’ll show you how to successfully track Magento shopping cart abandonment using Google Analytics for Magento 1.7 Community Edition.

Magento can track cart abandonment out the box but the information it provides is a limited and isn’t very comprehensive. Using Google Analytics we will be able to see exactly when a customer abandons the checkout process.

Please note: This one works only with Magento’s onepage checkout. I recommend you make a backup of your Magento website prior to following these instructions.

Step 1: Firstly we need to enable Google Analytics in Magento. To do this login to your admin panel, hover over the “System” menu option and click “Configuration”. Scroll down and click, “Google API” on the left hand settings menu. You want to enable Google Analytics and enter your website tracking code in the box provided.

01 - Enable Google Analytics in Magento

Step 2: We need to add some JavaScript to the checkout page to trak your visitors checkout process. To do this you need to make a copy of onepage.phtml from the Magento base theme into your theme so we can safely make the necessary changes.

You will need to copy:


Once you have copied the file to your theme you will need to add the following code to the bottom of the file:

<script type="text/javascript">// <![CDATA[
   Checkout.prototype.gotoSection = function(section) {
      try {
        _gaq.push(['_trackPageview', '/checkout/onepage/' + section + '/']);
      } catch(err) { }
      section = $('opc-'+section);
// ]]></script>

Your onepage.html file should look something like this: (click the image to see the full size image)
Your Magneto onepage.phtml file should look like this

Step 3: Now that we’re tracking the visitors checkout progress we now need to setup a goal within Google Analytics. To setup a goal login to Google Analytics and click on “Admin”. Scroll down and click on your website in the list to take you to the Google Analytics settings for your site.

02 - Setup goal in google analytics

In the next screen that appears click on your website name and you’ll be taken to your website’s profile page. Click the “Goal” tab.

03 - Setup goal in google analytics

Step 4: Setup the goal funnel in Google Analytics. The goal URL is where the visitor will be sent after their payment has been processed successfully. The default Magento URL is /checkout/onepage/success, but this may be different depending on what payment gateway your using.

Setup a goal funnel in Google Analytics to track Magento checkout abandonment

Google Analytics funnel steps:
Step 1: /checkout/cart/
Step 2: /checkout/onepage/
Step 3: /checkout/onepage/billing/
Step 4: /checkout/onepage/shipping/
Step 5: /checkout/onepage/shipping_method/
Step 6: /checkout/onepage/payment/
Step 7: /checkout/onepage/review/

Step 5: Now that we’ve setup our Goal Google Analytics will monitor and track the checkout process. You can test this by adding a product to the cart and going through the Magento onepage checkout process. There is normally a 24 hour delay in Google Analytics so your data won’t appear instantly.

Viewing the results of shopping cart abandonment in Google Analytics

After a few days I logged into Google Analytics and viewed the Funnel Visualisation for my goal (Click Conversions -> Goals -> Funnel Visualization)

Funnel visualisation of the Magento Checkout Process

Ben Lacey is the Managing Director of Lacey Tech Solutions. He is passionate about everything to do with websites from design and development through to search optimisation and hosting. He started the company blog as a platform to help educate current and prospective customers about the ever changing website development industry.

What are your thoughts?

We hope you found our article useful and look forward to answering your questions.