🌎 [Free] Get Country and Region without IP or third party API service [Country Getter]

Editor
Demo

Today release’s Country Getter, a clever and useful way to get a current user’s State and Country.

No more relying on API services or IP address complicated stuff - just use this plugin!

Simply run the action Get Country when the page loads, and capture the state and country from the State and Coutry exposed states available on the GetCountry element (must be placed on the page)

Technical Specs:

Exposed states:

  • Country
  • State

Events:

  • GetCountry Location Found

Setup :hammer_and_wrench:

  1. Place the country getter element anywhere on the page (any size you want, but it just needs to be visible)

  2. Create new workflow for when “Page is loaded”

  1. Run the Get Country action

3.5 (optional: if you want to use the location in a workflow do this). Create new workflow for when “Location Found”

  1. Use the “State” and “Country” exposed states available on the country getter element

For any questions or inquiries, please contact us at

www.visioncode.io

How it works :warning:

We are obtaining the state and country of the user based on the current system’s timezone. This can definitely be worked around - all the user has to do is change their timezone on their system and it will be fooled. However - I would wage that something like 99.9999% of users have automatic timezone enabled on their device (Especially smartphones).

Use case:

I would say if the stakes are not super high, and you just want to make an effort to tailor an experience to a particular location, or you want to have warnings for users outside of a particular state or country I think this plugin is perfect for you!

2 Likes

Hey I love the idea to get an idea of the country using the Internationalization API :slight_smile:

Some feedback:
I checked the demo page and it looks like you have created an infinite loop.
You assign a global object to a variable and then run a loop if the variable is empty, but the local variable is never updated.
Any reason why you are not using an element action for this? You automatically the the instance to publish state and trigger events. Running a function every 50 ms it’s usually not nice and also a source of bugs. :man_shrugging:

Also if my timezone is Europe/Madrid Intl.DateTimeFormat().resolvedOptions().timeZone.split("/")[1].replace("_", " ")returnsMadrid`, which I think it’s more a city than a state.

1 Like

Well, that was quick.
It looks like there is no more infinite loop in the demo page :slight_smile:

1 Like

Yeah :man_shrugging:

You’re right, I caught that, I fixed it. I know it’s bad practice but I needed it in one of my projects so I created something quickly. I will create an event listener for it to make it better. The reason why it’s a client-side action is because Bubble is moving to a promise based system for client side actions in the future (1 year or so) and so in order to reduce confusion I will live with global variables and then convert it to a better system when that comes out! Don’t worry, I’ll make the code cleaner & better when I have a little bit of time.

I only use the element for the event. Also I will update the map of city/country combos with time. I found that list online (open source, don’t worry) and thought it was very useful and should be available to bubble users.

About Madrid, it’s not perfect the map but I think the current map should suffice for general stuff.

Do you think this plugin will help you in your projects?

Cheers

1 Like

Madrid is just an example, European timezones are mostly in the form of Europe/Capital so the country state of the plugin will be actually a city for European users.

It’s still not clear what’s the point in storing the instance in the global window. You still need to add the element in the page because you need to publish the data to a state, why don’t you use a client side element action that has already the instance available. I’m aware that bubble will finally move to an asynchronous API but I don’t get why global variables can make any difference here.

In projects where I need to know the user location I usually ask the user, but I like the idea of using the browser timezone.

Cheers

1 Like

Hey all - new update

Version 1.0.3

Fixes occasional issues where code could cause an infinite loop. Also renamed plugin to Country and Region Getter

Cheers!