Need the IP address of your visitors in Google Analytics Reports? Is it possible?

October 1st, 2006 admin Location: Raleigh, NC, Topic: Web Design | Digital Media

In short: YES YOU CAN! Even though Google has blocked the ability to gather IP information out of the box from your Google Analytics reports, you can resort to PHP to “introduce” them back. This is based on the fact that by using Google Analytics you shouldn’t be able to identify specific users and their behaviors. There is an easy way to still gather the IP’s if you don’t mind using also a little bit of php (Apache server is the best way to go). Use the following code in your body tag (I would use it only in the home-page.

Remember, this is using PHP:

First you need to insert a combination of php and javascript in your website. Also, you need to understand that you will be using the “__utmSetVar” Javascript tag. This tag will allow you to set the user-defined field in your G.A. interface. You can only set this value once. If you set it twice, it simply will overwrite your previous value.

Now before we continue, please take two minutes of your time to register and gain access to the solution, it is free by the way.
[private]

The PHP

First the PHP code: (NOTE:Your homepage has to be a php page, otherwise it won’t run, this is obvious right?).

<?php echo $_SERVER['REMOTE_ADDR']; ?>

This basically says: “print the IP address of the visitor according to the browser in the page being displayed”

Then the javascript part:

<body onLoad="javascript:__utmSetVar('Something to create segmentation')">

This part says: “when the body element of the DOM loads call a javascript function named: utmSetVar, this function assigns a segmentation value to your Google Analytics User Defined field in the reports”.

The code you include in your page:

So when we combine the php and the javascript it should look like:

<body onLoad="javascript:__utmSetVar('<?php echo $_SERVER['REMOTE_ADDR']; ?>')">

This is the code that you need to include in your page. That is it. After a couple of hours you will start seeing the IP addresses of your visitors in the user-defined field of the visitor panel in your Google Analytics account. Couple of things before wrapping up:

  • 1. Remember that if you just placed this code in your homepage, the user-defined field will only show the IP addresses of those visitors that visited the homepage, conversely, you won’t be able to see the IP of those who don’t.
  • 2. You have to be able to run PHP in your homepage, therefore in a regular HTML file this code won’t work.
  • 3. Remember that from the moment you add this segmentation it will record all those IP addresses and therefore they are there for the long run, you can’t delete them from your reports unless you delete your entire profile, so make sure that you want them there.
  • 4. You can create segmentation like this for almost any information sent by the browser or the server, however, you only have 1 user-defined field in Google Analytics, therefore once you use it for something, that is pretty much it, you can’t have more than one user-defined segmentations of this kind.
  • 5. It is important to understand, if you were going for a Google Analytics filter ip, this won’t work. Why? This change happens in the website level, so all the profiles will have this information. I guess you could technically create a profile and then create a filter in that profile to block the ip information, but it would be a bit cumbersome.

Watch a free VideoCast about this technique.

Also make sure to contact Merkados in Raleigh, if you would like to learn more about website design, interactive marketing or if you want to build a new website with full analytics integration.

Update 2012

So one of the questions that we received is where can we see this information in the new, updated Google Analytics platform. The answer is to go to:
Audience > Custom > User Defined

You’ll find your IPS showing up there.

The Old Way (doesn’t work anymore)

This is the other way (not functional anymore) that you used to be able to accomplish the gathering of IP’s in GA if you want to apply this knowledge to other filters in Google Analytics.

Steps:

  1. In GA, go to the “Edit” menu for the profile that you are trying to collect IP addresses from. (This is located next to the “view reports” link for every profile.
  2. Scroll down to the third box “Filters for Profile”, and click on the link: “add filter” located at the right top section of this box.
  3. The settings will be the following:
    1. :: Add new Filter for Profile
    2. Filter Name: “IP Address”
    3. Filter Type: (Dropdown menu) Select“Custom Filter”
    4. Then from the radio boxes select: “advanced”
    5. In the first dropdown box: Field A: select the following:

i. Visitor IP Address

    1. In the text box next to it type the following:

i. (.*)

    1. In the next dropdown and text box don’t include anything.
    2. In the last dropdown box: Output to: select the following:

i. User defined

    1. In the text box next to it type the following:

i. $A1

    1. Field A required = yes
    2. Field B required = no
    3. Override Output Field = yes
    4. Case Sensitive = no
    5. FINISH

Once you had setup the filter like this you were able to see the IP addresses of your visitors by selecting the user defined menu in the visitor performance menu or by cross segmenting by user defined variable. Remember that you don’t want to place this filter if you are collecting any other custom segments in your site since you will overwrite those. If your tracking code is the same in every page of your site and you had no previous filters then you have nothing to worry.

That is it.

If you need more valuable information you can search the user-forum for Google Analytics at: http://groups.google.com/group/analytics-help

[/private]

About the Author

Alex Centeno MBA., is an international creative director and digital media strategist. Currently residing minutes away from the Research Triangle Park (RTP) - North Carolina, and with over 10 years of interactive marketing training and experience, Alex leads Merkados' international clients to maximizing their online business strategies. One of Alex's biggest strengths is his world-class capacity to effectively combine interactive marketing, digital media design and web development.

You may find further information about Alex Centeno MBA. at: and Twitter.

Sobre el Autor

Alex Centeno MBA., Es un director creativo y estratega de medios digitales reconocido internacionalmente. En la actualidad reside a tan solo minutos del Research Triangle Park (RTP) - Carolina del Norte, y con más de 10 años de entrenamiento y experiencia en marketing interactivo, Alex lidera a los clientes internacionales de Merkados™ para maximizar sus estrategias de negocios en línea. Una de las mayores fortalezas de Alex es su capacidad global de combinar de manera efectiva, mercadeo interactivo, diseño de medios digitales y desarrollo web.

Para más información sobre Alex Centeno MBA. puede visitar: y Twitter.