The gtag.js library includes a window property that, when set to
true, disables gtag.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 first check if this property is set, and will take no action if the value is set to
To disable Analytics programmatically, set the following window property to
window['ga-disable-GA_MEASUREMENT_ID'] = true;
GA_MEASUREMENT_ID with the Analytics ID of the property that you would like to disable.
window property must be set before any calls to
gtag() are made, and it must be set on each page for which you want to disable Analytics. If the property is not set or set to
false, then Analytics will work as usual.