Sometimes, you may want to limit who can access your online store based on their country. This is useful if you ship only to certain regions, need to follow local regulations, or want to make your store available only in selected markets.
Store.link does not currently offer a built-in option to restrict access by country. However, you can achieve this using Google Tag Manager, which allows you to control what visitors see based on their location.
In this guide, we’ll walk you through how to restrict access to your Store.link store for selected countries, step by step.
Set up Google Tag Manager
Go to your Google Tag Manager dashboard and select Create account.
In the account setup, add your preferred account name and select your country.
In the container setup, add your online store domain and select Web as the platform.
Click on Create.
Click Yes to accept the terms and continue with the setup process.
You’ll see two code snippets after the setup, which you will have to copy one at a time.
You’ll also find an option to enter your store URL to test whether Google Tag Manager is installed correctly.
Add Google Tag Manager to Store.link
Go to Store.link Dashboard → Settings → Integrations → Custom Script and paste the copied code snippets one by one, then Save.
Create the website blocking tag
In the Google Tag Manager dashboard, click Add a new tag to create a new tag for your container.
Click Tag Configuration, then select Custom HTML to create a tag using custom HTML code.
We are now adding a code snippet that checks the country a customer is browsing from based on their IP address (here we are using ipapi.co).
If the customer is browsing from a non-allowed country, the code hides the website and shows a message instead.
Now copy the code below and paste it into the editor.
<script>
(function () {
var allowedCountries = ["IN"];
// Add your allowed ISO 3166-1 alpha-2 codes here, e.g., ["IN", "US", "GB"]
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://ipapi.co/country/", true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
var country = xhr.responseText
.trim()
.toUpperCase(); // Ensure uppercase for matching
if (allowedCountries.indexOf(country) === -1) {
document.body.innerHTML =
'<div style="' +
'height:100vh;' +
'display:flex;' +
'align-items:center;' +
'justify-content:center;' +
'background:#f8f9fa;' +
'text-align:center;' +
'font-family:system-ui,sans-serif;' +
'padding:20px;' +
'box-sizing:border-box;' +
'">' +
'<div>' +
'<h1 style="' +
'font-size:24px;' +
'margin-bottom:16px;' +
'color:#333;' +
'">' +
'Access Restricted' +
'</h1>' +
'<p style="' +
'font-size:16px;' +
'color:#555;' +
'margin-bottom:24px;' +
'">' +
'Sorry, this store is not available in your region ' +
'due to shipping or regulatory restrictions.' +
'</p>' +
'<p style="' +
'font-size:14px;' +
'color:#777;' +
'">' +
'If you believe this is an error, please contact support.' +
'</p>' +
'</div>' +
'</div>';
}
} else {
// Optional fallback behavior if the API fails
console.warn(
"Geolocation API failed:",
xhr.status
);
// document.body.innerHTML = "... optional fallback message ...";
}
}
};
xhr.send();
})();
</script>
Note
Edit this line in the code to choose which countries your store is available in:
var allowedCountries = ["IN"];Examples:
Only India →
["IN"]India + US →
["IN", "US"]India + UK + Canada →
["IN", "GB", "CA"]
Click Triggering and select All Pages. Then click Save.
Give your tag a clear name so it’s easy to understand later. Click on Save.
In the Google Tag Manager dashboard, click on Submit.
Click Publish to make the changes live.
You can add a container version name and description if needed. And Click on Continue.
Test your store
Visit your store from another country and check the result.
Note
You can change what is shown on the blocked screen by editing the HTML code pasted in the tag. Feel free to modify the message or layout according to your needs.
The current code uses https://ipapi.co/country/, which remains functional, but the free tier is now limited to 1,000 requests per day (≈30,000/month) and is officially intended only for testing/development, not production websites with real traffic.
Still need help?
Contact us