Skip to content

Instantly share code, notes, and snippets.

@ashsmith
Last active April 13, 2023 19:33
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save ashsmith/1974388 to your computer and use it in GitHub Desktop.
Save ashsmith/1974388 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>
@ashsmith
Copy link
Author

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
Copy link
Author

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

@ashsmith
Copy link
Author

ashsmith commented Aug 1, 2014

Updated to be more upgrade friendly

@riconeitzel
Copy link

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

@bgarrison25
Copy link

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