﻿//GA Tracking Addon
;(function($) {

    var trackGA = function(link) {
        if (typeof (pageTracker) != 'undefined' && pageTracker != null) {
            pageTracker._trackPageview(link);
        }
        if (typeof (console) != 'undefined' && console != null) {
            console.log("Tracking: " + link);
        }
    }

    var gaInterpreter = function(data, command) {

        //this is in context of dom object, for example <a> 

        switch (command) {
            case "externalLink":
                trackGA("/External/" + data);
                break;
            case "vote":
                trackGA("/Vote/" + data.q + "/" + data.a);
                break;
            case "action":
                trackGA("/Action/" + data);
                break;
            case "rating":
                trackGA("/Rating/" + data.item + "/" + data.rating);
                break;
            default:
                trackGA(data);
                break;
        }
    }

    if (typeof $.tracker != 'undefined' && $.tracker != null) {
        $.tracker.providers.push(gaInterpreter);
    }

})(jQuery);