You are here

santianoEcommerce to gaEnhancedEcommerce

Tag Type: 
Custom HTML
	<script>
// grabs the santiano Ecommerce Event and plays with it for Google Enhanced Ecommerce
  // all the controls are in the event Commands
  var eventCommand = {{eventCommand}};

  // Common EventCategory for all Enhanced Ecommerce 
  var eventCategory = 'Enhanced Ecommerce';

  // My already GA formatted products are here
  var gaEcommerceProducts = {{gaEcommerceProducts}};

  switch (eventCommand) {
    case 'productImpression':
      var eventAction = 'Product Impression';
      var eventLabel = 'On list:{{productImpressionListName}}';
      var enhancedEcommerceObject = {
        'currencyCode': {{currencyCode}},
        'impressions': gaEcommerceProducts
      };
      break;

    case 'productClick':
      var productList = {{productList}};
      var eventAction = 'Product Click';
      var eventLabel = 'productId clicked is:' + productList[0].productId;
      var enhancedEcommerceObject = {
        'currencyCode': {{currencyCode}},
        'click': {
          'actionField': {'list': + {{productImpressionListName}}},
          'products': gaEcommerceProducts
         }
      };
      break;

    case 'productDetail':
      var productList = {{productList}};
      var eventAction = 'Product Detail';
      var eventLabel = 'productId viewed is:' + productList[0].productId;
      var enhancedEcommerceObject = {
        'currencyCode': '{{currencyCode}}',
        'detail': {
          'products': gaEcommerceProducts
         }
       };
      break;

    case 'cartProductAdded':
      var productList = {{productList}};
      var eventAction = 'Product added to cart';
      var eventLabel = 'productId added is:' + productList[0].productId;
      var enhancedEcommerceObject = {
            'currencyCode': '{{currencyCode}}',
            'add': {
                'products': gaEcommerceProducts
            }
        };
      break;

    case 'cartProductRemoved':
      var productList = {{productList}};
      var eventAction = 'Product removed from cart';
      var eventLabel = 'productId removed is:' + productList[0].productId;
      var enhancedEcommerceObject = {
            'currencyCode': '{{currencyCode}}',
            'remove': {
                'products': gaEcommerceProducts
            }
      };
      break;

    case 'checkoutStep':
      var eventAction = 'Checkout step {{checkoutStepNumber}}';
      var eventLabel = {{checkoutStepName}} + ' with ' + {{checkoutStepOption}};
      var enhancedEcommerceObject = {
        'currencyCode': '{{currencyCode}}',
        'checkout': {
          'actionField': {'step': {{checkoutStepNumber}} ,'option': {{checkoutStepOption}} },
        'products': gaEcommerceProducts
        }
      };
      break;

    case 'orderConfirmation':
      var eventAction = 'Order Confirmation';
      var eventLabel = 'orderId confirmed is:' + {{orderId}};
      var enhancedEcommerceObject = {
        'currencyCode': '{{currencyCode}}',
        'purchase': {
          'actionField': {
            'id': {{orderId}},
            'affiliation': {{orderShopName}},
            'revenue': {{orderRevenue}},
            'tax':{{orderTax}},
            'shipping': {{orderShippingCost}},
            'coupon': {{orderCoupon}}

          },
        'products': gaEcommerceProducts
        }
      };
      break;

    case 'productRefund':
      var eventAction = 'Product Refund';
      var eventLabel = 'productId refunded is:' + productList[0].productId;
      var enhancedEcommerceObject = {
        'refund': { 
          'actionField': {
            'id': {{orderId}}
          },
          'products': gaEcommerceProducts
        }
      };
      break;

    case 'orderRefund':
      var eventAction = 'Order Refund';
      var eventLabel = 'orderId Refunded is:' + {{orderId}};
      var enhancedEcommerceObject = {
        'refund': {
          'actionField': {
            'id': {{orderId}},     
          }
        }
      };
      break;

  } // end of Switch statement


dataLayer.push({
  'event': 'gaEnhancedEcommerce',
  'eventCategory': eventCategory,
  'eventAction': eventAction,
  'eventLabel': eventLabel,
  'ecommerce': enhancedEcommerceObject
});


</script>