Skip to content

Instantly share code, notes, and snippets.

@nelero
Forked from ashsmith/onepage.phtml
Created December 1, 2016 14:21
Show Gist options
  • Save nelero/23c10bfdaef555dd581f11d592feb9a4 to your computer and use it in GitHub Desktop.
Save nelero/23c10bfdaef555dd581f11d592feb9a4 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