Hello, I am trying to set up my GTM with my shop which uses New Dawn theme. I created an “add_to_cart” event when the customer adds an item to the cart I should see the item_name, item_variant_title, price, quantity. So far everything works fine except item_variant_title and quantity. When a customer selects an item variant I see only the default variant and not the right one. It looks like if the customer selects another variant the {{ product.selected_or_first_available_variant.title }} is not updated. Quantity is also not working. Can someone help me to get this right?
Here is my button and datalyer code:
<button
id="ProductSubmitButton-{{ section_id }}"
type="submit"
name="add"
class="product-form__submit button button--full-width {% if show_dynamic_checkout %}button--secondary{% else %}button--primary{% endif %}"
{% if product.selected_or_first_available_variant.available == false or quantity_rule_soldout %}
disabled
{% endif %}
onclick="dataLayer.push({ 'ecommerce': null });dataLayer.push({
'event': 'add_to_cart',
'ecommerce': {
'items': [{
'item_name': '{{ product.title | remove: "'" | remove: '"' }}',
'item_category': '{{ product.collections[0].title | remove: "'" | remove: '"' }}',
'item_variant': '{{ product.selected_or_first_available_variant.title }}',
'currency': '{{ shop.currency }}',
'price': '{{ product.price | times: 0.01}}',
'quantity': '{{ quantity }}'
}]
}
});"
>
<span>
{%- if product.selected_or_first_available_variant.available == false or quantity_rule_soldout -%}
{{ 'products.product.sold_out' | t }}
{%- else -%}
{{ 'products.product.add_to_cart' | t }}
{%- endif -%}
</span>
{%- render 'loading-spinner' -%}
</button>