|
<!-- Handle Neto data for GA --> |
|
<script> |
|
ga('require', 'ec'); |
|
var gaEE = { |
|
functions: { |
|
gaProductKitItems: function(kit_items){ |
|
var val = ""; |
|
for (var i = 0; i < kit_items.length; i++) { val += kit_items[i].assemble_qty + "x" + kit_items[i].name + "; ";} |
|
return val; |
|
}, |
|
gaProductSpecifics: function(specifics){ |
|
var val = ""; |
|
for (var i = 0; i < specifics.length; i++) { val += specifics[i].name + ": " + specifics[i].value + "; "; } |
|
return val; |
|
}, |
|
gaProductType: function(product){ |
|
if(product.kit_items.length > 0){ |
|
return gaEE.functions.gaProductKitItems(product.kit_items) |
|
}else if(product.specifics.length > 0){ |
|
return gaEE.functions.gaProductSpecifics(product.specifics) |
|
} |
|
return ""; |
|
}, |
|
gaProductSetup: function(product, type) { |
|
var productVariant = ""; |
|
if((product.kit_items.length > 0) || (product.specifics.length > 0)){ |
|
productVariant = gaEE.functions.gaProductType(product); |
|
} |
|
return { |
|
'id': product.SKU ? product.SKU : product.parent_sku, |
|
'name': product.name, |
|
'category': product.category_fullname ? product.category_fullname : "", |
|
'brand': product.brand ? product.brand : "", |
|
'variant': productVariant, |
|
'price': product.price, |
|
'quantity': product.qty |
|
} |
|
}, |
|
gaSend: function(product, action, description){ |
|
console.log('GA - ' + action); |
|
ga('ec:addProduct', product); |
|
ga('ec:setAction', action); |
|
ga('send', 'event', 'UX', 'click', description); |
|
}, |
|
gaAddToCart: function() { |
|
var nProduct = $.getLastItemAdded(); |
|
var gaProduct = gaEE.functions.gaProductSetup(nProduct); |
|
gaEE.functions.gaSend(gaProduct, 'add', 'add to cart'); |
|
}, |
|
gaRemoveFromCart: function() { |
|
var nProduct = $.getLastItemRemoved(); |
|
var gaProduct = gaEE.functions.gaProductSetup(nProduct); |
|
gaEE.functions.gaSend(gaProduct, 'remove', 'removed from cart'); |
|
}, |
|
gaAddMultiToCart: function() { |
|
var nProducts = $.getLastItemsAdded(); |
|
console.log('Sent multi add GA'); |
|
for (var i = 0; i < nProducts.length; i++) { |
|
var gaProduct = gaEE.functions.gaProductSetup(nProducts[i]); |
|
gaEE.functions.gaSend(gaProduct, 'add', 'add to cart'); |
|
} |
|
}, |
|
init: function(){ |
|
nAddItemCallbacks.push(gaEE.functions.gaAddToCart); |
|
nRemoveItemCallbacks.push(gaEE.functions.gaRemoveFromCart); |
|
nAddMultiItemsCallbacks.push(gaEE.functions.gaAddMultiToCart); |
|
} |
|
} |
|
} |
|
gaEE.functions.init(); |
|
</script> |
|
<!-- End Handle Neto data for GA --> |