Tracking Magento’s Onepage Checkout Steps in Google Analytics

Published:

Being able to track Checkout Abandonment is crucial when you’re focused on increasing conversions, with Magento’s one page checkout by default you can’t step up goals for Google Analytics to pick out each step, so instead we can use the trackPageview method to track fake pageviews for each step, we can then add these into our Goal steps inside GA.

Step 1) Modify onepage checkout template file

First of all we need to modify the file called onepage.phtml located inside checkout/onepage.phtml within your theme’s template directory, if the file doesn’t exist here copy it across from the base/default folder:

Your Theme: app/design/frontend/[package]/[yourtemplate]/template/checkout/onepage.phtml Base Default: app/design/frontend/base/default/template/checkout/onepage.phtml

Once you’ve got the file open paste in the following code at the end of the file, save and upload.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<script type="text/javascript">
  Checkout.prototype.gotoSection = Checkout.prototype.gotoSection.wrap(function(parentMethod, section, reloadProgressBlock) {

    // Call parent method.
    parentMethod(section, reloadProgressBlock);

    var _gaq = _gaq || [];

    try {
      // push current checkout section to google analytics if available.
      _gaq.push(['_trackPageview', '<?php echo $this->getUrl('checkout/onepage'); ?>' + section + '/']);
    } catch(err) {
      // silent fail.
    }
  });
</script>

Step 2) Set up Goal & Funnel on Google Analytics

All that is left to do now is to set up the goal and funnel on Google Analytics so we can begin tracking our abandonment’s. To do this within the new version of Google Analytics in the top right in the main navigation bar there is a link called “Admin” on this page navigate to the Goals section under Profiles > Goals.

Then enter the following information:

Google Analytics Goal Setup

Goal Type: URL Destination Match Type: Head Match Goal URL: /checkout/onepage/success/

Example of goal funnel setup

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/

And that’s it!

Save those changes and voila! You’re done and now tracking checkout abandonment! On the Standard Reporting section to Google Analytics go to Conversions > Goals > Funnel Visualization to see where your users are dropping out from the checkout process.

Looking for an expert Magento 2 Developer to help with your project?

Contact Me Today
Show Comments