Capturing user location data enhances form intelligence and personalization opportunities without adding complexity to your user experience.
While traditional Webflow forms require manual country selection, brix-autocountry attribute automatic detection silently gathers valuable geographic information while users complete other fields.
This approach provides rich data for analytics, lead routing, and more without extending form length or creating additional steps that could impact conversion rates.
Best of all, this Webflow attribute can be implemented for free in under 5 minutes.
Form optimization involves balancing data collection needs with user experience requirements. The brix-autocountry attribute helps achieve this balance by automatically detecting and filling country fields using IP geolocation technology.
This implementation captures valuable location data while users focus on completing other form fields, creating an intelligent data collection system that works behind the scenes. You'll learn how to implement seamless country detection in any Webflow form using free IPinfo's reliable geolocation API.
Understanding the strategic value of country detection helps you implement this feature effectively across different form types:
Browser geolocation requires user permission (which people often decline) and returns GPS coordinates instead of country names. IP geolocation works differently - it uses your visitor's IP address to determine their country automatically. Since Internet Service Providers assign IP addresses by geographic regions, services like IPinfo can instantly tell you "this visitor is from Canada" without any popups or permission requests.
IPinfo provides 99.5% accuracy for country detection and processes billions of requests monthly. Setting up your free account takes just a few minutes.
Follow these steps to create your account and get the credentials you need:
Once you're in the dashboard, grab your API token:
Your free plan includes everything you need: full country names, country codes, continent data, and no rate limiting for basic country requests.
The setup involves adding JavaScript to your Webflow project and configuring form fields with the brix-autocountry attribute.
Here's how to add the country detection functionality:
1 - Copy the implementation script: Use this code that handles all the country detection magic:
<script>
/**
* BRIX Templates Auto Country Detection
* Automatically fills country fields using IPinfo API
* @version 1.0.1
*/
(function() {
'use strict';
// Configuration
const IPINFO_TOKEN = 'YOUR_TOKEN_HERE'; // Replace with your IPinfo token
async function detectCountry() {
try {
const url = `https://api.ipinfo.io/lite/me?token=${encodeURIComponent(IPINFO_TOKEN)}`;
const response = await fetch(url, {
headers: { 'Accept': 'application/json' }
});
if (!response.ok) {
throw new Error(`API Error: ${response.status}`);
}
const data = await response.json();
// Enhanced console output
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
console.log('🌎 BRIX Templates Auto Country Attribute - User detected in ' + data.country);
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
return {
country: data.country || '',
countryCode: data.country_code || '',
continent: data.continent || '',
ip: data.ip
};
} catch (error) {
console.error('Country detection failed:', error);
return null;
}
}
async function initBrixAutoCountry() {
// Find all inputs with brix-autocountry attribute
const countryInputs = document.querySelectorAll('[brix-autocountry]');
if (countryInputs.length === 0) {
console.log('No inputs with [brix-autocountry] attribute found.');
return;
}
// Detect country once
const locationData = await detectCountry();
if (!locationData) {
console.log('Country detection failed - inputs remain empty for manual entry');
return;
}
// Fill each country input
countryInputs.forEach(input => {
const fillType = input.getAttribute('brix-autocountry') || 'country';
switch (fillType) {
case 'country':
input.value = locationData.country;
break;
case 'country-code':
input.value = locationData.countryCode;
break;
case 'continent':
input.value = locationData.continent;
break;
default:
input.value = locationData.country;
}
// Trigger change event for form validation
input.dispatchEvent(new Event('change', { bubbles: true }));
});
}
// Run when DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initBrixAutoCountry);
} else {
initBrixAutoCountry();
}
})();
</script>
2 - Replace your token: Find const IPINFO_TOKEN = 'YOUR_TOKEN_HERE';. Replace YOUR_TOKEN_HERE with your actual token. Make sure there are no extra spaces.
3 - Add the script to Webflow:
4 - Publish your site: Click Publish in the top-right > Select your domains and publish
Now let's set up your form fields to automatically receive country data:
The brix-autocountry attribute accepts different values depending on what kind of country data you want. This gives you flexibility to capture exactly what your forms need.
You can use these attribute values:
Need more specific location data? IPinfo's paid plans starting at $49/month unlock city-level detection, state/province information, postal codes, and even neighborhood-level precision. These enhanced features are perfect for businesses requiring detailed geographic segmentation or local service routing.
If your project needs this level of location intelligence, we can easily modify the script to capture and utilize this additional data - just reach out to our Webflow team and we'll customize the implementation for your specific requirements.
Time to make sure everything works perfectly:
Here's how to fix the most common problems:
Nothing happens - fields stay empty:
Wrong country shows up:
Script doesn't run at all:
Yes! The brix-autocountry attribute makes this super easy. Just add our JavaScript code to your Webflow project and apply the brix-autocountry attribute to any form field. The system detects your visitor's IP address, looks up their country using IPinfo's database, and automatically fills the field with their country name. Users can still edit it if needed.
Absolutely! The brix-autocountry implementation works seamlessly with any third-party forms for Webflow as well. It doesn't interfere with form submissions, email notifications, or any integrations you have set up. The script simply pre-fills fields with country data and triggers the right events so Webflow's form validation continues working normally.
IPinfo's free tier gives you 50,000 requests per month at zero cost - that covers about 1,600 daily visitors. This includes full country names, country codes, and continent data with no setup fees. For busier sites, paid plans start at $49 monthly with higher limits and extra features like city-level detection.
Implementing automatic country detection with the brix-autocountry attribute makes your Webflow forms smarter by capturing valuable location data without any user friction. This solution improves data collection efficiency, enables better lead routing and analytics, and provides geographic insights that support business decision-making. The combination of Webflow's intuitive form builder and IPinfo's reliable geolocation service creates a powerful tool for intelligent data capture.
Start with IPinfo's generous free tier to test everything out, then upgrade as your traffic grows. Your forms will become smarter, your data more comprehensive, and your user experience more streamlined through reduced manual input requirements.
For advanced implementations requiring custom conditional logic, multi-step form integration, or city or neighbourhood geolocation features, our Webflow development team can create sophisticated solutions that perfectly align with your specific business requirements.
Control which bots access your Framer site with meta tags. Reduce bandwidth while keeping SEO strong and AI visibility intact.
Learn how to block AI bots and crawlers in Webflow with simple methods to save bandwidth and control which bots access your content.
Transform your Webflow blog with hand-picked related articles. Step-by-step Multi-Reference field setup for better user journeys and SEO.