Dev: Troubleshooting
How the functionality works
The script initializes the window.refactor_apps.back_in_stock object, which exposes the core methods: checking subscription status, subscribing/unsubscribing, retrieving subscribers and subscribed products, and automatically merging guest subscriptions with a customer account on login.
Once the script loads, it dispatches an apps:back-in-stock:ready event. After the guest-to-customer merge step completes, it dispatches apps:back-in-stock:merge-complete .
Issue: The subscribe button doesn't appear, or the widget doesn't initialize
Possible causes:
- The theme tries to access
window.refactor_apps.back_in_stockbefore the script has finished loading. - The
isReadyflag is stillfalseat the time it's accessed.
Solution: Wait for the apps:back-in-stock:ready event, or check the isReady flag, before calling any widget methods. Calling methods before initialization will throw an error or silently fail.
Issue: checkIsSubscribed returns success: false
Possible causes:
- Incorrect or missing
emailorvariantIdpassed to the request. - The
/apps/refactor-back-in-stock/api/checkendpoint returns a server-side error (e.g., the product or shop can't be found). - Network or proxy issues — for example, if a tunneling service like ngrok is in use, the
ngrok-skip-browser-warningheader is already set in the request, but additional middleware could still interfere.
Solution: Check the message.errors object returned on failure — it contains a description of the specific error. Also confirm email and variantId are valid strings, not undefined or null .
Issue: subscribeOnTheProduct doesn't work, or the subscription isn't saved
Possible causes:
- A required parameter (
productId,variantId, oremail) is missing. - The server rejects the request due to validation (e.g., invalid email format).
customerIdwas passed but the customer isn't found in the system, so the subscription is only saved as a guest subscription.
Solution:
- Check the request body — all IDs should be coerced to strings (this is already handled via
String()). - Confirm
window.Shopify.localeandwindow.Shopify.countryare defined on the page — if missing, the payload will sendnullfor these, which isn't fatal but may affect notification localization. - On success, the
apps:back-in-stock:subscribedevent should fire. If it doesn't, the request didn't complete successfully — check the browser console for network errors.
Issue: unsubscribeFromTheProduct returns an error
Possible causes:
- No subscription exists matching the given
email/variantId/productId. customerIdwas used when subscribing but not when unsubscribing (or vice versa), so the system can't locate the matching record.
Solution: Use the same identifiers that were used when subscribing. For logged-in customers, prefer unsubscribeFromTheProductByCustomerId to avoid mismatches between email-based and customer-based records.
Issue: Guest subscriptions don't merge with the account after login
Possible causes:
window.refactor_apps.__customerDatais missingidoremailat the time the script runs.- The merge (
mergeCustomer) already ran previously, and there are no remaining unlinked records to merge — this is expected behavior, not an error.
Solution: Confirm that __customerData is correctly populated by the theme and available before the script runs. If there's nothing to merge, the apps:back-in-stock:merge-complete event will still fire — this is normal, and you shouldn't expect merged: true on every occurrence.
Do you need help?
If you have any questions or run into issues, please contact us — we're happy to help.