$(function() { $('.button_acquista').click(function() { fLoading( 1 ); var strID_Prodotto = $(this).attr('name'); if ( strID_Prodotto != '' ) { var strID_Taglia = $(".size-item.active .taglia").data('taglia'); var strID_Colore = $(".colore.active").data('colore'); $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/assets/ajax/setCarrello.php", data: "action=setCarrello&pstrID_Prodotto=" + strID_Prodotto + "&pintQuantita=" + $("#fp_quantita").val() + "&pstrCarrelloTipo=" + $("#fp_carrello_tipo").val() + "&pstrLangCurrent=" + $("#fp_lang_current").val() + ( strID_Taglia != undefined && strID_Taglia != "" ? "&pstrID_Taglia=" + strID_Taglia : "" ) + ( strID_Colore != undefined && strID_Colore != "" ? "&pstrID_Colore=" + strID_Colore : "" ), success: function(data) { if ( data.status == 'ok' ) { dataLayer.push({ ecommerce: null }); // Clear the previous ecommerce object. dataLayer.push({ event: "add_to_cart", ecommerce: { currency: "EUR", value: $("#"+strID_Prodotto+"prd_prezzo").val(), items: [ { item_id: $("#"+strID_Prodotto+"prd_sku").val(), item_name: $("#"+strID_Prodotto+"prd_titolo").val(), coupon: "", discount: $("#"+strID_Prodotto+"prd_sconto").val(), index: 0, item_category: $("#"+strID_Prodotto+"prd_categoria_main").val(), item_category2: $("#"+strID_Prodotto+"prd_categoria_parent").val(), price: $("#"+strID_Prodotto+"prd_prezzo").val(), quantity: 1 } ] } }); location.href = $('#fp_carrello_url').val(); } else swal("Oops...", "Procedure uncompleted.", "error"); }, error: function(data) { swal("Oops...", "Procedure uncompleted.", "error"); } }); /* ajax */ } }); });