Opt-out of measurement for your site
The analytics.js library includes a window property that, when set to
true, disables analytics.js from sending data to Google Analytics. When Google Analytics attempts to set a cookie or send data back to the Google Analytics servers, it will check whether this property is set to
true. If it is, no action will be taken.
To disable measurement, set the following
window property to
window['ga-disable-UA-XXXXX-Y'] = true;
Where the value
UA-XXXXX-Y corresponds to the property ID on which you would like to disable measurement.
window property must be set before any calls to the
ga() command queue are made, and it must be set on each page for which you want to disable Google Analytics measurement. If the property is not set or set to
false then measurement will work as usual.
Opt-out of measurement on all sites
To opt-out of Google Analytics measurement for all sites, even sites whose source code you do not control, you can install the Google Analytics opt-out browser add-on.