How to Track IP Address in Google Analytics

Cody Schneider7 min read

Wondering why you can't see visitor IP addresses in your Google Analytics reports? It's intentional. Google automatically hides this data to comply with global privacy laws, treating IP addresses as personally identifiable information. This article walks you through the technical (and risky) method to capture this information, explains why it's generally a bad idea, and shows you much better, privacy-safe alternatives to get the insights you're really after.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

Why Google Analytics Anonymizes IP Addresses by Default

The primary reason you can't find a list of visitor IP addresses in Google Analytics is privacy. Regulations like the General Data Protection Regulation (GDPR) in Europe and the California Consumer Privacy Act (CCPA) classify IP addresses as Personally Identifiable Information (PII). Collecting and storing PII comes with strict legal responsibilities.

To keep you and your business on the right side of the law, Google's Terms of Service explicitly forbid sending any PII to its servers. Google Analytics enforces this by automatically employing a process called IP anonymization. Before any data is processed or stored, Google Analytics truncates the last octet of the user's IPv4 address or the last 80 bits of an IPv6 address, effectively making it impossible to identify the specific individual.

This process allows you to get valuable geographic data - like country, region, and city - without storing the visitor's exact IP, striking a balance between useful analytics and user privacy.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

The Technical Method: Using Google Tag Manager to Capture IP Addresses

Before proceeding, a strong warning is necessary: This method likely violates Google's Terms of Service and may put you on the wrong side of privacy regulations like GDPR. It is presented for educational purposes only. Always consult with a legal professional before capturing user data to ensure compliance.

If you have a legitimate, compliant reason to proceed, the most common method involves using Google Tag Manager (GTM) to fetch the IP address from a third-party service and pass it to Google Analytics as a custom dimension.

Step 1: Create a Custom Dimension in Google Analytics 4

First, you need to tell GA4 where to store the IP address data. This is done by creating a user-scoped custom dimension.

  • Navigate to your GA4 property and click Admin in the bottom-left corner.
  • In the Data display column, click Custom definitions.
  • Click the Create custom dimensions button.
  • Configure the dimension as follows:
  • Click Save.

Step 2: Use a Custom HTML Tag to Fetch the IP in GTM

Since the browser doesn't know its own external IP address, you need to ask an external server. We'll use a simple API endpoint for this. This step involves creating a Custom HTML tag in Google Tag Manager to fetch the IP and push it to the dataLayer.

  • In your GTM container, navigate to Tags and click New.
  • Name your tag something clear, like "HTML - Fetch User IP."
  • For Tag Configuration, choose Custom HTML.
  • Paste the following code into the HTML box:
<script>
  fetch('https://api.ipify.org?format=json')
    .then(response => response.json())
    .then(data => {
      window.dataLayer.push({
        'event': 'ip_captured',
        'user_ip': data.ip
      }),
    })
    .catch(error => console.error('Error fetching IP:', error)),
</script>
  • Under Triggering, select a trigger that fires early, like Initialization - All Pages. This ensures the IP is captured for most page loads.
  • Click Save.

Step 3: Create a Data Layer Variable in GTM

Now that the IP address is being pushed to the dataLayer, you need to create a variable in GTM to "catch" it so you can use it in other tags.

  • In GTM, go to Variables.
  • Under User-Defined Variables, click New.
  • Name your variable "DLV - User IP."
  • For Variable Configuration, choose Data Layer Variable.
  • In the Data Layer Variable Name field, enter user_ip. This must exactly match the key you used in the Custom HTML tag.
  • Click Save.
GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

Step 4: Send the IP Address to GA4

The final step is to modify your main GA4 configuration tag to send the captured IP address to the custom dimension you created earlier.

  • In GTM, go back to Tags and find your main Google Tag: GA4 Configuration tag. (It might be named something like "GA4 Config".)
  • Click into the Tag Configuration.
  • Expand the Configuration settings section and under User Properties, click Add row.
  • Set it up as follows:
  • Click Save.

Once you publish your GTM container, this setup will send the visitor's IP address to GA4 and populate the "IP Address" custom dimension you created. You can find this data in the Explorations section of GA4.

Why Tracking Full IP Addresses is Problematic

Running through the technical steps above makes one thing clear: you have to intentionally work around the platform's design to track IPs. This is because, beyond the privacy compliance issues, the data can be technically unreliable.

  • Legal Risks: As mentioned, collecting PII without explicit consent can lead to significant fines under regulations like GDPR. You also risk losing user trust if they feel their privacy isn't respected.
  • Dynamic IPs: Most residential internet providers assign dynamic IP addresses, meaning a single user's IP can change frequently. Tracking it doesn't give you a stable identifier for a returning user.
  • Shared IPs and VPNs: A single IP address often represents an entire office, university campus, or co-working space. Conversely, a user might be using a VPN, which masks their true location and IP address. In either case, the IP address isn't a reliable signal of an individual's location or identity.

Smarter Alternatives: What to Track Instead of IP Addresses

Most of the time, tracking a full IP address is a clumsy means to another end. By focusing on your actual goal, you can find a more effective and compliant solution right within Google Analytics or with the help of specialized tools.

For Filtering Internal Traffic: Use GA4's Built-in IP Filtering

One of the most common reasons marketers want visitor IPs is to filter out traffic from their own company, preventing employee activity from skewing the data. GA4 has a built-in feature for this that doesn't require any custom tracking.

  1. In GA4, go to Admin > Data Streams.
  2. Click on your web data stream.
  3. Under Google tag, click Configure tag settings.
  4. Click Define internal traffic.
  5. Create rules to identify your office's IP addresses. Google uses this information to filter traffic on its end, but you never see or store the IPs in your reports.

For Identifying Companies: Use Reverse IP Lookup Tools

If your goal is to identify B2B leads visiting your site, a raw IP address is only the first step. Dedicated B2B intelligence tools like Leadfeeder, Clearbit, or Albacross specialize in this. They take the visitor's IP, match it against a large database of corporate IP addresses, and provide rich firmographic data like a company name, industry, size, and location - all without you needing to handle PII directly.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

For Geo-Targeting: Use GA4's Geographic Dimensions

GA4's native location data is more than enough for geographical analysis. While Google anonymizes the full IP, it still uses it to accurately derive a user's location beforehand. You can build reports and Explorations using dimensions like Country, Region, and City to understand where your users are coming from and how their behavior differs by location.

For Detecting Unwanted Traffic: Look at Engagement Metrics

Suspicious or fraudulent traffic can often be identified without knowing the source IP. Google Analytics automatically filters a significant amount of known bots and spider traffic. For anything that gets through, you can look for patterns that suggest low-quality traffic:

  • Extremely high bounce rates from a specific source.
  • Session durations of 0–1 seconds.
  • Traffic spikes from unexpected geographical locations.

Investigating these behavioral patterns is often a more reliable way to identify bot traffic than trying to block individual IP addresses, which are easily changed.

Final Thoughts

While it's technically possible to track IP addresses in Google Analytics, it opens a Pandora's box of privacy concerns, legal risks, and data inaccuracies. In almost every case, there's a safer, more effective way to accomplish your reporting goals using built-in GA4 features or specialized third-party tools that are designed to be privacy-compliant.

Connecting all the dots between web behavior in Google Analytics and customer data in your CRM or ad platforms can quickly become overwhelming. At Graphed, we simplify this entirely. By connecting your data sources like GA4, Shopify, or Salesforce, you can use simple English to ask questions like, "Show me traffic, conversions, and revenue by city for our latest campaign." We automate the reporting so you can build real-time dashboards in seconds, not hours, letting you focus on the insights instead of the data wrangling.

Related Articles