Need the IP address of your visitors in Google Analytics Reports? Is it possible?
October 1st, 2006 adminIn 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.
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.
Watch a free VideoCast about this technique.
Also make sure to contact Merkados in Raleigh: website design, interactive marketing and if you want to build a new website with full analytics integration.
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:
- 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.
- 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.
- The settings will be the following:
- :: Add new Filter for Profile
- Filter Name: “IP Address”
- Filter Type: (Dropdown menu) Select“Custom Filter”
- Then from the radio boxes select: “advanced”
- In the first dropdown box: Field A: select the following:
i. Visitor IP Address
-
- In the text box next to it type the following:
i. (.*)
-
- In the next dropdown and text box don’t include anything.
- In the last dropdown box: Output to: select the following:
i. User defined
-
- In the text box next to it type the following:
i. $A1
-
- Field A required = yes
- Field B required = no
- Override Output Field = yes
- Case Sensitive = no
- 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


