Setting Up Google Analytics on localhost
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.
One thought on “Setting Up Google Analytics on localhost”
I was trying to track the google analytics on my local jsp page(accessing through the tomcat server).when i’m trying to give Website URL as http://localhost:8080/Appname/..jsp it’s not taking.is there any anyway to track the localhost URL.
You need to setup virtual host for your app.
Thanks for the post. Its really helped to enable google analytics tracking for my localhost application.
But the google analytics doesnt take localhost url, and the copy pasting the script code is the further step.
Its nice to know that how to set a url for a localhost but in the next option where we have to put our site name in the begining of form what we have to put their.
Hi, I cannot create a google analytics account because of this error: “URL ends with an invalid top-level domain name”. The website URL that I entered is the same as yours “localhost.local”.
Even it did not work for me either. I think this solution is out dated.
http://localhost.local, this fix is not working for me