Hello Shopify Developer Community,
I am experiencing an issue with the add_to_cart event when using the Ajax API in our app. Here are the details:
Context:
Our app uses the Shopify Add to Cart Ajax API to manage cart additions when a merchant applies a volume discount offer. The app is intended to trigger a single add_to_cart event each time items are added, based on the Shopify documentation. However, we have encountered a situation where the add_to_cart event is triggered multiple times in the Shopify dataLayer, even though our code only calls the Ajax API once.
Steps Taken:
-
We’ve confirmed that the API is called only once per cart addition, regardless of quantity or variant type.
-
Tested different scenarios (e.g., adding items with the same variant and adding items with different variants) and observed a single Ajax API call each time.
-
Despite this, multiple add_to_cart events appear in the dataLayer, affecting analytics.
Questions:
-
Has anyone encountered similar issues with the add_to_cart event triggering multiple times in the dataLayer when using the Ajax API?
-
Are there specific conditions or settings in the Shopify ecosystem that might cause this behavior?
-
Any troubleshooting advice or recommendations for resolving this discrepancy?
Supporting Material:
Here’s a Loom video showing the behavior we observed during testing.
Here’s a link to the offer where this issue can be reproduced - https://consolatio.com.br/products/kit-3-camisas-ultra-stretch
Additional Information:
- Shopify API Version: 2023-07
-
API Type: Ajax API
-
App Language: JavaScript
Thank you in advance for any insights or advice you may have. I appreciate any guidance from those who may have faced similar issues or have expertise with Shopify’s Ajax API.
Cheers,
Ohad