Skip to content

Instantly share code, notes, and snippets.

@hemantshekhawat
Forked from ashsmith/onepage.phtml
Created June 16, 2016 22:55
Show Gist options
  • Save hemantshekhawat/c991fffc749a89e596f68b8f1db4b458 to your computer and use it in GitHub Desktop.
Save hemantshekhawat/c991fffc749a89e596f68b8f1db4b458 to your computer and use it in GitHub Desktop.
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment