Exclude localhost from Google Analytics
As a website developer, you usually have a copy of each site on your local computer or a development sever – for testing, development and maybe backup purposes. If you use Google Analytics you should remove the tracking code from your development site, otherwise Analytics will also count the hits from the development site. Often this goes unnoticed, so don’t be too euphoric when you see a high visit count – many of them may come from your local host.
More convenient than removing the code is to simply exclude the development server’s host name from the stats, by setting up a filter in Analytics. This is pretty easy and flexible. Please note that this won’t affect past statistics, it will be valid from the time it is set up.
Prerequisites

First check the hostnames overview in Analytics to see if it actually tracks your local hosts and what the host names are (in case you don’t know). Go to Visitors > Network Properties > Hostnames, that’s the list of hosts that Analytics receives data from. If there are any hosts listed that shouldn’t be there, such as localhost, they should be excluded from tracking to keep the stats clean.
Setting up filters

If you found hostnames that should be excluded, go back to the main Analytics site overview, select your website and click the Edit link on the right. Under Filters Applied to Profile click Add Filter.

Select Custom Filter, then Exclude, and from the Filter Field box select Hostname. In the Filter Pattern field enter the host that should be excluded, e.g. localhost. Click Save and that’s it. As mentioned before, please note that it will only filter future tracking data, it won’t clean the existing stats.