2018 update: Where and how you mount Analytics has changed over and over and over again. The current gtag.js code does a few things:
- Load the gtag script but async (non-blocking). This means it doesn't slow your page down in any other way than bandwidth and processing.
- Create an array on the page called
window.datalayer
- Define a little
gtag()
function that just pushes whatever you throw at it into that array.
- Calls that with a pageload event.
Once the main gtag script loads, it syncs this array with Google and monitors it for changes. It's a good system and unlike the previous systems (eg stuffing code in just before </body>
) it means you can call events before the DOM has rendered, and script order doesn't really matter, as long as you define gtag()
first.
That's not to say there isn't a performance overhead here. We're still using bandwidth on loading up the script (it's cached locally for 15 minutes), and it's not a small pile of scripts that they throw at you, so there's some CPU time processing it.
But it's all negligible compared to (eg) modern frontend frameworks.
If you're going for the absolute, most cut-down website possible, avoid it completely. If you're trying to protect the privacy of your users, don't use any third party scripts... But if we're talking about an average modern website, there is much lower hanging fruit than gtag.js if you're hitting performance issues.
This question remains valid today, however the technology has changed. The old Urchin tracker is deprecated and obsolete. The new asynchronous Google Analytics tracking code uses slightly different code to achieve the same results.
Google Analytics Classic - Asynchronous Syntax - ga.js
The current syntax for setting the tracking domain to none on google analytics looks like this:
_gaq.push(['_setDomainName', 'none']);
Google analytics will then fire off the _utm.gif tracker request on localhost. You can verify this by opening the developer tools in your favorite browser and watching the network requests during page load. If it is working you will see a request for _utm.gif in the network requests list.
Updated 2013 for Universal Analytics - analytics.js
Google released a new version of analytics called "Universal Analytics" (late 2012 or early 2013). As I write, this the program is still in BETA so the above code is still recommended for most users with existing installations of Google Analytics.
However, for new developments using the new analytics.js
code, the Google Analytics, Advanced Configuration - Web Tracking Documentation shows that we can test Universal Analytics on localhost with this new code:
ga('create', 'UA-XXXX-Y', {
'cookieDomain': 'none'
});
Check out the linked documentation for more details on advanced configuration of Universal Analytics.
Update 2019
Both Global Site Tag - gtag.js
and Universal Analytics - analytics.js
will detect localhost
automatically. You do not need to make any change to the configuration.
If gtag.js detects that you're running a server locally (e.g. localhost
), it automatically sets the cookie_domain
to 'none'
.
- developers.google.com
Best Answer
UPDATE/EDIT – December 5, 2014 : Converted this to community wiki… feel invited to edit and update.
UPDATE/EDIT – AUGUST 1, 2014
Google has done it again… they changed the design. But they also made things a bit simpler and more logic. Go to
Administration → Property Settings
and look for theDelete Property
link at the right-bottom of the page. Click that link to delete the property.Here’s a schreenshot of the current (2014-08-01) interface, pointing to the link you’re looking for…
Note that the RGB noise is not part of the Google design. I added that to protect personal information. ;)
Stop reading here…
What follows was my original answer, which has been rendered obsolete by Google’s design update on 2014-08-01. For potential reference purposes, I’ve decided to not yet remove that outdated info…
Google decided to move that feature into the
View Settings
. To find it, go to the "View Settings" in your Admin area…Then click the link to delete it…