Tracking Magento one page checkout steps using Google Analytics

If your looking for a way to implement funnel tracking for Magento's one-page checkout then the following solution adapted from here is the implementation that I have used on many of accessions. It involves overriding the accordion function of the onepage, whilst that sounds complicated it's very easy to implement.

First copy the following file

SpiritualQuest

home or business

locksmith Boston

http://emergency-dentistry.org/

Vacation Breeze Honolulu

/app/design/frontend/base/default/template/checkout/onepage.phtml

and paste it into your own theme folder which should be located at

/app/design/frontend/default/YOURTHEME/template/checkout/onepage.phtml

After you now have a local copy of the template, open it up and locate the line where the accordion is specified

var accordion = new Accordion('checkoutSteps', '.step-title', true);

After identifying the following line copy the following code before the above identified line but still inside the javascript tag

Checkout.prototype.gotoSection = function(section) {
        try {
                _gaq.push(["_trackPageview", "escape($_SERVER['REQUEST_URI']); ?>" + section + "/"]);
        } catch(err) { }
        section = $('opc-'+section);
        section.addClassName('allow');
        this.accordion.openSection(section);
};

So your javascript tag at the bottom of the template should look something along the lines of

<script type="text/javascript">
        Checkout.prototype.gotoSection = function(section) {
                try {
                        _gaq.push(["_trackPageview", "<?php echo Mage::getSingleton('core/url')->escape($_SERVER['REQUEST_URI']); ?>" + section + "/"]);
                } catch(err) { }
                section = $('opc-'+section);
                section.addClassName('allow');
                this.accordion.openSection(section);
        };
        var accordion = new Accordion('checkoutSteps', '.step-title', true);
        <?php if($this->getActiveStep()): ?>
        accordion.openSection('opc-<?php echo $this->getActiveStep() ?>');
        <?php endif ?>
        var checkout = new Checkout(accordion,{
                progress: '<?php echo $this->getUrl('checkout/onepage/progress') ?>',
                review: '<?php echo $this->getUrl('checkout/onepage/review') ?>',
                saveMethod: '<?php echo $this->getUrl('checkout/onepage/saveMethod') ?>',
                failure: '<?php echo $this->getUrl('checkout/cart') ?>'}
        );
</script>

Now finally the last set that you might want to do is set up a goal with the url of /checkout/onepage/success/ and the following Step URLs

  • /checkout/onepage/
  • /checkout/onepage/billing/
  • /checkout/onepage/shipping/
  • /checkout/onepage/shipping_method/
  • /checkout/onepage/payment/
  • /checkout/onepage/review/
  • /checkout/onepage/success/

Any that's how you set up Google Analytics on Magento's one page checkout, if you have any recommendations on anyway to improve this then then please comment and I will update the post accordingly!

Twitter Intent Events with Google Analytics using _gaq.push();

This is a quick script that i created to enable twitter intent event tracking with google analytics.

It's derived from twitters offical intents-events page but wrapped around a jQuery document ready so twitter's script doesn't slow down your page load and also makes sure the twitter javascript is loaded before you bind your own callbacks to track the intents

jQuery(document).ready(function($) {
        
        var e = document.createElement('script'); e.type="text/javascript"; e.async = true; 
        e.src = 'http://platform.twitter.com/widgets.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(e);

        $(e).load(function() {
                function clickEventToAnalytics(intent_event) {
                        if (intent_event) {
                                var label = intent_event.region;
                                 _gaq.push(['_trackEvent', 'twitter_web_intents', intent_event.type, label]);
                        };      
                }       
                function tweetIntentToAnalytics(intent_event) {
                        if (intent_event) {
                                var label = intent_event.data.tweet_id;
                                _gaq.push(['_trackEvent', 'twitter_web_intents', intent_event.type, label]);
                        };      
                }       
                function favIntentToAnalytics(intent_event) {
                        tweetIntentToAnalytics(intent_event);
                }       
                function retweetIntentToAnalytics(intent_event) {
                        if (intent_event) {
                                var label = intent_event.data.source_tweet_id;
                                _gaq.push(['_trackEvent', 'twitter_web_intents', intent_event.type, label]);
                        };      
                }       
                function followIntentToAnalytics(intent_event) {
                        if (intent_event) {
                                var label = intent_event.data.user_id + " (" + intent_event.data.screen_name + ")";
                                _gaq.push(['_trackEvent', 'twitter_web_intents', intent_event.type, label]);
                        };      
                }       
                twttr.events.bind('click',    clickEventToAnalytics);
                twttr.events.bind('tweet',    tweetIntentToAnalytics);
                twttr.events.bind('retweet',  retweetIntentToAnalytics);
                twttr.events.bind('favorite', favIntentToAnalytics);
                twttr.events.bind('follow',   followIntentToAnalytics);
        });
});

 

No doubt i will revisit this in a few days when i have slept and the hype about the Twitter "Follow" buttons cools down, but for now this suffices but if anyone can recommend any improvements I would love to hear them!