- Help Center
- Configuration
-
Getting Started
-
Configuration
- Targeting
- Split URL
- Product Testing
- Full Stack
- Experiment Management
- CSP Configuration
- Experiment Execution
- Reports
- Exit Popups
- GTM Integration
- Troubleshooting
- Performance Optimization
- Event-Triggered Changes
- Holdout Groups
- Split URL Pages
- URL Parameters
- DataLayer
- Menu Configurations
- Traffic Exclusion
- Experiment Scheduling
- Dynamic Element Changes
- Price Targeting
- Experience Scheduling
- Privacy
- Hash Changes
- Async Tracking
- Selective Installation
- CSS Selectors
- Vue.js Integration
- Page Content
- Multipage Split URL
- Organic Traffic
- Visual Editor
- Server-Side Testing
- Traffic Bucketing
- GDPR Warnings
- Statistical Confidence
- Browser Privacy
- Query Parameters
- Embedded Videos
- Tracking Code Execution
- Simultaneous Experiments
- Tags
- Deployments
- Disable Testing
- Locations
- Programmatic Bucketting
- Query Parameter Handling
- Convert Library
- Variation Previews
- Experiment Editing
- Opt-Out Script
- Data Reset
- Body Hiding
- Visit-Specific Variations
- Variation Styling
- Preview Issues
- Variation Editing
- Full-Site Testing
- Blinking Variations
- Cross-Domain Cookies
- Regex Support
- Conversion Tracking
- SPA Testing
- Project Setup
- Cross-Domain Tracking
- Geo-Targeting
- Analytics Tools
- Campaign Tags
- Previewing
- IDs
- Query String Targeting
- Bounce Rate Goals
- Bot Filtering
- Query String Variables
- Custom Audiences
- Redirects
- Baseline
- Tracking Code Location
- Secure Cookies
- AngularJS
- Cloudflare
- Code Installation
-
Track Goals
- Form Tracking
- Cookie Management
- iFrame Click Tracking
- Performance Optimization
- Revenue Tracking
- Interaction Goals
- Form Submissions
- Advanced Goals
- Lazy Loading
- Multi-Conversions
- URL Parameters
- Bounce Rate Goals
- DataLayer Integration
- Scroll Depth
- Social Interactions
- Page Views
- Marketo Forms
- Feature Analysis
- AJAX Forms
- Revenue Tracking via GTM
- Order Outliers
- Cumulative Revenue
- Goal Templates
- Adding Revenue Goals
- JS-Based Goals
- Goal Basics
- Google Analytics Goals
- Social Sharing
- Dynamic Goals
- Typeform Integration
-
Target Visitors
- Geolocation
- Interaction Goals
- Goal-Based Targeting
- Weather Targeting
- Cookie-Based Targeting
- Page Visits
- Audience Management
- Audience Segmentation
- Experiment Targeting
- Advanced Audience Creation
- Audience Templates
- Audience Creation
- Data Layer Integration
- Manual Activation
- JavaScript Conditions
- Device Targeting
- Language Targeting
- IP-Based Exclusion
- Visitor Management
- Page Tagging
- Cookies
-
Troubleshooting
- Google Warnings
- Visual Editor
- HTTPS Content
- Logs
- Support Options
- Bootstrap
- Cookie Blocking
- Change History
- Mobile Debugging
- AdWords
- Bot Exclusion
- Domain Issues
- Cloudflare Issues
- Monitoring
- Cloaking Penalties
- Goal Editor Issues
- Variations
- Snippet Performance
- Changes Not Saved
- Blocked Visual Editor
- Goal Testing
- Visual Editor Browsing
- Experiment Issues
- Installation Verification
- Data Leak Prevention
- Usage Limits
- Experiment Previews
- GA4 Revenue
- Chrome Debugger Logs
- SPA Errors
- Checkout JSON Error
-
Analyze Results
-
Integrations
- Google Analytics
- Cookie Consent Platforms
- Microsoft Clarity
- Plausible
- Marketo
- HubSpot
- Tealium
- Smartlook
- Klaviyo
- Salesforce CRM
- FullStory
- Snowplow Analytics
- Webflow
- GA4 Roles
- Amplitude
- Segment
- React
- BigCommerce
- WooCommerce
- Active Campaign
- Google Tag Manager
- Mixpanel
- Zapier
- Inspectlet
- Crazy Egg
- LanderApp
- Unbounce
- Instapage
- Drupal
- PrestaShop
- Magento
- Roistat
- Piano Analytics
- Heap Analytics
- Kissmetrics
- Mouseflow
- Adobe Analytics
- Clicky
-
Account Management
-
Developers
-
What's New
-
Common Questions
-
Shopify
Blocking certain visitors based on their IP address.
In some scenarios, you may need to restrict or customize content for visitors based on their IP addresses or a range of IP addresses. To implement this, you'll require the services of a third-party provider to determine the IP addresses of your visitors. While many providers offer such services, we'll use https://ipapi.co/
as our example for demonstration purposes in this guide.
Setting Up IP-Based Filtering
1. Adding and Configuring the JavaScript Code
To begin, you need to insert the following JavaScript code into the Global JavaScript section of your project. Adjust the settings in the code as per your specific requirements:
// Configuration settings
const config = {
singleIP: false,
startIP: '187.189.49.60',
endIP: '187.189.49.70',
showExperiences: false,
};
// Function to convert IP address to a numerical value
function IPtoNum(ip) {
return ip.split('.').reduce((acc, octet) = acc * 256 + parseInt(octet, 10), 0);
}
// Function to check and update experiences visibility
function updateExperiences(geoipdata) {
const userIPNum = IPtoNum(geoipdata.ip);
const startIPNum = IPtoNum(config.startIP);
const endIPNum = IPtoNum(config.endIP);
if (config.singleIP && geoipdata.ip === config.startIP) {
config.showExperiences = true;
} else if (!config.singleIP && userIPNum = startIPNum && userIPNum <= endipnum)="endIPNum)" {="{" config.showexperiences="false;" }="}" else="else" fetch="Fetch" user="user" s="s" ip="IP" data="data" and="and" update="update" experiences="experiences" based="based" on="on" function="function" fetchipdata()="fetchIPData()" fetch(="fetch(" https:="https:" ipapi.co="ipapi.co" json="json" )=")" .then(response=".then(response"> {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data = {
updateExperiences(data);
console.log('Experiences visibility set to:', config.showExperiences);
})
.catch(error = {
console.error('Failed to fetch IP data:', error);
});
}
// Initiate the process
fetchIPData();
</=>
2. Integrating the JavaScript Condition
Next, add the following JavaScript condition to the audience conditions of the experiences you wish to control. This condition should be combined with any other audience conditions using an AND logic:
(function() {
// Make sure to include a reference to the configuration and functions defined earlier
// Initiates fetching IP data and updates the visibility of experiences accordingly
fetchIPData();
// Function to recheck the experiment if needed, placeholder for actual functionality
function convert_recheck_experiment() {
console.log("Rechecking experiment due to missing IP data.");
// Additional logic to recheck or retry fetching IP data could be added here
}
// Check if the IP data has been set and is not undefined or null
function checkIPDataAvailability() {
if (typeof geoipdata === "undefined" || geoipdata.ip === null) {
convert_recheck_experiment();
return false;
} else {
return config.showExperiences; // Refer to the showExperiences within the config object
}
}
// Execute the check
return checkIPDataAvailability();
})();
The JS condition needs to be configured in the following way:
With this setup, your specified content will be blocked or displayed for users within the designated IP or range configured in the JavaScript code.
Debugging Tips
To verify the functionality, type config.showExperiences
in your browser's console. This will indicate whether the script correctly identified if a visitor's IP matches the designated single IP or falls within the configured range