Need an API Service?
There are many services that provide an IP API as long as that service can provide the api in a JSON format, it will work with this script. Some things to note however, some services are blocked by other applications, most notably Ad blockers. With this in mind it's important that you choose a service that is able to detect IP Addresses in any situation.
We would recommend using IPStack as this is one service provider that is able to detect IP addresses even with ad blockers enabled.
IP API Stack - Sign up
You will need to create an account for IP Stack, you can find pricing for their services here. Know roughly the amount of traffic you expect per month, as this will determine the account tier you will need to consider signing up for. Many service providers charge by session traffic.
Once you select your plan fill out the required details for payment, and you should then be directed to your account dashboard!
Creating your Fetch URL
- Base URL (http://api.ipstack.com/)
- API Request action check
- Access Key
Your access key will be found on the main page of your account dashboard. With all three pieces gathered piece them together in the following configuration.
https://api.ipstack.com/check?access_key=[PASTE ACCESS KEY HERE]
To see if your URL is set up correctly simply paste it into a new tab on your browser and click enter. If successful you should see a string of information detailing your Country, IP address, etc. If you see False, or Error in the string, please review your URL to ensure that it is typed out correctly.
You are now ready to implement code so that your API service can help you show or hide elements based on location.