A developer encountered an issue where Shopify’s Customer Privacy API fails to load when called with a delay (e.g., via setTimeout). The problem specifically affects asynchronous JavaScript files, including those loaded through the Script Tags API.
Problem Details:
When the loadFeatures function is wrapped in setTimeout, the callback (2nd parameter) doesn’t execute with success/error responses
Direct loading in Liquid files works as expected
The issue is demonstrated through attached code screenshots comparing successful (Ex 1) vs. failed (Ex 2) implementations
Solution:
Move the setTimeout inside the callback function rather than wrapping the entire loadFeatures call:
Call loadFeatures immediately without delay
Place timing logic within the success callback function
This ensures the API loads properly before any delayed operations execute
A working code example is provided showing the restructured approach with initCookieBanner() containing the delayed logic.
Summarized with AI on November 2.
AI used: claude-sonnet-4-5-20250929.
We are trying to load Customer Privacy API in store front but could not call success in some cases. The one case is when you load below code in delay its not working. https://shopify.dev/docs/api/customer-privacy
If you load that code directly in any liquid file than its working as expected.
So in our case our app js loading in async mode so obviously it will take some delay in that case its not calling 2nd parameter of that function with error/success.
I guess you have already solved your problem, but this may be beneficial for others.
I also faced the same problem and thanks to your post I understood that it was caused by the setTimeout for some unknown reason.
To solve this problem you can move the setTimeout like this :