Found this useful? Love this post

Setting up hitCallBack using Google Universal Analytics

Google has recently released Universal Analytics. as a closed developer preview public beta. You can create a new web property in Google Analytics to try it out or upgrade your existing Google Analytics account. The tracking code should be calling google-analytics.com/analytics.js as opposed to google-analytics.com/ga.js.

One of the best features for a developer I’ve found so far in my hour of playing around is the ability to have a callback method executed after you’ve sent some data.

The prime case would be when you would track a link as an event. You would use a setTimeout to trigger the clicked link after you’d hoped the event had been sent to Google. No more! You can now use the following piece of javascript utilising the hitCallback function:

var href = "http://www.domsammut.com/";        

ga('send', 'event', {
    'eventCategory' : 'Star Trek',
    'eventAction'   : 'Fire',
    'eventLabel'    : 'Phasers',
    'eventValue'    : 100,
    'hitCallback'   : function () {
        document.location = href;
    }
});

Reference

Additional Reading

Subscribe

You'll only get 1 email per month containing new posts (I hate spam as much as you!). You can opt out at anytime.

Categories

Leave a Reply

Your email address will not be published. Required fields are marked *

Preview Comment

7 Comments

  1. Dom Sammut