/g, '/'); PAGE_ATTRS.category = PAGE_ATTRS.category.replace(/>/g, '/'); gtag('event', 'view_item', { currency: 'USD', value: parseFloat(PAGE_ATTRS.salePrice), items: [{ item_name: PAGE_ATTRS.name, item_category: PAGE_ATTRS.category, item_brand: PAGE_ATTRS.brand, price: parseFloat(PAGE_ATTRS.salePrice) }] }); } function defaultTrackAddToCart() { var all_forms = document.forms; document.addEventListener('DOMContentLoaded', event => { for (var i = 0; i < all_forms.length; i += 1) { if (typeof storeCheckoutDomain != 'undefined' && storeCheckoutDomain != 'order.store.turbify.net') { all_forms[i].addEventListener('submit', function(e) { if (typeof(GA_GLOBALS.dont_track_add_to_cart) !== 'undefined' && GA_GLOBALS.dont_track_add_to_cart === true) { return; } e = e || window.event; var target = e.target || e.srcElement; if (typeof(target) === 'object' && typeof(target.id) === 'string' && target.id.indexOf('yfc') === -1 && e.defaultPrevented === true) { return } e.preventDefault(); vwqnty = 1; if( typeof(target.vwquantity) !== 'undefined' ) { vwqnty = target.vwquantity.value; } if( vwqnty > 0 ) { gtag('event', 'add_to_cart', { value: parseFloat(PAGE_ATTRS.salePrice), currency: 'USD', items: [{ item_name: PAGE_ATTRS.name, item_category: PAGE_ATTRS.category, item_brand: PAGE_ATTRS.brand, price: parseFloat(PAGE_ATTRS.salePrice), quantity: e.target.vwquantity.value }] }); if (typeof(target) === 'object' && typeof(target.id) === 'string' && target.id.indexOf('yfc') != -1) { return; } if (typeof(target) === 'object') { target.submit(); } } }) } } }); } return { startPageTracking: function() { initGA(); if (isProductPage) { setProductPageView(); if (typeof(GA_GLOBALS.dont_track_add_to_cart) === 'undefined' || GA_GLOBALS.dont_track_add_to_cart !== true) { defaultTrackAddToCart() } } }, trackAddToCart: function(itemsList, callback) { itemsList = itemsList || []; if (itemsList.length === 0 && typeof(PAGE_ATTRS) === 'object') { if (typeof(PAGE_ATTRS.catNamePath) !== 'undefined') { PAGE_ATTRS.category = PAGE_ATTRS.catNamePath.replace(/ > /g, '/'); PAGE_ATTRS.category = PAGE_ATTRS.category.replace(/>/g, '/') } itemsList.push(PAGE_ATTRS) } if (itemsList.length === 0) { return; } var ga_cartItems = []; var orderTotal = 0; for (var i = 0; i < itemsList.length; i += 1) { var itemObj = itemsList[i]; var gaItemObj = {}; if (typeof(itemObj.id) !== 'undefined') { gaItemObj.id = itemObj.id } if (typeof(itemObj.name) !== 'undefined') { gaItemObj.name = itemObj.name } if (typeof(itemObj.category) !== 'undefined') { gaItemObj.category = itemObj.category } if (typeof(itemObj.brand) !== 'undefined') { gaItemObj.brand = itemObj.brand } if (typeof(itemObj.salePrice) !== 'undefined') { gaItemObj.price = itemObj.salePrice } if (typeof(itemObj.quantity) !== 'undefined') { gaItemObj.quantity = itemObj.quantity } ga_cartItems.push(gaItemObj); orderTotal += parseFloat(itemObj.salePrice) * itemObj.quantity; } gtag('event', 'add_to_cart', { value: orderTotal, currency: 'USD', items: ga_cartItems }); } } })(); YStore.GA.startPageTracking() } catch (e) { if (typeof(window.console) === 'object' && typeof(window.console.log) === 'function') { console.log('Error occurred while executing Google Analytics:'); console.log(e) } }