Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Track each step of the Magento onepage checkout in Google Analytics with this simple Javascript addition to [package]/[theme]/template/checkout/onepage.phtml just add it to the bottom of that file and follow up by configuring with Google Analytics goals
<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>
@ashsmith

This comment has been minimized.

Copy link
Owner Author

@ashsmith ashsmith commented Mar 4, 2012

There is a full blog post write up http://ashsmith.io/2012/03/tracking-magentos-onepage-checkout-steps-in-google-analytics/

This includes how to set up your goals within Google Analytics.

@ashsmith

This comment has been minimized.

Copy link
Owner Author

@ashsmith ashsmith commented Apr 17, 2012

There was a typo on line 4 as pointed out in the comments on the blog post, typo has now been fixed :)

@ashsmith

This comment has been minimized.

Copy link
Owner Author

@ashsmith ashsmith commented Aug 1, 2014

Updated to be more upgrade friendly

@riconeitzel

This comment has been minimized.

Copy link

@riconeitzel riconeitzel commented Apr 9, 2015

There's a missing <?php in Line #11 before "getUrl…"

@bgarrison25

This comment has been minimized.

Copy link

@bgarrison25 bgarrison25 commented Apr 17, 2015

don't forget the echo after <?php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment