Last active
April 13, 2023 19:33
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
There was a typo on line 4 as pointed out in the comments on the blog post, typo has now been fixed :)
Updated to be more upgrade friendly
There's a missing <?php in Line #11 before "getUrl…"
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
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.