Skip to main content
Solved

Set up a Geolocation triggered pop-up on Shopify

  • February 6, 2024
  • 2 replies
  • 407 views

Forum|alt.badge.img+1

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>
 

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
Forum|alt.badge.img+31
  • Community Manager
  • 498 replies
  • 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
Forum|alt.badge.img+37
  • Klaviyo Alum
  • 1393 replies
  • Answer
  • 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