script type="text/javascript"> template.load(function () { var app = this; var _ = app.getLibrary('_'); app.metrika.on('reachGoal', function (name) { app.ecommerce.sendData({'event': name}); }); app.api.basket.on('add', function (data, item) { app.metrika.reachGoal('basket.add'); if (!_.isNil(item)) app.ecommerce.sendData({ 'event': 'addToCart', 'ecommerce': { 'add': { 'products': [{ 'name': item.name, 'id': item.id, 'price': item.price, 'category': !_.isNil(item.section) ? item.section.name : null, 'quantity': item.quantity }] } } }); }); app.api.basket.on('remove', function (data, item) { app.metrika.reachGoal('basket.remove'); if (!_.isNil(item)) app.ecommerce.sendData({ 'event': 'removeFromCart', 'ecommerce': { 'remove': { 'products': [{ 'name': item.name, 'id': item.id, 'price': item.price, 'category': !_.isNil(item.section) ? item.section.name : null, 'quantity': item.quantity }] } } }); }); app.api.basket.on('clear', function (items) { var data; app.metrika.reachGoal('basket.clear'); if (!_.isNil(items)) { data = { 'event': 'removeFromCart', 'ecommerce': { 'remove': { 'products': [] } } }; _.each(items, function (item) { data.ecommerce.remove.products.push({ 'name': item.name, 'id': item.id, 'price': item.price, 'category': !_.isNil(item.section) ? item.section.name : null, 'quantity': item.quantity }); }); app.ecommerce.sendData(data); } }); }, { 'name': '[Metrika] Events' });