I built a public Shopify application that runs embedded within merchant stores. The challenge I’m facing is getting the actual store domain from within my app code.
When my application loads, the URL structure looks like this:
https://merchantstore.myshopify.com/admin/apps/my-application
I tried using $_SERVER['HTTP_REFERER'] to capture the store URL, but this method returns my application’s URL rather than the merchant’s store domain. Since my app runs inside an iframe, I can’t rely on JavaScript solutions because I need the store URL on the server side to handle billing redirects properly.
The main issue is that I need to programmatically determine which store is using my app so I can either redirect users to the appropriate billing page or modify the current view to show billing information.
Is there a reliable way to extract the parent store domain from within an embedded Shopify app using server-side code?