﻿AnalyticsProvider =
{
    _provider:null,
    getCurrent: function()
    {
    /*
        if (this._provider==null && typeof fireunit === "object")
        {
            this._provider = new FireUnitAnalyticsProvider();
        }
    */
        if (this._provider==null && window._gaq)
        {
            this._provider = new GoogleAnalyticsProvider();
        }
        
        return this._provider;
    }
}

function FireUnitAnalyticsProvider()
{
    jQuery.extend(this,{
    trackView: function(url)
    {
        fireunit.ok( true, "trackView(" + url+ ");" );
        
    },
    trackEvent: function(name, category, object)
    {
    fireunit.ok( true, "trackEvent(" + name+ "," + category + "," + JSON.stringify(object) + ");" );
    },
    setVariable: function(variable,name,scope)
    {
        fireunit.ok( true, "setVariable(" + variable+ "," + name + "," + scope + ");" );
    }
    });
}

function GoogleAnalyticsProvider()
{
    jQuery.extend(this,{
    
    Variables:
    {
        "user":1
    },
    
    Scopes:
    {
        'Visitor':1,
        'Session':2,
        'Page': 3
    },
    
    trackView: function(url)
    {
        _gaq.push(['_trackPageview',url]);
    },
    trackEvent: function(category, action, object)
    {
        var params = ['_trackEvent',category,action];
        if (object.label)
        {
            if (object.value)
            {
                params.push(object.value + "-" + object.label);
            }
            else
            {
                params.push(object.label);
            }
        }
        _gaq.push(params);
    },
    setVariable: function(variable,name,scope)
    {
        if (!this.variables[name]) return ;
        _gaq.push(["_setCustomVar", this.variables[name] ,name, this.Scopes[scope] ] );
        
    }
    });
}


