Can you setup Google Analytics to work on your localhost? Yes!
I searched for the answer to this question and found many responses, several of them said it’s not possible. The solution wasn’t easy to find and I tried several things before finally getting it to work, so I thought I would post what I did to get it to work on my localhost.
First, you’ll need to to create a Google Analytics account (http://www.google.com/analytics/); and for that, you’ll need a gmail account. When you create a new Analytics account, the first thing you’ll need to supply is a url for your website. Google Analytics won’t let you put in the url for your localhost (e.g.: http://localhost:8080), you have to enter a url that Google Analytics will allow (i.e.: it must include a “.”). I used http://localhost.local (a suggestion I found on a forum somewhere).
Here’s what the code looks like…
(Note: The UA id is unique for each Analytics account. Replace the ‘UA-xxxxxxxx-x’ value with the unique UA id that is generated by Goole Analytics for your site.)
Once Google finds your code, the icon on your Google Analytics Overview screen will change from a yellow warning icon to a green checkmark.
After you get the green checkbox, Google Analytics will start capturing your data. I’ve noticed there is a 5-10 minute delay from the time I click through the screens on my site, to the time I see the data in the Google Analytics reports.
One other thing to note, the date range on the Google Analytics dashboard and reports defaults to end on yesterday’s date. Make sure to modify the date range to include today’s date to see your most recent activity.