Skip to main content
Contributor I
February 6, 2024
Solved

Set up a Geolocation triggered pop-up on Shopify

  • February 6, 2024
  • 2 replies
  • 494 views

I'm trying to create a pop-up that is going to be triggered to any user that is coming from outside the US. I've created a pop-up with the custom trigger and also the code to be added on the theme.liquid just before the </body> . However I can't make it work, any ideas?

 

<script type="text/javascript">
  function getGeolocation(callback) {
    const userCountryCode = 'US';
    callback(userCountryCode);
  }
  function openPopUpBasedOnGeolocation(userCountryCode) {
  
    if (userCountryCode !== 'US') {
   
      window._klOnsite = window._klOnsite || [];
      window._klOnsite.push(['openForm', 'FORM_ID']);
    }
  }

 openPopUpBasedOnGeolocation
  getGeolocation(function (userCountryCode) {
    openPopUpBasedOnGeolocation(userCountryCode);
  });
</script>
 

    This topic has been closed for replies.
    Best answer by Brian Turcotte

    Hi @paulanoba!

    When you say that you can’t make it work, would you mind explaining a little more about what is/is not happening? Is the form appearing and not collecting the correct information, or is the form not appearing at all?

     

    Cheers,

    Brian

    2 replies

    kaila.lawrence
    Community Manager
    Community Manager
    February 7, 2024

    Hey @paulanoba! You’ll get much more insightful answers on anything to do with custom code in our Developer Group. I’ve moved this thread over there for you! :) 

    Brian Turcotte
    Klaviyo Alum
    February 8, 2024

    Hi @paulanoba!

    When you say that you can’t make it work, would you mind explaining a little more about what is/is not happening? Is the form appearing and not collecting the correct information, or is the form not appearing at all?

     

    Cheers,

    Brian