If you notice unusually large quantity values (e.g., thousands or millions) in item details within your GA4 reports, it might be caused by the lack of a maximum quantity limit. Visitors can manipulate this to trigger exaggerated “Add to Cart” events, distorting your analytics data. To prevent such issues, you can set minimum and maximum quantity limits in your input fields.
This implementation ensures valid input values for product quantity fields in an e-commerce environment by dynamically assigning min and max values using Liquid. The limits are derived from the product’s quantity_rule or default to 1 and 10, respectively, if no rules are defined. By using Liquid’s assign, the logic remains clean, reusable, and maintainable.
Below is an example implementation:
{% assign min_quantity = product.selected_or_first_available_variant.quantity_rule.min | default: 1 %}
{% assign max_quantity = product.selected_or_first_available_variant.quantity_rule.max | default: 10 %}
<input
class="quantity__input"
type="number"
name="quantity"
id="Quantity-{{ section.id }}"
data-cart-quantity="{{ cart_qty }}"
data-min="{{ min_quantity }}"
min="{{ min_quantity }}"
data-max="{{ max_quantity }}"
max="{{ max_quantity }}"
step="{{ product.selected_or_first_available_variant.quantity_rule.increment | default: 1 }}"
value="{{ min_quantity }}"
form="{{ product_form_id }}"
>