I am using jquery to get the value of a text input box named with id of qty however I am not sure how to then get the value to appear in my javascript for my google analytics datalayer push.
So how do I get the value of qtyvalue to properly show in the quantity section of the below code?
<script>
require(['jquery'], function ($) {
//GET VALUE OF QTY BOX
qtyvalue = $("#qty").val();
$(".tocart").click(function(){
dataLayer.push({
'event': 'addToCart',
'ecommerce': {
'currencyCode': 'USD',
'add': {
'products': [{
'name': '<?php echo noSingleQuote($all_names);?>', // Name or ID is required
'id': '<?php echo "$google_sku";?>', // Name or ID is required
'price': '<?php echo "$google_price";?>', // Insert product price
'brand': '<?php echo "$google_site_owned_by_name";?>', // Insert product brand
'category': '<?php echo "$category_name";?>', // Insert product category
'quantity': 'qtyvalue',
}]
}
}
});
});
});
</script>
,after the last property of an object.