1. Create a new file 'sellify-ucd-gtm.liquid' in snippets of your theme and paste the following code


<script>
  (function(){
    function addToCart(event, lineItem, quantity, price){
        sellify.ucd.dataLayer = sellify.ucd.dataLayer || window.dataLayer || [];

        sellify.ucd.dataLayer.push( {
            'event': 'addToCart',
            'ecommerce': {
                'currencyCode': sellify.ucd.cart.currency,
                'add': {
                    'products': [
                        {
                            'name': lineItem.product_title,
                            'id': lineItem.product_id,
                            'price': typeof price !== "undefined" ? price / 100 : lineItem.line_price / 100,
                            'brand': lineItem.vendor,
                            'category': lineItem.product_type,
                            'variant': lineItem.variant_title || '',
                            'quantity': quantity,
                        }
                    ]
                }
            }
        } );
    }

    function removeFromCart(event, lineItem, quantity, price){
        sellify.ucd.dataLayer = sellify.ucd.dataLayer || window.dataLayer || [];

        sellify.ucd.dataLayer.push( {
            'event': 'removeFromCart',
            'ecommerce': {
                'currencyCode' : sellify.ucd.cart.currency,
                'remove': {
                    'products': [
                        {
                            'name': lineItem.product_title,
                            'id': lineItem.product_id,
                            'price': typeof price !== "undefined" ? price / 100 : lineItem.line_price / 100,
                            'brand': lineItem.vendor,
                            'category': lineItem.product_type,
                            'variant': lineItem.variant_title || '',
                            'quantity': quantity,
                        }
                    ]
                }
            }
        } );
    }

    window.addEventListener( "Sellify::UCD::ItemAdded", function( e ){
        addToCart(e.detail, e.detail.line_item, e.detail.line_item.quantity);
    } );

    window.addEventListener( "Sellify::UCD::ItemChanged", function( e ){
        sellify.ucd.dataLayer = sellify.ucd.dataLayer || window.dataLayer || [];
        const previousLineItem = e.detail.previous_cart.items[e.detail.line - 1];

        var lineItem = null;
        if( e.detail.quantity > 0 )
        {
            lineItem = e.detail.cart.items[e.detail.line - 1];

            if( lineItem.quantity > previousLineItem.quantity )
            {
                addToCart( e.detail, lineItem, lineItem.quantity - previousLineItem.quantity, lineItem.line_price - previousLineItem.line_price  );
            }
            else if( lineItem.quantity < previousLineItem.quantity )
            {
                removeFromCart( e.detail, lineItem, previousLineItem.quantity - lineItem.quantity, previousLineItem.line_price - lineItem.line_price );
            }

        }
        else if( e.detail.previous_cart )
        {
            lineItem = e.detail.previous_cart.items[e.detail.line - 1];
            removeFromCart( e.detail, lineItem, previousLineItem.quantity, previousLineItem.line_price );
        }
    } );
})();
</script>


2. Include 'sellify-ucd-gtm.liquid' in your theme.liquid with the following code


{% include 'sellify-ucd-gtm' %}


3. Now you have to create a few tags and triggers in your Google Tag Manager account. Please create tags according to the following screenshot:


Tag for AddToCart:



Trigger for addToCart:



Tag for Remove from cart:



Trigger for Remove from cart: