﻿var _gaq = _gaq || [];

_gaq.push(['_setAccount', 'UA-4015922-2']);
_gaq.push(['_trackPageview']);

(function () {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

var ga_items = new Array();
function ga_clear_items() {
    ga_items.length = 0;
}
function ga_set_items(item, i) {
    var i = parseInt(i);
    var item = $.parseJSON(item);
    ga_items[i] = item;
}

function ga_ecommerce(orderID, total, tax, shipping, city, state, partnerName) {
    _gaq.push(['_setAccount', 'UA-4015922-2']);
    _gaq.push(['_addTrans',
        orderID,  // order ID - required
        'PN-US-' + partnerName,   // affiltiation or store name
        total, // total - required
        tax,  //  tax
        shipping,   // shipping
        city, // city
        state,  //state
        'USA'  // country
        ]);
    for (i = 0; i < ga_items.length; i++) {
        _gaq.push(['_addItem',
            orderID,           // order ID - required
            ga_items[i].Number,           // SKU/code - required
            (ga_items[i].Title != null && ga_items[i] != "") ?
            ga_items[i].Title : ga_items[i].Description,        // product name
            ga_items[i].MFG,   // category or variation
            ga_items[i].Price.toString(), // unit price - required
            ga_items[i].Quantity.toString()]);                // quantity - required
    }
    _gaq.push(['_trackTrans']); //submits transaction to the Analytics servers

    (function () {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();
}




/*Transaction Data----
Transaction ID: your internal transaction ID [required]
Affiliate or store name
Total
Tax
Shipping
City
State or region
Country

Item Data-------
Transaction ID: same as in transaction data [required]
SKU
Product name
Product category or product variation
Unit price [required]
Quantity [required]*/


/** EXAMPLE **/
/*<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);
_gaq.push(['_addTrans',
'1234',           // order ID - required
'Acme Clothing',  // affiliation or store name
'11.99',          // total - required
'1.29',           // tax
'5',              // shipping
'San Jose',       // city
'California',     // state or province
'USA'             // country
]);

// add item might be called for every item in the shopping cart
// where your ecommerce engine loops through each item in the cart and
// prints out _addItem for each
_gaq.push(['_addItem',
'1234',           // order ID - required
'DD44',           // SKU/code - required
'T-Shirt',        // product name
'Green Medium',   // category or variation
'11.99',          // unit price - required
'1'               // quantity - required
]);
_gaq.push(['_trackTrans']); //submits transaction to the Analytics servers

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

</script>*/
/*************/
