
<script type="text/javascript">
    document.addEventListener('DOMContentLoaded', function() {
        var addToCartButton = document.getElementById('single_add_to_cart');
        if (addToCartButton) {
            addToCartButton.addEventListener('click', function() {
                var layerQuantityElement = document.getElementById('layerQuantity');
                var layerQuantity = layerQuantityElement ? (parseInt(layerQuantityElement.value) || 1) : 1;
                
                var layerPrice = <?php echo e($layerPrice ?? 0); ?>;
                var layerDiscount = <?php echo e($layerDiscount ?? 0); ?>;
                
                window.dataLayer = window.dataLayer || [];
                window.dataLayer.push({
                    event: "add_to_cart",
                    ecommerce: {
                        currency: "BDT",
                        value: layerPrice * layerQuantity,
                        items: [
                            {
                                item_id: "<?php echo e($product->sku ?? $product->id ?? ''); ?>",
                                item_name: "<?php echo e($product->title ?? ''); ?>",
                                affiliation: "<?php echo e(config('app.name')); ?>",
                                coupon: "",
                                discount: layerDiscount,
                                index: 0,
                                item_brand: "<?php echo e($product->brand->name ?? ''); ?>",
                                item_category: "<?php echo e($product->categories[0]->name ?? ''); ?>",
                                item_category2: "<?php echo e($product->categories[1]->name ?? ''); ?>",
                                item_category3: "<?php echo e($product->categories[2]->name ?? ''); ?>",
                                item_category4: "<?php echo e($product->categories[3]->name ?? ''); ?>",
                                item_list_id: "",
                                item_list_name: "",
                                item_variant: "<?php echo e($product->colors->first()->name ?? ''); ?>",
                                location_id: "",
                                price: layerPrice,
                                quantity: layerQuantity
                            }
                        ]
                    }
                });
            });
        } else {
            console.error('Button with ID "add_to_cart" not found.');
        }
    });
</script><?php /**PATH /home/apleusbj/public_html/resources/views/layouts/frontend/partials/gtm_add_to_cart_event_data_layer.blade.php ENDPATH**/ ?>