Disable tracking

In some cases, it may be necessary to disable Google Analytics tracking on a page without removing the gtag.js tracking snippet. For example, you might do this if your site's privacy policy provides an option for the user to opt-out of Google Analytics tracking.

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 true.

To disable tracking, set the following window property to true:

window['ga-disable-GA_TRACKING_ID'] = true;

Replace GA_TRACKING_ID with the tracking ID of the property that you would like to disable.

This 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 Google Analytics tracking. If the property is not set or set to false, then tracking will work as usual.