How to Get Visitor IP Address in Google Analytics
Trying to find a visitor's IP address directly in Google Analytics is a dead end - it's not available. This isn't an oversight or a missing feature, Google deliberately hides this information to comply with global privacy regulations. This article will explain why that is, and more importantly, walk you through a few common methods to legally and ethically track this information when you have a legitimate business need.
Why Doesn't Google Analytics Show IP Addresses?
The primary reason you can't see individual visitor IP addresses in your Google Analytics reports is privacy. An IP address is considered Personally Identifiable Information (PII) under major privacy laws like the GDPR in Europe and the CCPA in California. Google's Terms of Service are very clear on this: you are strictly forbidden from sending any PII to Analytics.
Violating this policy can lead to a warning or even the suspension of your Google Analytics account. To avoid this automatically, Google takes two steps:
- IP Anonymization: In Google Analytics 4, IP anonymization is enabled by default and cannot be disabled. While GA uses a visitor’s IP address to determine a coarse location (city, country, continent), it then immediately discards the full IP address before it's ever logged or processed. You get the useful geographic data without storing the sensitive personal data.
- PII Policy Enforcement: Google's policies prevent you from collecting any data that a person could use to identify an individual, including names, email addresses, and of course, IP addresses.
So, while you might have valid reasons for wanting this data - like B2B lead generation or filtering out spam - doing it the wrong way puts your data and your account at risk. Fortunately, there are correct ways to handle it.
Is It Legal and Ethical to Track Visitor IPs?
Before you implement any tracking solution, you have to address the legal and ethical side of things. Simply wanting the data isn't enough, you need a legitimate reason, and you must be transparent about it.
Disclaimer: This is not legal advice. You should always consult with a legal professional to ensure your data collection practices comply with the laws in all regions you operate in.
Here are the fundamentals you need to cover:
- Legitimate Interest: You need a clear and valid business reason for collecting IP addresses. Common examples include identifying corporate visitors for B2B sales (Account-Based Marketing), enhancing fraud and bot detection, or personalizing content based on an organization.
- Update Your Privacy Policy: Your website's privacy policy must clearly state that you collect IP addresses, why you collect them, and how you use them. Transparency is non-negotiable.
- Get User Consent: A properly configured cookie consent banner is essential. Users must be able to opt-in or opt-out of tracking. Forcing tracking on users who have not consented is a direct path to legal trouble.
How to Track Visitor IP Addresses with Google Tag Manager
Using Google Tag Manager (GTM) is the most powerful and flexible method for sending IP address data into Google Analytics as a custom dimension. This method involves using a third-party API to fetch the user's IP, as it can't be found directly from the browser's JavaScript environment.
Here’s the step-by-step process:
Step 1: Set Up a Custom Dimension in GA4
First, you need to tell Google Analytics where to store the IP address data you're going to send it. You do this by creating a user-scoped custom dimension.
- In your GA4 property, go to Admin (the gear icon at the bottom-left).
- In the Property column, click on Custom definitions.
- Click the Create custom dimensions button.
- Configure the dimension as follows:
- Click Save. It can take some time for new custom dimensions to become available in your property, so it's a good first step.
Step 2: Create a Custom JavaScript Variable in GTM
Next, you'll create a variable in Google Tag Manager. This variable will contain a small piece of JavaScript code that calls an external service to identify and return the visitor's IP address.
- In your GTM container, navigate to Variables and click New under User-Defined Variables.
- Give the variable a name, like JS - Get Visitor IP.
- Click on Variable Configuration and select Custom JavaScript as the variable type.
- Copy and paste the following code snippet into the code box. This code uses a free service called ipify.org to get the IP.
function() {
try {
var xhr = new XMLHttpRequest(),
// Use true for asynchronous to avoid freezing the browser.
// However, GTM might execute tags before the response arrives.
// A synchronous call is generally simpler to ensure the value is set before the GA tag fires.
xhr.open('GET', 'https://api.ipify.org', false),
xhr.send(null),
if (xhr.status === 200) {
return xhr.responseText,
} else {
return 'undefined', // Or handle error appropriately
}
} catch (e) {
return 'undefined', // Error handling
}
}Note: This synchronous method is simpler but can slightly slow down your page load. For advanced users, an asynchronous approach with callbacks or promises is better for performance but much more complex to configure in GTM. For most use cases, this script works fine.
Step 3: Update Your GA4 Configuration Tag
Now, you need to tell GTM to send the value from the variable you just created to the custom dimension you set up in GA4.
- In GTM, navigate to Tags and find your main Google Analytics: GA4 Configuration tag (this might also be an Event tag if you are configuring it there). Click to edit it.
- Expand the User Properties section.
- Click Add Row.
- In the Property Name field, enter the exact name you used for the User Property in GA4:
visitor_ip. - In the Value field, click the lego-brick icon and select the Custom JavaScript variable you created:
{{JS - Get Visitor IP}}. - Save the tag.
Step 4: Preview, Test, and Publish
Never publish GTM changes without testing them first.
- Click the Preview button in GTM. Enter your website URL and connect.
- Once your site loads in the preview tab, look for the GA4 Configuration tag in the left-hand event stream (usually under "Initialization" or a container load event).
- Click on the tag and look at the "User Properties" section in the tag details. You should see your
visitor_ipproperty with your current public IP address as the value. - If everything looks correct, return to GTM, click Submit, and publish your changes.
Data should now start flowing into your GA4 property. You can use your "Visitor IP Address" dimension in your Explore reports to see which IPs are associated with events and users.
Alternative Methods for Capturing IP Data
While the GTM method is a great all-around solution, there are other ways to access this information, each with different strengths.
Using Third-Party Visitor Identification Tools
For B2B companies, the real goal isn't just getting an IP address - it's knowing which company is visiting your website. Several services specialize in this:
- Leadfeeder
- Albacross
- ZoomInfo
- KickFire
These platforms maintain databases that map billions of IP addresses to corporate networks. When someone from a known company visits your site, they can tell you the company's name, industry, size, and even surface potential contacts. Many of these tools integrate with Google Analytics, pushing this enriched firmographic data directly into GA4 as custom dimensions. This gives you much more actionable information than just a raw IP address.
Analyzing Server Logs
This is a more manual and technical approach. Your web server (e.g., Apache, Nginx) logs the IP address of every single request it receives, including visits to webpages, image loads, and API calls. Your web developer or a system administrator can access these logs.
The main challenge here is correlating server log data with Google Analytics data. You can try to match sessions based on timestamps and pages viewed, but it’s an imperfect, labor-intensive process best suited for specific forensic analyses (like investigating a security incident) rather than ongoing marketing reporting.
Final Thoughts
In summary, Google Analytics doesn't show IP addresses out-of-the-box to protect user privacy, but you can build a solution using Google Tag Manager and a custom dimension. Just remember to always prioritize legal compliance and user transparency by updating your privacy policy and getting clear consent.
Once you start collecting and blending this powerful new data with your other sales and marketing metrics, the next step is making sense of it all. At Graphed, we make this part easy. By connecting all your tools - Google Analytics, your CRM, ad platforms, and more - we allow you to simply ask questions in plain English like, "show me a list of companies from our target accounts list that viewed the pricing page more than three times last month." We turn hours of complex report-building into a 30-second conversation, giving you the insights you need instantly.
Related Articles
What SEO Tools Work with Google Analytics?
Discover which SEO tools integrate seamlessly with Google Analytics to provide a comprehensive view of your site's performance. Optimize your SEO strategy now!
Looker Studio vs Metabase: Which BI Tool Actually Fits Your Team?
Looker Studio and Metabase both help you turn raw data into dashboards, but they take completely different approaches. This guide breaks down where each tool fits, what they are good at, and which one matches your actual workflow.
How to Create a Photo Album in Meta Business Suite
How to create a photo album in Meta Business Suite — step-by-step guide to organizing Facebook and Instagram photos into albums for your business page.