How to access customer country on the server side when using app proxy?

I’m creating a Shopify app that uses app proxy to render a list of products on the merchant webstore.

If the store supports multiple countries/markets, then the customer can select his country using “Country/region selector” from the footer:

I want to show the products (with prices in local currency) specific to the user selected country.

Question

Is it possible somehow for the app proxy server to access the country that user has selected?

I’d like to use the country information to perform contextual Storefront Graphql queries to support multiple markets.

query @inContext(country: GB) { # <---- use the country for contextual query
  products(first: 2)  {
    nodes {
      title
      variants(first: 1) {
        nodes {
          price {
            amount
            currencyCode
          }
        }
      }
    }
  }
}

Additional info

The webstore liquid allows accessing the country using {{ localization.country.iso_code }} and Shopify server injects dynamically into the store webpage the country as well:

I can, of course, do the fetching from the client side adding the country as a parameter. However, I’d like to access the country directly on the app proxy server side.

Thank you!

Hey Dimitri,

I would say your best bet is to use query params that hold the currently selected country.

If you don’t receive a country query parameter within your endpoint return something like:

{% layout none %}
<html>
  <head>
    <meta http-equiv="refresh" content="0;url=/apps/test?country={{ localization.country.iso_code  }}">
  </head>
  <body></body>
</html>

Sadly we get very little context when working with app proxies, hope this helps regardless.

Kevin :hatching_chick:

1 Like

Thank you @Kevin_Sieger. It’s a smart workaround but unfortunately HTML redirect is a bit slow to put in front of the customers. My goal with server side rendering is to show the products to the customers as fast as possible because some merchants use my app as their main sales point on their web stores.

I agree that the app proxies should get much more context about the customer. Having access to Shopify object injected (kind of the Shopify JavaScript object inserted by Shopify into web store) on the server side is a good start.

On a side note, I have also opened an issue in app-js repository and even contacted Shopify partner support for some help but I didn’t get it resolved.

1 Like