View Visitor IP Address in Google Analytics

2020 update: There has been a lot of talk lately in the analytics blogosphere and beyond about Google’s commitment to privacy and the way they handle sensitive data (like IP addresses). Due to this, the information in this blog post is no longer available within Google Analytics.

Previously, by stripping out the visitor IP address and adding it to the User Defined variable, the IP address would show up in reports. However, now this report (Marketing Optimization > Visitor Segment Performance > User Defined) now shows a value of ‘(not set)’ for all visitors, as it would if the User Defined variable had never been used.

We recommend that anyone who has attempted this hack on their own Google Analytics profiles remove it. As we’ll mention below, it violates your Terms of Service and it no longer works.

If you were interested in this blog post, here are some other posts you may be interested in instead:

 

View Visitor IP Address in Google AnalyticsThere’s no way to view your visitors IP addresses right out of the box with Google Analytics. You can view visitor location and ISP in Marketing Optimization > Visitor Segment Performance, under the Domains and Geo Location reports.

But surely Google Analytics must collect the IP address, or there’s no way that it could calculate visitor location and ISP.

In fact, it does collect this data from each visitor who accesses your site. Better still, the data is easily accessible with a fairly straightforward Advanced Filter and the User Defined variable. Here’s how.

You’ll need to create a new filter for your profile. Bear in mind that if you are using any custom visitor segmentation with the ‘__utmSetVar’ function, you should set up a new profile for the IP address data. If you don’t, you’ll overwrite your custom segmentation.

In the Filter Manager, enter the following filter information:

  • Filter name: IP extraction
  • Filter Type: Advanced
  • Field A -> Extract A: Visitor IP address / (.*)

You can leave Field B and Extract B blank.

  • Output To -> Constructor: User Defined / $A1

Then be sure to apply the filter to your profile.

This will take the User Defined field and replace it with the IP address (which is used behind the scenes in several reports, but unfortunately does not headline in its own). You will then be able to Cross Segment by User Defined in your reports to see all of the IP addresses for a particular entry, or view them in the User Defined report under Marketing Optimization > Visitor Segment Performance.

Now, there is a huge caveat to this entire procedure. If you take a look at Item 7 in the Google Analytics Terms of Service, you’ll notice that you are not allowed to “associate any data gathered from your website(s) (or such third parties’ website(s)) with any personally identifying information from any source.” So, using the filter above will break the ToS. Just a heads up.